{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "add-token",
  "title": "Add Token",
  "description": "'Add USDC to wallet' button (EIP-747 wallet_watchAsset via useWatchAsset) with adding, added, cancelled and error states. Renders nothing when no wallet is connected.",
  "dependencies": [
    "wagmi",
    "viem",
    "lucide-react"
  ],
  "registryDependencies": [
    "button",
    "@0xui/morph-text",
    "@0xui/0xui-utils"
  ],
  "files": [
    {
      "path": "registry/default/components/add-token.tsx",
      "content": "// Docs: https://0xui.io/components/add-token.md\nimport { CheckIcon, Loader2Icon, WalletIcon } from \"lucide-react\";\nimport type { ComponentProps, ReactNode } from \"react\";\nimport type { Address } from \"viem\";\nimport { useConnection, useWatchAsset } from \"wagmi\";\nimport { MorphText } from \"@/components/morph-text\";\nimport { Button } from \"@/components/ui/button\";\nimport { errorCode, isUserRejection } from \"@/lib/0xui-utils\";\nimport { cn } from \"@/lib/utils\";\n\nexport type AddTokenPhase = \"idle\" | \"adding\" | \"added\" | \"cancelled\" | \"error\";\n\nexport type AddTokenProps = Omit<ComponentProps<typeof Button>, \"onClick\" | \"children\"> & {\n  /** ERC-20 to add. Wallets show `logoURI` as the token icon. */\n  token: { address: Address; symbol: string; decimals: number; logoURI?: string };\n  children?: ReactNode;\n};\n\n/**\n * \"Add USDC to wallet\" button (EIP-747). Renders nothing when no wallet is\n * connected. A declined prompt shows as cancelled.\n */\nexport function AddToken({\n  token,\n  children,\n  variant = \"outline\",\n  size = \"sm\",\n  className,\n  disabled,\n  ...buttonProps\n}: AddTokenProps) {\n  const { status } = useConnection();\n  const watch = useWatchAsset();\n\n  if (status !== \"connected\") return null;\n\n  const phase: AddTokenPhase = watch.isPending\n    ? \"adding\"\n    : watch.data === true\n      ? \"added\"\n      : watch.data === false || isUserRejection(watch.error)\n        ? \"cancelled\"\n        : watch.error\n          ? \"error\"\n          : \"idle\";\n\n  return (\n    <span\n      data-slot=\"add-token\"\n      data-phase={phase}\n      data-error={errorCode(phase, watch.error)}\n      className={cn(\"inline-flex flex-col gap-1\", className)}\n    >\n      <Button\n        variant={variant}\n        size={size}\n        disabled={disabled || phase === \"adding\" || phase === \"added\"}\n        aria-busy={phase === \"adding\" || undefined}\n        onClick={() =>\n          watch.mutate({\n            type: \"ERC20\",\n            options: {\n              address: token.address,\n              symbol: token.symbol,\n              decimals: token.decimals,\n              image: token.logoURI,\n            },\n          })\n        }\n        {...buttonProps}\n      >\n        {phase === \"adding\" ? (\n          <Loader2Icon aria-hidden className=\"animate-spin\" />\n        ) : phase === \"added\" ? (\n          <CheckIcon aria-hidden />\n        ) : (\n          <WalletIcon aria-hidden />\n        )}\n        <MorphText>\n          {phase === \"added\"\n            ? `${token.symbol} added`\n            : (children ?? `Add ${token.symbol} to wallet`)}\n        </MorphText>\n      </Button>\n      <span role=\"status\" className=\"text-xs text-muted-foreground empty:hidden\">\n        {phase === \"adding\"\n          ? \"Confirm in your wallet.\"\n          : phase === \"cancelled\"\n            ? \"Cancelled in wallet.\"\n            : \"\"}\n      </span>\n      {phase === \"error\" && (\n        <span role=\"alert\" className=\"text-xs text-destructive\">\n          Your wallet couldn't add this token.\n        </span>\n      )}\n    </span>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "docs": "Docs: https://0xui.io/components/add-token.md",
  "categories": [
    "tokens"
  ],
  "type": "registry:component"
}