{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "token-amount",
  "title": "Token Amount",
  "description": "Formats a bigint token amount with its decimals, e.g. '1,234.5678 USDC', without float precision loss. Rounds toward zero so balances never look larger than they are, shows '<0.0001' for dust, supports compact notation (1.2M) and an optional fiat value from a price prop. The exact amount shows on hover. Exports formatFiat.",
  "dependencies": [
    "viem"
  ],
  "registryDependencies": [
    "@0xui/morph-text",
    "@0xui/0xui-utils"
  ],
  "files": [
    {
      "path": "registry/default/components/token-amount.tsx",
      "content": "// Docs: https://0xui.io/components/token-amount.md\nimport { formatUnits } from \"viem\";\nimport {\n  formatTokenAmount,\n  type FormatTokenAmountOptions,\n} from \"@/lib/0xui-utils\";\nimport { MorphText } from \"@/components/morph-text\";\nimport { cn } from \"@/lib/utils\";\n\nexport type TokenAmountProps = FormatTokenAmountOptions & {\n  /** Raw amount in the token's smallest unit. */\n  value: bigint;\n  /** Token decimals, e.g. 18 for ETH, 6 for USDC. */\n  decimals: number;\n  /** Shown after the amount. */\n  symbol?: string;\n  /** Price of one token in `currency`. When set, a fiat value is shown below. */\n  price?: number;\n  /** ISO 4217 currency for the fiat value. */\n  currency?: string;\n  /** Morph the amount and fiat value when they change. Leave off in long lists. */\n  animate?: boolean;\n  className?: string;\n};\n\n/** Fiat value of a token amount, formatted as currency. */\nexport function formatFiat(\n  value: bigint,\n  decimals: number,\n  price: number,\n  { currency = \"USD\", locale }: { currency?: string; locale?: string } = {}\n) {\n  const amount = Number(formatUnits(value, decimals)) * price;\n  return new Intl.NumberFormat(locale, { style: \"currency\", currency }).format(\n    amount\n  );\n}\n\n/**\n * Formatted token amount, e.g. `1,234.5678 USDC`. Never loses precision to\n * floats and never rounds up. The exact amount is available on hover.\n */\nexport function TokenAmount({\n  value,\n  decimals,\n  symbol,\n  price,\n  currency,\n  maxDecimals,\n  compact,\n  locale,\n  animate = false,\n  className,\n}: TokenAmountProps) {\n  const formatted = formatTokenAmount(value, decimals, {\n    maxDecimals,\n    compact,\n    locale,\n  });\n  const exact = `${formatUnits(value, decimals)}${symbol ? ` ${symbol}` : \"\"}`;\n  const fiat =\n    price === undefined ? undefined : formatFiat(value, decimals, price, { currency, locale });\n\n  return (\n    <span\n      data-slot=\"token-amount\"\n      className={cn(\"inline-flex flex-col\", className)}\n    >\n      <span title={exact} className=\"tabular-nums\">\n        {animate ? <MorphText>{formatted}</MorphText> : formatted}\n        {symbol && <span className=\"ml-1 text-muted-foreground\">{symbol}</span>}\n      </span>\n      {fiat !== undefined && (\n        <span className=\"text-sm text-muted-foreground tabular-nums\">\n          {animate ? <MorphText>{fiat}</MorphText> : fiat}\n        </span>\n      )}\n    </span>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "docs": "Docs: https://0xui.io/components/token-amount.md",
  "categories": [
    "tokens"
  ],
  "type": "registry:component"
}