{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"address-identity","type":"registry:ui","title":"Address Identity","description":"Resolves an EVM address to an ENS or Base name with optional avatar, copy-to-clipboard, and explorer link.","docs":"```tsx\nimport { AddressIdentity } from \"@/components/ui/address-identity\"\n\n<AddressIdentity address=\"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045\" />\n```","dependencies":["viem@2.55.19","sonner","lucide-react"],"devDependencies":[],"registryDependencies":["@onchain-ui/sonner"],"files":[{"path":"registry/onchain-ui/address-identity.tsx","type":"registry:ui","target":"components/ui/address-identity.tsx","content":"\"use client\";\n\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport { cn } from \"@/lib/utils\";\nimport { truncateAddress } from \"@/lib/onchain/format\";\nimport {\n  resolveOnchainIdentity,\n  resolveNameAvatar,\n  type OnchainIdentity,\n  type OnchainResolverOptions,\n} from \"@/lib/onchain/resolvers\";\nimport {\n  AddressDisplay,\n  type AddressDisplayProps,\n} from \"./address-display\";\nimport type { Address } from \"viem\";\n\nexport interface AddressIdentityProps\n  extends Omit<AddressDisplayProps, \"label\" | \"address\"> {\n  /** EVM wallet address */\n  address: Address;\n  /** Resolved name override, e.g. vitalik.eth or alice.base.eth */\n  name?: string | null | undefined;\n  /** Avatar URL override */\n  avatarUrl?: string | null | undefined;\n  /** Resolve ENS/Base name and avatar. Default: true */\n  resolveIdentity?: boolean | undefined;\n  /** Resolver client and lookup overrides */\n  resolverOptions?: OnchainResolverOptions | undefined;\n  /** Show avatar when available. Default: true */\n  showAvatar?: boolean | undefined;\n  /** Applied to the root wrapper */\n  className?: string | undefined;\n  /** Applied to the avatar */\n  avatarClassName?: string | undefined;\n  /** Applied to the identity text group */\n  contentClassName?: string | undefined;\n}\n\nexport function AddressIdentity({\n  address,\n  name,\n  avatarUrl,\n  resolveIdentity = true,\n  resolverOptions,\n  showAvatar = true,\n  className,\n  avatarClassName,\n  contentClassName,\n  truncate = true,\n  truncateChars = 4,\n  ...addressDisplayProps\n}: AddressIdentityProps) {\n  const identityKey = `${address}:${name ?? \"\"}:${avatarUrl ?? \"\"}:${resolveIdentity}`;\n  const [resolvedIdentity, setResolvedIdentity] = useState<{\n    key: string;\n    identity: OnchainIdentity;\n  } | null>(null);\n  const [avatarFailure, setAvatarFailure] = useState<{\n    src: string;\n    attempts: number;\n  } | null>(null);\n\n  // Read resolver options through a ref so inline object literals don't\n  // retrigger resolution on every render.\n  const resolverOptionsRef = useRef(resolverOptions);\n  useEffect(() => {\n    resolverOptionsRef.current = resolverOptions;\n  });\n\n  useEffect(() => {\n    if (!resolveIdentity || (name && avatarUrl)) return;\n\n    let isMounted = true;\n    const options = resolverOptionsRef.current;\n\n    const identityPromise = name\n      ? resolveNameAvatar(name, options).then((avatar) => ({\n          address,\n          name,\n          avatar,\n          source: name.endsWith(\".base.eth\") ? \"basename\" : \"ens\",\n        }) satisfies OnchainIdentity)\n      : resolveOnchainIdentity(address, options);\n\n    identityPromise\n      .then((result) => {\n        if (isMounted) {\n          setResolvedIdentity({ key: identityKey, identity: result });\n        }\n      });\n\n    return () => {\n      isMounted = false;\n    };\n  }, [address, avatarUrl, identityKey, name, resolveIdentity]);\n\n  const activeIdentity =\n    resolvedIdentity?.key === identityKey ? resolvedIdentity.identity : null;\n  const displayName = name ?? activeIdentity?.name ?? null;\n  const resolvedAvatar = avatarUrl ?? activeIdentity?.avatar ?? null;\n  const displayAvatar =\n    resolvedAvatar !== null &&\n    !(avatarFailure?.src === resolvedAvatar && avatarFailure.attempts >= 2)\n      ? resolvedAvatar\n      : null;\n  const isLoading =\n    resolveIdentity && !(name && avatarUrl) && activeIdentity === null;\n  const fallbackLabel = truncate\n    ? truncateAddress(address, truncateChars)\n    : address;\n  const label = displayName ?? fallbackLabel;\n\n  const avatarFallback = useMemo(() => {\n    if (displayName) return displayName.slice(0, 2).toUpperCase();\n    return address.slice(2, 4).toUpperCase();\n  }, [address, displayName]);\n\n  return (\n    <div className={cn(\"flex min-w-0 items-center gap-2\", className)}>\n      {showAvatar && (\n        <span\n          className={cn(\n            \"flex size-7 shrink-0 items-center justify-center overflow-hidden rounded-full border bg-muted text-[10px] font-medium text-muted-foreground\",\n            isLoading && \"animate-pulse\",\n            avatarClassName\n          )}\n          aria-hidden=\"true\"\n        >\n          {displayAvatar ? (\n            <img\n              key={`${displayAvatar}:${avatarFailure?.src === displayAvatar ? avatarFailure.attempts : 0}`}\n              src={displayAvatar}\n              alt=\"\"\n              className=\"size-full object-cover\"\n              referrerPolicy=\"no-referrer\"\n              onError={() =>\n                setAvatarFailure((failure) => ({\n                  src: displayAvatar,\n                  attempts:\n                    failure?.src === displayAvatar ? failure.attempts + 1 : 1,\n                }))\n              }\n            />\n          ) : (\n            avatarFallback\n          )}\n        </span>\n      )}\n\n      <AddressDisplay\n        address={address}\n        label={label}\n        truncate={truncate}\n        truncateChars={truncateChars}\n        className={contentClassName}\n        {...addressDisplayProps}\n      />\n    </div>\n  );\n}\n"},{"path":"registry/onchain-ui/address-display.tsx","type":"registry:ui","target":"components/ui/address-display.tsx","content":"\"use client\";\n\nimport { toast } from \"sonner\";\nimport { CopyIcon, ExternalLinkIcon } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\nimport { truncateAddress } from \"@/lib/onchain/format\";\nimport { getDefaultChainId, getExplorerUrl } from \"@/lib/onchain/config\";\nimport type { Address } from \"viem\";\nimport type { ReactNode } from \"react\";\n\nexport interface AddressDisplayProps {\n  /** EVM wallet address */\n  address: Address;\n  /** Display label. The copied value is always the underlying address. */\n  label?: ReactNode | undefined;\n  /** Applied to the root wrapper */\n  className?: string | undefined;\n  /** Applied to the address text or copy trigger */\n  addressClassName?: string | undefined;\n  /** Truncate the address. Default: true */\n  truncate?: boolean | undefined;\n  /** Number of characters to show at each end when truncated. Default: 4 */\n  truncateChars?: number | undefined;\n  /** Show copy-to-clipboard button. Default: true */\n  showCopy?: boolean | undefined;\n  /** Show block explorer link. Default: true */\n  showExplorer?: boolean | undefined;\n  /** EVM chain id used to pick a known block explorer. Default: onchainConfig.defaultChainId, else 1 */\n  chainId?: number | null | undefined;\n  /** Full explorer URL override e.g. \"https://basescan.org/address/0x...\" */\n  explorerUrl?: string | undefined;\n  /** Icon rendered before the address when copy is enabled */\n  copyIcon?: ReactNode | undefined;\n  /** Icon rendered for the explorer link */\n  explorerIcon?: ReactNode | undefined;\n  /** Type size of the address. Default: xs */\n  size?: keyof typeof sizeClasses | undefined;\n}\n\n// A variant rather than a className override, so the address can match a\n// dense table or the sentence around it.\nconst sizeClasses = { \"2xs\": \"text-[0.625rem]\", xs: \"text-xs\", sm: \"text-sm\" } as const;\n\nexport function AddressDisplay({\n  address,\n  label,\n  className,\n  addressClassName,\n  truncate = true,\n  truncateChars = 4,\n  showCopy = true,\n  showExplorer = true,\n  chainId,\n  explorerUrl,\n  copyIcon = <CopyIcon className=\"size-3 shrink-0\" />,\n  explorerIcon = <ExternalLinkIcon className=\"size-3 shrink-0\" />,\n  size = \"xs\",\n}: AddressDisplayProps) {\n  const handleCopy = async () => {\n    try {\n      await navigator.clipboard.writeText(address);\n      toast.success(\"Address copied\");\n    } catch {\n      toast.error(\"Could not copy address\");\n    }\n  };\n\n  // No chain id means the configured default (mainnet unless set). A chain id we\n  // do not recognise is different: linking it to Etherscan would point at a\n  // page about a different chain's address space. Drop the link instead and\n  // let `explorerUrl` cover the long tail.\n  const explorerBase = getExplorerUrl(chainId ?? getDefaultChainId());\n  const href =\n    explorerUrl ??\n    (explorerBase ? `${explorerBase}/address/${address}` : null);\n  const displayLabel =\n    label ?? (truncate ? truncateAddress(address, truncateChars) : address);\n  const labelClassName = truncate ? \"whitespace-nowrap\" : \"break-all\";\n\n  return (\n    // A span, so the address can sit inside a sentence or a table cell's text\n    // (a div is invalid inside <p>).\n    <span className={cn(\"inline-flex min-w-0 items-center gap-1.5\", className)}>\n      {showCopy ? (\n        <button\n          type=\"button\"\n          onClick={handleCopy}\n          title=\"Copy address\"\n          className={cn(\n            \"flex min-w-0 items-center gap-1.5 font-mono text-muted-foreground\",\n            sizeClasses[size],\n            \"hover:text-foreground cursor-copy transition-colors duration-150\",\n            addressClassName\n          )}\n        >\n          {copyIcon}\n          <span className={labelClassName}>{displayLabel}</span>\n        </button>\n      ) : (\n        <span\n          className={cn(\n            \"min-w-0 font-mono text-muted-foreground\",\n            sizeClasses[size],\n            labelClassName,\n            addressClassName\n          )}\n        >\n          {displayLabel}\n        </span>\n      )}\n\n      {showExplorer && href && (\n        <a\n          href={href}\n          target=\"_blank\"\n          rel=\"noopener noreferrer\"\n          title=\"View on explorer\"\n          className=\"text-muted-foreground hover:text-foreground transition-colors duration-150\"\n        >\n          {explorerIcon}\n        </a>\n      )}\n    </span>\n  );\n}\n"},{"path":"lib/onchain/format.ts","type":"registry:lib","target":"lib/onchain/format.ts","content":"export function truncateAddress(address: string, chars = 4): string {\n  if (!address) return \"\";\n\n  return `${address.slice(0, chars + 2)}…${address.slice(-chars)}`;\n}\n\nexport type NumericValue = number | string | null | undefined;\n\n/** Parses numbers and numeric strings; anything else becomes null. */\nexport function parseNumericValue(value: NumericValue): number | null {\n  if (typeof value === \"number\") return Number.isFinite(value) ? value : null;\n  if (typeof value === \"string\" && value.trim() !== \"\") {\n    const parsed = Number(value);\n    return Number.isFinite(parsed) ? parsed : null;\n  }\n  return null;\n}\n\n"},{"path":"lib/onchain/resolvers.ts","type":"registry:lib","target":"lib/onchain/resolvers.ts","content":"import {\n  createPublicClient,\n  encodePacked,\n  fallback,\n  http,\n  isAddress,\n  keccak256,\n  namehash,\n  zeroAddress,\n  type Address,\n  type AssetGatewayUrls,\n  type Hex,\n  type PublicClient,\n} from \"viem\";\nimport { normalize, parseAvatarRecord } from \"viem/ens\";\nimport { base, mainnet } from \"viem/chains\";\nimport {\n  getConfiguredAvatarGatewayUrls,\n  getConfiguredClient,\n  type OnchainReadClient,\n} from \"./config\";\n\nexport const BASENAME_L2_RESOLVER_ADDRESS =\n  \"0xC6d566A56A1aFf6508b41f6c90ff131615583BCD\";\n\nconst baseNamesAbi = [\n  {\n    inputs: [{ internalType: \"bytes32\", name: \"node\", type: \"bytes32\" }],\n    name: \"name\",\n    outputs: [{ internalType: \"string\", name: \"\", type: \"string\" }],\n    stateMutability: \"view\",\n    type: \"function\",\n  },\n  {\n    inputs: [\n      { internalType: \"bytes32\", name: \"node\", type: \"bytes32\" },\n      { internalType: \"string\", name: \"key\", type: \"string\" },\n    ],\n    name: \"text\",\n    outputs: [{ internalType: \"string\", name: \"\", type: \"string\" }],\n    stateMutability: \"view\",\n    type: \"function\",\n  },\n  {\n    inputs: [{ internalType: \"bytes32\", name: \"node\", type: \"bytes32\" }],\n    name: \"addr\",\n    outputs: [{ internalType: \"address\", name: \"\", type: \"address\" }],\n    stateMutability: \"view\",\n    type: \"function\",\n  },\n] as const;\n\nexport interface OnchainResolverOptions {\n  mainnetClient?: OnchainReadClient | undefined;\n  baseClient?: OnchainReadClient | undefined;\n  basenameResolverAddress?: Address | undefined;\n  avatarGatewayUrls?: AssetGatewayUrls | undefined;\n  reverseLookupOrder?: Array<\"ens\" | \"basename\"> | undefined;\n}\n\nexport interface OnchainIdentity {\n  address: Address;\n  name: string | null;\n  avatar: string | null;\n  source: \"ens\" | \"basename\" | null;\n}\n\n// The default clients use each chain's public RPC endpoint, with a fallback:\n// viem's default mainnet endpoint (eth.merkle.io) aggressively rate limits\n// some IPs, which would otherwise silently break name resolution. Public\n// endpoints are fine for demos; pass your own clients through\n// `OnchainResolverOptions` in production.\nfunction createDefaultMainnetClient() {\n  return createPublicClient({\n    chain: mainnet,\n    transport: fallback([\n      http(),\n      http(\"https://ethereum-rpc.publicnode.com\"),\n    ]),\n  });\n}\n\nfunction createDefaultBaseClient() {\n  return createPublicClient({\n    chain: base,\n    transport: fallback([http(), http(\"https://base-rpc.publicnode.com\")]),\n  });\n}\n\nlet defaultMainnetClient:\n  | ReturnType<typeof createDefaultMainnetClient>\n  | undefined;\nlet defaultBaseClient: ReturnType<typeof createDefaultBaseClient> | undefined;\n\n// Precedence is per-instance, then app-wide, then the public fallback above.\n// The middle step is what stops an app that already configured RPC endpoints\n// (in wagmi, say) from having to configure them a second time here.\nfunction getMainnetClient(options?: OnchainResolverOptions) {\n  if (options?.mainnetClient) return options.mainnetClient;\n\n  const configured = getConfiguredClient(mainnet.id);\n  if (configured) return configured;\n\n  if (!defaultMainnetClient) defaultMainnetClient = createDefaultMainnetClient();\n  return defaultMainnetClient;\n}\n\nfunction getBaseClient(options?: OnchainResolverOptions) {\n  if (options?.baseClient) return options.baseClient;\n\n  const configured = getConfiguredClient(base.id);\n  if (configured) return configured;\n\n  if (!defaultBaseClient) defaultBaseClient = createDefaultBaseClient();\n  return defaultBaseClient;\n}\n\nfunction getBasenameResolverAddress(options?: OnchainResolverOptions) {\n  return options?.basenameResolverAddress ?? BASENAME_L2_RESOLVER_ADDRESS;\n}\n\nfunction getAvatarGatewayUrls(options?: OnchainResolverOptions) {\n  return (\n    options?.avatarGatewayUrls ??\n    getConfiguredAvatarGatewayUrls() ?? {\n      ipfs: \"https://gateway.pinata.cloud\",\n      arweave: \"https://arweave.net\",\n    }\n  );\n}\n\nexport function convertChainIdToCoinType(chainId: number): string {\n  if (chainId === mainnet.id) return \"addr\";\n\n  const coinType = (0x80000000 | chainId) >>> 0;\n  return coinType.toString(16).toUpperCase();\n}\n\nexport function convertReverseNodeToBytes(address: Address, chainId: number) {\n  const addressFormatted = address.toLowerCase() as Address;\n  const addressNode = keccak256(addressFormatted.substring(2) as Hex);\n  const chainCoinType = convertChainIdToCoinType(chainId);\n  const baseReverseNode = namehash(`${chainCoinType}.reverse`);\n\n  return keccak256(\n    encodePacked([\"bytes32\", \"bytes32\"], [baseReverseNode, addressNode])\n  );\n}\n\n// Internal lookups report failures instead of collapsing them into null, so\n// callers can tell \"no record exists\" (cacheable) from \"the RPC call failed\"\n// (must not be cached). The exported resolve* functions keep returning null\n// for both.\ntype LookupResult<T> = { value: T; failed: boolean };\n\nasync function lookupEnsName(\n  address: Address,\n  options?: OnchainResolverOptions\n): Promise<LookupResult<string | null>> {\n  try {\n    const name = await getMainnetClient(options).getEnsName({ address });\n    return { value: name, failed: false };\n  } catch {\n    return { value: null, failed: true };\n  }\n}\n\nasync function lookupBasename(\n  address: Address,\n  options?: OnchainResolverOptions\n): Promise<LookupResult<string | null>> {\n  try {\n    const reverseNode = convertReverseNodeToBytes(address, base.id);\n\n    const name = await getBaseClient(options).readContract({\n      abi: baseNamesAbi,\n      address: getBasenameResolverAddress(options),\n      functionName: \"name\",\n      args: [reverseNode],\n    });\n\n    return { value: name || null, failed: false };\n  } catch {\n    return { value: null, failed: true };\n  }\n}\n\nexport async function resolveEnsName(\n  address: Address,\n  options?: OnchainResolverOptions\n) {\n  return (await lookupEnsName(address, options)).value;\n}\n\nexport async function resolveBasename(\n  address: Address,\n  options?: OnchainResolverOptions\n) {\n  return (await lookupBasename(address, options)).value;\n}\n\n// Session-level caches so repeated lookups (portfolio rows, remounts) don't\n// refetch. Keyed lookups share in-flight promises, deduping concurrent calls.\n// Failed lookups are evicted once settled so transient RPC errors are retried\n// instead of pinning \"no result\" for the whole session.\n//\n// Caches are scoped per resolver config: results from different clients or a\n// different Basename resolver must not mix. Scopes are keyed on the client\n// instances via WeakMap so a custom client keeps request deduplication, and\n// short-lived clients get garbage collected along with their cache.\ntype ResolverCaches = {\n  avatar: Map<string, Promise<LookupResult<string | null>>>;\n  identity: Map<string, Promise<LookupResult<OnchainIdentity>>>;\n};\n\nconst defaultMainnetScope = {};\nconst defaultBaseScope = {};\n\nconst cacheScopes = new WeakMap<\n  object,\n  WeakMap<object, Map<string, ResolverCaches>>\n>();\n\nfunction getResolverCaches(options?: OnchainResolverOptions): ResolverCaches {\n  const mainnetScope = options?.mainnetClient ?? defaultMainnetScope;\n  const baseScope = options?.baseClient ?? defaultBaseScope;\n  const resolverAddress = getBasenameResolverAddress(options).toLowerCase();\n  const gatewayUrls = getAvatarGatewayUrls(options);\n  const resolverConfigKey = [\n    resolverAddress,\n    gatewayUrls.ipfs ?? \"\",\n    gatewayUrls.arweave ?? \"\",\n  ].join(\":\");\n\n  let baseScopes = cacheScopes.get(mainnetScope);\n  if (!baseScopes) {\n    baseScopes = new WeakMap();\n    cacheScopes.set(mainnetScope, baseScopes);\n  }\n\n  let resolverScopes = baseScopes.get(baseScope);\n  if (!resolverScopes) {\n    resolverScopes = new Map();\n    baseScopes.set(baseScope, resolverScopes);\n  }\n\n  let caches = resolverScopes.get(resolverConfigKey);\n  if (!caches) {\n    caches = { avatar: new Map(), identity: new Map() };\n    resolverScopes.set(resolverConfigKey, caches);\n  }\n\n  return caches;\n}\n\nexport async function resolveNameAvatar(\n  name: string,\n  options?: OnchainResolverOptions\n) {\n  return (await lookupNameAvatarWithRetry(name, options)).value;\n}\n\n/** Retry one transient RPC failure before exposing the avatar as unavailable. */\nasync function lookupNameAvatarWithRetry(\n  name: string,\n  options?: OnchainResolverOptions\n): Promise<LookupResult<string | null>> {\n  const first = await lookupNameAvatarCached(name, options);\n  if (!first.failed) return first;\n\n  // Failed cached lookups evict themselves, so this is a fresh RPC attempt.\n  return lookupNameAvatarCached(name, options);\n}\n\nasync function lookupNameAvatarCached(\n  name: string,\n  options?: OnchainResolverOptions\n): Promise<LookupResult<string | null>> {\n  const cache = getResolverCaches(options).avatar;\n\n  const cached = cache.get(name);\n  if (cached) return cached;\n\n  const promise = lookupNameAvatar(name, options);\n  cache.set(name, promise);\n\n  const result = await promise;\n  if (result.failed) cache.delete(name);\n  return result;\n}\n\nasync function lookupNameAvatar(\n  name: string,\n  options?: OnchainResolverOptions\n): Promise<LookupResult<string | null>> {\n  try {\n    if (name.endsWith(\".base.eth\")) {\n      // The Basename L2 resolver is a plain resolver, not an ENS universal\n      // resolver, so viem's getEnsAvatar reverts against it. Read the avatar\n      // text record directly instead.\n      const client = getBaseClient(options);\n      const record = await client.readContract({\n        abi: baseNamesAbi,\n        address: getBasenameResolverAddress(options),\n        functionName: \"text\",\n        args: [namehash(normalize(name)), \"avatar\"],\n      });\n\n      if (!record) return { value: null, failed: false };\n      return {\n        // parseAvatarRecord only consumes read actions, but viem types it as a\n        // full client. The configured seam deliberately accepts less.\n        value: await parseAvatarRecord(client as PublicClient, {\n          record,\n          gatewayUrls: getAvatarGatewayUrls(options),\n        }),\n        failed: false,\n      };\n    }\n\n    const avatar = await getMainnetClient(options).getEnsAvatar({\n      name,\n      assetGatewayUrls: getAvatarGatewayUrls(options),\n    });\n    return { value: avatar, failed: false };\n  } catch {\n    return { value: null, failed: true };\n  }\n}\n\nexport async function resolveAddress(\n  input: string,\n  options?: OnchainResolverOptions\n): Promise<Address | null> {\n  if (isAddress(input)) return input;\n\n  try {\n    if (input.endsWith(\".base.eth\")) {\n      // Direct resolver read; see fetchNameAvatar for why getEnsAddress with\n      // a universalResolverAddress override does not work for Basenames.\n      const address = await getBaseClient(options).readContract({\n        abi: baseNamesAbi,\n        address: getBasenameResolverAddress(options),\n        functionName: \"addr\",\n        args: [namehash(normalize(input))],\n      });\n\n      return address && address !== zeroAddress ? address : null;\n    }\n\n    if (input.endsWith(\".eth\")) {\n      return await getMainnetClient(options).getEnsAddress({ name: input });\n    }\n  } catch {\n    return null;\n  }\n\n  return null;\n}\n\nexport async function resolveOnchainIdentity(\n  address: Address,\n  options?: OnchainResolverOptions\n): Promise<OnchainIdentity> {\n  const reverseLookupOrder = options?.reverseLookupOrder ?? [\n    \"basename\",\n    \"ens\",\n  ];\n\n  const cache = getResolverCaches(options).identity;\n  const cacheKey = `${address.toLowerCase()}:${reverseLookupOrder.join(\",\")}`;\n\n  const cached = cache.get(cacheKey);\n  if (cached) return (await cached).value;\n\n  const promise = lookupOnchainIdentity(address, reverseLookupOrder, options);\n  cache.set(cacheKey, promise);\n\n  const result = await promise;\n  if (result.failed) cache.delete(cacheKey);\n  return result.value;\n}\n\nasync function lookupOnchainIdentity(\n  address: Address,\n  reverseLookupOrder: Array<\"ens\" | \"basename\">,\n  options?: OnchainResolverOptions\n): Promise<LookupResult<OnchainIdentity>> {\n  let failed = false;\n\n  for (const source of reverseLookupOrder) {\n    const name =\n      source === \"basename\"\n        ? await lookupBasename(address, options)\n        : await lookupEnsName(address, options);\n\n    if (name.failed) failed = true;\n\n    if (name.value) {\n      const avatar = await lookupNameAvatarWithRetry(name.value, options);\n\n      return {\n        value: {\n          address,\n          name: name.value,\n          avatar: avatar.value,\n          source,\n        },\n        failed: failed || avatar.failed,\n      };\n    }\n  }\n\n  return {\n    value: {\n      address,\n      name: null,\n      avatar: null,\n      source: null,\n    },\n    failed,\n  };\n}\n"},{"path":"lib/onchain/config.ts","type":"registry:lib","target":"lib/onchain/config.ts","content":"import {\n  arbitrum,\n  base,\n  mainnet,\n  optimism,\n  polygon,\n  robinhood,\n} from \"viem/chains\";\nimport type { AssetGatewayUrls, Chain, PublicClient } from \"viem\";\n\n/** The small client surface identity resolution actually consumes. */\nexport type OnchainReadClient = Pick<\n  PublicClient,\n  \"getEnsAddress\" | \"getEnsAvatar\" | \"getEnsName\" | \"readContract\"\n>;\n\n/**\n * The single place onchain-ui components look for app-wide settings.\n *\n * This file is yours: edit it once and every component follows. There is no\n * provider and no context — components import these functions directly, so\n * they work the same in a server component, a test, or a non-React consumer.\n *\n * Per-instance overrides always win. `<NetworkLogo name=\"…\" />` and\n * `<AddressDisplay explorerUrl=\"…\" />` beat anything configured here.\n */\n\nexport interface OnchainUIConfig {\n  /**\n   * Chains your app supports. Supplies block explorer URLs and display names\n   * for networks that have no built-in entry below.\n   *\n   * Using wagmi? Point this at the config you already wrote:\n   *\n   * ```ts\n   * import { wagmiConfig } from \"@/lib/onchain/wagmi\";\n   * chains: wagmiConfig.chains,\n   * ```\n   */\n  chains: readonly Chain[];\n\n  /**\n   * Returns a viem client for reads that are not tied to a rendered component\n   * — currently ENS and Basename resolution. Leave undefined to use the public\n   * endpoints below.\n   *\n   * Using wagmi? Share its transports instead of configuring RPC twice:\n   *\n   * ```ts\n   * import { getPublicClient } from \"@wagmi/core\";\n   * import { wagmiConfig } from \"@/lib/onchain/wagmi\";\n   * getClient: (chainId) => getPublicClient(wagmiConfig, { chainId }),\n   * ```\n   */\n  getClient?: (chainId: number) => OnchainReadClient | undefined;\n\n  /**\n   * Public gateways used to turn IPFS and Arweave avatar records into URLs.\n   * Replace these with your own gateway in production when reliability or\n   * rate limits matter.\n   */\n  avatarGatewayUrls?: AssetGatewayUrls | undefined;\n\n  /**\n   * The chain an address is assumed to live on when a component is given no\n   * chain id. Default: 1 (Ethereum). An app on one L2 sets its own, or every\n   * explorer link points at the wrong chain.\n   */\n  defaultChainId?: number | undefined;\n}\n\nexport const onchainConfig: OnchainUIConfig = {\n  chains: [mainnet, base, arbitrum, optimism, polygon, robinhood],\n  avatarGatewayUrls: {\n    ipfs: \"https://gateway.pinata.cloud\",\n    arweave: \"https://arweave.net\",\n  },\n};\n\n/**\n * Curated network names and symbols.\n *\n * These are deliberately not derived from the viem chain: `chain.name` gives\n * \"OP Mainnet\" where a badge wants \"Optimism\", and `nativeCurrency.symbol`\n * gives \"ETH\" for Base, Optimism, and Arbitrum alike, which is useless as a\n * network mark. Chains absent here fall back to the configured chain's name.\n */\nconst knownNetworks: Partial<\n  Record<number, { name: string; symbol: string }>\n> = {\n  1: { name: \"Ethereum\", symbol: \"ETH\" },\n  10: { name: \"Optimism\", symbol: \"OP\" },\n  137: { name: \"Polygon\", symbol: \"POL\" },\n  4663: { name: \"Robinhood Chain\", symbol: \"RH\" },\n  8453: { name: \"Base\", symbol: \"BASE\" },\n  42161: { name: \"Arbitrum\", symbol: \"ARB\" },\n};\n\nfunction findChain(chainId?: number | null) {\n  if (chainId == null) return null;\n  return onchainConfig.chains.find((chain) => chain.id === chainId) ?? null;\n}\n\nexport interface NetworkMeta {\n  name: string | null;\n  symbol: string | null;\n}\n\n/** Display name and symbol for a chain, or nulls when it is unrecognised. */\nexport function getNetworkMeta(chainId?: number | null): NetworkMeta {\n  if (chainId == null) return { name: null, symbol: null };\n\n  const known = knownNetworks[chainId];\n  if (known) return known;\n\n  return { name: findChain(chainId)?.name ?? null, symbol: null };\n}\n\n/**\n * Block explorer base URL for a chain, or null when we have none.\n *\n * Derived from the configured chains rather than a second hardcoded map —\n * viem's chain objects already carry `blockExplorers`. Null is a real answer:\n * an address on an unrecognised chain does not exist in mainnet's address\n * space, so callers render no link rather than a misleading one.\n */\nexport function getExplorerUrl(chainId?: number | null): string | null {\n  const chain = findChain(chainId);\n  return chain?.blockExplorers?.default.url ?? null;\n}\n\n/** The chain to assume when a component is given none. */\nexport function getDefaultChainId(): number {\n  return onchainConfig.defaultChainId ?? 1;\n}\n\n/** A read client for `chainId`, if the app configured one. */\nexport function getConfiguredClient(\n  chainId: number\n): OnchainReadClient | undefined {\n  return onchainConfig.getClient?.(chainId);\n}\n\n/** App-wide gateways for ENS and Basename avatar assets, if configured. */\nexport function getConfiguredAvatarGatewayUrls(): AssetGatewayUrls | undefined {\n  return onchainConfig.avatarGatewayUrls;\n}\n"}]}