From dd13ef6b2ecd96e0e0851a78bb6c86b1833ee64d Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Mon, 18 Aug 2025 13:52:47 +0530 Subject: [PATCH] fix: ENS status --- src/components/ui/author-display.tsx | 33 ++++++++++++++++++---------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/components/ui/author-display.tsx b/src/components/ui/author-display.tsx index 1b2731f..56c3a7b 100644 --- a/src/components/ui/author-display.tsx +++ b/src/components/ui/author-display.tsx @@ -2,6 +2,8 @@ import React from 'react'; import { Badge } from '@/components/ui/badge'; import { Shield, Crown } from 'lucide-react'; import { UserVerificationStatus } from '@/lib/forum/types'; +import { getEnsName } from '@wagmi/core'; +import { config } from '@/lib/identity/wallets/appkit'; interface AuthorDisplayProps { address: string; @@ -17,12 +19,26 @@ export function AuthorDisplay({ showBadge = true }: AuthorDisplayProps) { const userStatus = userVerificationStatus?.[address]; - const isVerified = userStatus?.isVerified || false; - const hasENS = userStatus?.hasENS || false; + const [resolvedEns, setResolvedEns] = React.useState(undefined); + + // 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; - // Get ENS name from user verification status if available - const ensName = userStatus?.ensName; + // Only show a badge if the author has ENS or Ordinal ownership (not for basic verification) + const shouldShowBadge = showBadge && (hasENS || hasOrdinal); + + const ensName = userStatus?.ensName || resolvedEns; const displayName = ensName || `${address.slice(0, 6)}...${address.slice(-4)}`; return ( @@ -31,7 +47,7 @@ export function AuthorDisplay({ {displayName} - {showBadge && isVerified && ( + {shouldShowBadge && ( ENS - ) : hasOrdinal ? ( - <> - - Ordinal - ) : ( <> - Verified + Ordinal )}