import { useEffect, useState } from 'react' import clsx from 'clsx' import { getKnownDisplayName } from '@/utils/web3IdentityRegistry' import { resolveEnsName } from '@/utils/ens' interface AddressProps { address: string chainId?: number /** Blockscout or caller-provided label (highest precedence). */ label?: string | null showCopy?: boolean showENS?: boolean truncate?: boolean className?: string } export function Address({ address, chainId: _chainId, label, showCopy = true, showENS = false, truncate = false, className, }: AddressProps) { const [copied, setCopied] = useState(false) const [ensName, setEnsName] = useState(null) const registryLabel = getKnownDisplayName(address) useEffect(() => { if (!showENS || !address) return let active = true void resolveEnsName(address).then((name) => { if (active) setEnsName(name) }) return () => { active = false } }, [address, showENS]) const primaryLabel = label || registryLabel || (showENS ? ensName : null) || null const displayAddress = truncate ? `${address.slice(0, 6)}...${address.slice(-4)}` : address const handleCopy = async () => { try { await navigator.clipboard.writeText(address) setCopied(true) setTimeout(() => setCopied(false), 2000) } catch { setCopied(false) } } return (
{primaryLabel ? (
{primaryLabel}
) : null} {displayAddress}
{showCopy && ( )}
) }