mirror of
https://github.com/logos-messaging/OpChan.git
synced 2026-01-05 22:33:07 +00:00
fix: ENS status
This commit is contained in:
parent
97d34daad3
commit
dd13ef6b2e
@ -2,6 +2,8 @@ import React from 'react';
|
|||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
import { Shield, Crown } from 'lucide-react';
|
import { Shield, Crown } from 'lucide-react';
|
||||||
import { UserVerificationStatus } from '@/lib/forum/types';
|
import { UserVerificationStatus } from '@/lib/forum/types';
|
||||||
|
import { getEnsName } from '@wagmi/core';
|
||||||
|
import { config } from '@/lib/identity/wallets/appkit';
|
||||||
|
|
||||||
interface AuthorDisplayProps {
|
interface AuthorDisplayProps {
|
||||||
address: string;
|
address: string;
|
||||||
@ -17,12 +19,26 @@ export function AuthorDisplay({
|
|||||||
showBadge = true
|
showBadge = true
|
||||||
}: AuthorDisplayProps) {
|
}: AuthorDisplayProps) {
|
||||||
const userStatus = userVerificationStatus?.[address];
|
const userStatus = userVerificationStatus?.[address];
|
||||||
const isVerified = userStatus?.isVerified || false;
|
const [resolvedEns, setResolvedEns] = React.useState<string | undefined>(undefined);
|
||||||
const hasENS = userStatus?.hasENS || false;
|
|
||||||
|
// Lazily resolve ENS name for Ethereum addresses if not provided
|
||||||
|
React.useEffect(() => {
|
||||||
|
const isEthereumAddress = address.startsWith('0x') && address.length === 42;
|
||||||
|
if (!userStatus?.ensName && isEthereumAddress) {
|
||||||
|
getEnsName(config, { address: address as `0x${string}` })
|
||||||
|
.then((name) => setResolvedEns(name || undefined))
|
||||||
|
.catch(() => setResolvedEns(undefined));
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [address]);
|
||||||
|
|
||||||
|
const hasENS = userStatus?.hasENS || Boolean(resolvedEns) || Boolean(userStatus?.ensName);
|
||||||
const hasOrdinal = userStatus?.hasOrdinal || false;
|
const hasOrdinal = userStatus?.hasOrdinal || false;
|
||||||
|
|
||||||
// Get ENS name from user verification status if available
|
// Only show a badge if the author has ENS or Ordinal ownership (not for basic verification)
|
||||||
const ensName = userStatus?.ensName;
|
const shouldShowBadge = showBadge && (hasENS || hasOrdinal);
|
||||||
|
|
||||||
|
const ensName = userStatus?.ensName || resolvedEns;
|
||||||
const displayName = ensName || `${address.slice(0, 6)}...${address.slice(-4)}`;
|
const displayName = ensName || `${address.slice(0, 6)}...${address.slice(-4)}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -31,7 +47,7 @@ export function AuthorDisplay({
|
|||||||
{displayName}
|
{displayName}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
{showBadge && isVerified && (
|
{shouldShowBadge && (
|
||||||
<Badge
|
<Badge
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
className="text-xs px-1.5 py-0.5 h-auto bg-green-900/20 border-green-500/30 text-green-400"
|
className="text-xs px-1.5 py-0.5 h-auto bg-green-900/20 border-green-500/30 text-green-400"
|
||||||
@ -41,15 +57,10 @@ export function AuthorDisplay({
|
|||||||
<Crown className="w-3 h-3 mr-1" />
|
<Crown className="w-3 h-3 mr-1" />
|
||||||
ENS
|
ENS
|
||||||
</>
|
</>
|
||||||
) : hasOrdinal ? (
|
|
||||||
<>
|
|
||||||
<Shield className="w-3 h-3 mr-1" />
|
|
||||||
Ordinal
|
|
||||||
</>
|
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<Shield className="w-3 h-3 mr-1" />
|
<Shield className="w-3 h-3 mr-1" />
|
||||||
Verified
|
Ordinal
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Badge>
|
</Badge>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user