{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "account",
  "title": "Account",
  "description": "Connected-account button: avatar plus ENS name or truncated address (morphing from one to the other when the name resolves), optional balance. Opens a popover panel with the balance, current chain, copy address, explorer link, connector name and disconnect, plus a children slot for app links. Renders nothing when disconnected. Exports useConnectedAccount. When more than one wallet is connected, the panel lists the others under 'Switch account' (useConnections, useSwitchConnection).",
  "dependencies": [
    "wagmi",
    "lucide-react"
  ],
  "registryDependencies": [
    "button",
    "popover",
    "@0xui/address-avatar",
    "@0xui/balance",
    "@0xui/chain-badge",
    "@0xui/copy-button",
    "@0xui/explorer-link",
    "@0xui/0xui-utils",
    "@0xui/morph-text"
  ],
  "files": [
    {
      "path": "registry/default/components/account.tsx",
      "content": "// Docs: https://0xui.io/components/account.md\nimport { ChevronDownIcon, LogOutIcon } from \"lucide-react\";\nimport { useState, type ReactNode } from \"react\";\nimport {\n  useConnection,\n  useConnections,\n  useDisconnect,\n  useEnsName,\n  useSwitchConnection,\n  type Connector,\n} from \"wagmi\";\nimport { mainnet } from \"wagmi/chains\";\nimport { AddressAvatar } from \"@/components/address-avatar\";\nimport { Balance } from \"@/components/balance\";\nimport { ChainBadge } from \"@/components/chain-badge\";\nimport { CopyButton } from \"@/components/copy-button\";\nimport { ExplorerLink } from \"@/components/explorer-link\";\nimport { MorphText } from \"@/components/morph-text\";\nimport { Button } from \"@/components/ui/button\";\nimport {\n  Popover,\n  PopoverContent,\n  PopoverTrigger,\n} from \"@/components/ui/popover\";\nimport { truncateAddress } from \"@/lib/0xui-utils\";\nimport { cn } from \"@/lib/utils\";\n\n/**\n * The connected account with its ENS name, plus disconnect. When more than\n * one wallet is connected, `otherAccounts` lists the rest and\n * `switchAccount` makes one of them the current account.\n */\nexport function useConnectedAccount() {\n  const { address, connector, chain, chainId, status } = useConnection();\n  const { data: ensName } = useEnsName({\n    address,\n    chainId: mainnet.id,\n    query: { enabled: Boolean(address) },\n  });\n  const { mutate: disconnect, isPending: isDisconnecting } = useDisconnect();\n  const connections = useConnections();\n  const { mutate: switchConnection, isPending: isSwitching } = useSwitchConnection();\n  const otherAccounts = connections.flatMap((connection) =>\n    connection.connector.uid === connector?.uid || !connection.accounts[0]\n      ? []\n      : [{ address: connection.accounts[0], connector: connection.connector }]\n  );\n\n  return {\n    address,\n    ensName: ensName ?? undefined,\n    displayName: ensName ?? (address ? truncateAddress(address) : undefined),\n    connector,\n    chain,\n    chainId,\n    status,\n    disconnect: () => disconnect({ connector }),\n    isDisconnecting,\n    otherAccounts,\n    switchAccount: (to: Connector) => switchConnection({ connector: to }),\n    isSwitching,\n  };\n}\n\nexport type AccountProps = {\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  /** Show the native balance in the trigger. */\n  showBalance?: boolean;\n  /** Called after the wallet disconnects. */\n  onDisconnect?: () => void;\n  /** Extra content at the bottom of the panel, e.g. links to your app's account pages. */\n  children?: ReactNode;\n  className?: string;\n};\n\n/**\n * Connected-account button: avatar and ENS name or address. Opens a panel\n * with balance, copy, explorer link, the other connected wallets to switch\n * to, and disconnect. Renders nothing when no\n * wallet is connected. For a single button that handles both states, use\n * WalletButton.\n */\nexport function Account({\n  open: openProp,\n  defaultOpen = false,\n  onOpenChange,\n  showBalance = false,\n  onDisconnect,\n  children,\n  className,\n}: AccountProps) {\n  const account = useConnectedAccount();\n  const [openState, setOpenState] = useState(defaultOpen);\n  const open = openProp ?? openState;\n  const setOpen = (next: boolean) => {\n    setOpenState(next);\n    onOpenChange?.(next);\n  };\n\n  if (!account.address) return null;\n  const { address, displayName, ensName, connector, chainId } = account;\n\n  return (\n    <Popover open={open} onOpenChange={setOpen}>\n      <PopoverTrigger\n        className={cn(\n          \"inline-flex h-10 items-center gap-2 rounded-full border bg-background py-1 pr-3 pl-1 text-sm font-medium outline-none\",\n          \"hover:bg-muted focus-visible:ring-3 focus-visible:ring-ring/50\",\n          className\n        )}\n      >\n        <AddressAvatar address={address} size={30} />\n        {showBalance && (\n          <Balance className=\"text-muted-foreground\" maxDecimals={3} />\n        )}\n        {/* Morphs from the address to the ENS name when it resolves. */}\n        <span className={cn(!ensName && \"font-mono\")}>\n          <MorphText>{displayName}</MorphText>\n        </span>\n        <ChevronDownIcon\n          aria-hidden\n          className={cn(\"size-4 transition-transform\", open && \"rotate-180\")}\n        />\n      </PopoverTrigger>\n      <PopoverContent align=\"end\" className=\"flex w-72 flex-col gap-4 p-4\">\n        <div className=\"flex items-center gap-3\">\n          <AddressAvatar address={address} size={44} />\n          <div className=\"flex min-w-0 flex-col\">\n            <span className={cn(\"truncate font-medium\", !ensName && \"font-mono\")}>\n              <MorphText>{displayName}</MorphText>\n            </span>\n            {ensName && (\n              <span className=\"truncate font-mono text-xs text-muted-foreground\">\n                {truncateAddress(address)}\n              </span>\n            )}\n          </div>\n          <CopyButton\n            value={address}\n            label=\"Copy address\"\n            className=\"ml-auto\"\n          />\n        </div>\n\n        <div className=\"flex flex-col gap-1\">\n          <span className=\"text-xs text-muted-foreground\">Balance</span>\n          <Balance className=\"text-2xl font-semibold\" />\n        </div>\n\n        <div className=\"flex items-center justify-between gap-2 text-sm\">\n          {chainId !== undefined && <ChainBadge chainId={chainId} />}\n          <ExplorerLink address={address} className=\"text-muted-foreground\" />\n        </div>\n\n        {account.otherAccounts.length > 0 && (\n          <div className=\"flex flex-col gap-1\">\n            <span className=\"text-xs text-muted-foreground\">Switch account</span>\n            <ul className=\"-mx-2 flex flex-col\">\n              {account.otherAccounts.map((other) => (\n                <li key={other.connector.uid}>\n                  <button\n                    type=\"button\"\n                    disabled={account.isSwitching}\n                    onClick={() => account.switchAccount(other.connector)}\n                    className=\"flex min-h-11 w-full items-center gap-2 rounded-lg px-2 text-left text-sm outline-none hover:bg-muted focus-visible:ring-3 focus-visible:ring-ring/50 disabled:opacity-50\"\n                  >\n                    <AddressAvatar address={other.address} size={24} />\n                    <span className=\"font-mono\">{truncateAddress(other.address)}</span>\n                    <span className=\"ml-auto truncate text-xs text-muted-foreground\">\n                      {other.connector.name}\n                    </span>\n                  </button>\n                </li>\n              ))}\n            </ul>\n          </div>\n        )}\n\n        {children}\n\n        <div className=\"flex items-center justify-between gap-2 border-t pt-3\">\n          {connector && (\n            <span className=\"text-xs text-muted-foreground\">\n              Connected with {connector.name}\n            </span>\n          )}\n          <Button\n            variant=\"ghost\"\n            size=\"sm\"\n            disabled={account.isDisconnecting}\n            onClick={() => {\n              account.disconnect();\n              setOpen(false);\n              onDisconnect?.();\n            }}\n          >\n            <LogOutIcon aria-hidden />\n            Disconnect\n          </Button>\n        </div>\n      </PopoverContent>\n    </Popover>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "docs": "Docs: https://0xui.io/components/account.md",
  "categories": [
    "wallet"
  ],
  "type": "registry:component"
}