'use client'; import { useAttestations } from '@/identity/hooks/useAttestations'; import { COINBASE_VERIFIED_ACCOUNT_SCHEMA_ID } from '@/identity/constants'; import type { BadgeProps } from '@/identity/types'; import { badgeSvg } from '@/internal/svg/badgeSvg'; import { zIndex } from '@/styles/constants'; import { cn, pressable, text } from '@/styles/theme'; import { useMemo, useState } from 'react'; import { useOnchainKit } from '../../useOnchainKit'; import { useIdentityContext } from './IdentityProvider'; type ExtractAttestationNameParams = { decodedDataJson?: string; id?: string; attester?: string; expirationTime?: number; recipient?: string; revocationTime?: number; revoked?: boolean; schemaId?: string; time?: number; }; /** * Badge component. */ export function Badge({ className, tooltip = false }: BadgeProps) { const [showTooltip, setShowTooltip] = useState(false); const { address, schemaId: contextSchemaId } = useIdentityContext(); const { chain } = useOnchainKit(); const attestations = useAttestations({ address, chain, schemaId: tooltip ? (contextSchemaId ?? COINBASE_VERIFIED_ACCOUNT_SCHEMA_ID) : null, }); // Get tooltip text from tooltip prop or attestation const displayText = useMemo(() => { if (!tooltip) { return null; } return typeof tooltip === 'string' ? tooltip : extractAttestationName(attestations[0]); }, [tooltip, attestations]); const ariaLabel = useMemo(() => { if (displayText) { return `Verification badge: ${displayText}`; } return 'Verification badge'; }, [displayText]); const badgeSize = '12px'; return (