{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ens-profile",
  "title": "ENS Profile",
  "description": "Profile card for an ENS name (forward) or address (primary name): avatar, name, address with copy, description, and website / X / GitHub / email links from text records, read on mainnet. Loading skeleton measured from the real layout (skullet) and a not-found state. Exports useEnsProfile, which can read arbitrary text records.",
  "dependencies": [
    "wagmi",
    "viem",
    "@tanstack/react-query",
    "lucide-react",
    "skullet"
  ],
  "registryDependencies": [
    "@0xui/address",
    "@0xui/address-avatar"
  ],
  "files": [
    {
      "path": "registry/default/components/ens-profile.tsx",
      "content": "// Docs: https://0xui.io/components/ens-profile.md\nimport { useQuery } from \"@tanstack/react-query\";\nimport { AtSignIcon, CodeXmlIcon, GlobeIcon, MailIcon, type LucideIcon } from \"lucide-react\";\nimport { Skeleton } from \"skullet/react\";\nimport type { Address as AddressType } from \"viem\";\nimport { normalize } from \"viem/ens\";\nimport { useEnsAddress, useEnsAvatar, useEnsName, usePublicClient } from \"wagmi\";\nimport { mainnet } from \"wagmi/chains\";\nimport { Address } from \"@/components/address\";\nimport { AddressAvatar } from \"@/components/address-avatar\";\nimport { cn } from \"@/lib/utils\";\n\n/** Text records read by default. */\nexport const defaultEnsRecords = [\"description\", \"url\", \"com.twitter\", \"com.github\", \"email\"] as const;\n\n/**\n * ENS profile for an address (reverse lookup) or a name (forward lookup):\n * name, address, avatar and text records. Reads from mainnet.\n */\nexport function useEnsProfile({\n  address: addressProp,\n  name: nameProp,\n  records = defaultEnsRecords,\n}: {\n  address?: AddressType;\n  name?: string;\n  records?: readonly string[];\n}) {\n  const client = usePublicClient({ chainId: mainnet.id });\n  const reverse = useEnsName({\n    address: addressProp,\n    chainId: mainnet.id,\n    query: { enabled: Boolean(addressProp) && !nameProp },\n  });\n  const name = nameProp ? safeNormalize(nameProp) : (reverse.data ?? undefined);\n  const forward = useEnsAddress({\n    name,\n    chainId: mainnet.id,\n    query: { enabled: Boolean(nameProp && name) },\n  });\n  const address = addressProp ?? forward.data ?? undefined;\n  const avatar = useEnsAvatar({ name, chainId: mainnet.id, query: { enabled: Boolean(name) } });\n  const texts = useQuery({\n    queryKey: [\"0xui\", \"ens-texts\", name, records],\n    queryFn: async () => {\n      const values = await Promise.all(\n        records.map((key) => client!.getEnsText({ name: name!, key }).catch(() => null))\n      );\n      return Object.fromEntries(records.map((key, i) => [key, values[i] ?? undefined])) as Record<\n        string,\n        string | undefined\n      >;\n    },\n    enabled: Boolean(name && client),\n    staleTime: 5 * 60_000,\n  });\n\n  const isLoading = reverse.isLoading || forward.isLoading || (Boolean(name) && texts.isLoading);\n  return {\n    name,\n    address,\n    avatar: avatar.data ?? undefined,\n    records: texts.data ?? {},\n    isLoading,\n    /** A name was given but has no address, or an address has no primary name. */\n    notFound: !isLoading && (nameProp ? !address : !name),\n  };\n}\n\nfunction safeNormalize(name: string) {\n  try {\n    return normalize(name);\n  } catch {\n    return undefined;\n  }\n}\n\nconst links: Record<string, { icon: LucideIcon; label: string; href: (v: string) => string; text?: (v: string) => string }> = {\n  url: { icon: GlobeIcon, label: \"Website\", href: (v) => (/^https?:\\/\\//.test(v) ? v : `https://${v}`), text: (v) => v.replace(/^https?:\\/\\//, \"\").replace(/\\/$/, \"\") },\n  \"com.twitter\": { icon: AtSignIcon, label: \"X\", href: (v) => `https://x.com/${v.replace(/^@/, \"\")}`, text: (v) => `@${v.replace(/^@/, \"\")}` },\n  \"com.github\": { icon: CodeXmlIcon, label: \"GitHub\", href: (v) => `https://github.com/${v}` },\n  email: { icon: MailIcon, label: \"Email\", href: (v) => `mailto:${v}` },\n};\n\n/** Stand-in the loading skeleton is measured from. Never shown as text. */\nconst sampleProfile = {\n  name: \"sample-name.eth\",\n  address: \"0x0000000000000000000000000000000000000001\",\n  avatar: undefined,\n} as const;\n\nexport type EnsProfileProps = {\n  /** Look up the primary name of this address. */\n  address?: AddressType;\n  /** Or look up this name directly. */\n  name?: string;\n  /** Text records to read. Known ones (url, com.twitter, com.github, email) render as links. */\n  records?: readonly string[];\n  className?: string;\n};\n\n/**\n * Profile card for an ENS name: avatar, name, address with copy, bio and\n * links from text records. Falls back to the address alone when there's no\n * primary name.\n */\nexport function EnsProfile({ address, name, records, className }: EnsProfileProps) {\n  const profile = useEnsProfile({ address, name, records });\n  const phase = profile.isLoading ? \"loading\" : profile.notFound ? \"not-found\" : \"ready\";\n  const linkKeys = Object.keys(links).filter((key) => profile.records[key]);\n  // While loading, the header is drawn from a stand-in and measured into a skeleton.\n  const shown =\n    phase === \"loading\" ? { ...sampleProfile, address: profile.address ?? sampleProfile.address } : profile;\n\n  return (\n    <article\n      data-slot=\"ens-profile\"\n      data-phase={phase}\n      className={cn(\"w-full max-w-sm rounded-2xl border p-5\", className)}\n    >\n      <Skeleton loading={phase === \"loading\"} label=\"Loading ENS profile\">\n        <div className=\"flex flex-col gap-4\">\n          <header className=\"flex items-center gap-3\">\n            {shown.address && <AddressAvatar address={shown.address} src={shown.avatar} size={56} />}\n            <div className=\"flex min-w-0 flex-col gap-0.5\">\n              <h3 className=\"truncate text-lg font-semibold\">{shown.name ?? \"No ENS name\"}</h3>\n              {shown.address && (\n                <Address address={shown.address} ens={false} className=\"text-sm text-muted-foreground\" />\n              )}\n            </div>\n          </header>\n\n          {phase === \"not-found\" && name && (\n            <p className=\"text-sm text-muted-foreground\">{name} doesn't point to an address.</p>\n          )}\n\n          {profile.records.description && <p className=\"text-sm\">{profile.records.description}</p>}\n\n          {linkKeys.length > 0 && (\n            <ul className=\"flex flex-col gap-1.5 text-sm\">\n              {linkKeys.map((key) => {\n                const link = links[key]!;\n                const value = profile.records[key]!;\n                const Icon = link.icon;\n                return (\n                  <li key={key}>\n                    <a\n                      href={link.href(value)}\n                      target={key === \"email\" ? undefined : \"_blank\"}\n                      rel=\"noopener noreferrer\"\n                      className=\"inline-flex items-center gap-2 text-muted-foreground hover:text-foreground\"\n                    >\n                      <Icon aria-hidden className=\"size-4 shrink-0\" />\n                      <span className=\"sr-only\">{link.label}: </span>\n                      {link.text ? link.text(value) : value}\n                    </a>\n                  </li>\n                );\n              })}\n            </ul>\n          )}\n        </div>\n      </Skeleton>\n    </article>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "docs": "Docs: https://0xui.io/components/ens-profile.md",
  "categories": [
    "identity"
  ],
  "type": "registry:component"
}