{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "gas-price",
  "title": "Gas Price",
  "description": "Current gas price in gwei with three significant digits (useGasPrice, refreshed on an interval). Optional low/medium/high tone from per-chain gwei thresholds, exposed as data-tone. Skeleton (skullet) while loading and an error state. Exports useGasPriceInfo, formatGasPrice and gasTone.",
  "dependencies": [
    "wagmi",
    "viem",
    "lucide-react",
    "skullet"
  ],
  "registryDependencies": [
    "@0xui/morph-text"
  ],
  "files": [
    {
      "path": "registry/default/components/gas-price.tsx",
      "content": "// Docs: https://0xui.io/components/gas-price.md\nimport { FuelIcon } from \"lucide-react\";\nimport type { ComponentType } from \"react\";\nimport { SkeletonBox } from \"skullet/react\";\nimport { formatGwei } from \"viem\";\nimport { useGasPrice } from \"wagmi\";\nimport { MorphText } from \"@/components/morph-text\";\nimport { cn } from \"@/lib/utils\";\n\nexport type GasTone = \"low\" | \"medium\" | \"high\";\n\n/** SkeletonBox is a block by default. This one sits in a line of text. */\nconst inlineBox = { display: \"inline-block\", verticalAlign: \"middle\" } as const;\n\nexport type GasPriceProps = {\n  /** Chain to read. Defaults to the current chain. */\n  chainId?: number;\n  /** How often to refresh, in ms. Pass false to fetch once. */\n  refreshInterval?: number | false;\n  /**\n   * Gwei cut-offs for coloring the price. Below `low` is low, above `high` is\n   * high. Gas varies a lot between chains, so there is no default. Without\n   * thresholds the price is shown without a tone.\n   */\n  thresholds?: { low: number; high: number };\n  /** Custom icon. Pass false to hide. */\n  icon?: ComponentType<{ className?: string }> | false;\n  locale?: string;\n  className?: string;\n};\n\n/** Format gwei with 3 significant digits, so 0.0123 and 42.1 both read well. */\nexport function formatGasPrice(wei: bigint, locale?: string) {\n  const gwei = Number(formatGwei(wei));\n  return new Intl.NumberFormat(locale, {\n    maximumSignificantDigits: 3,\n  }).format(gwei);\n}\n\nexport function gasTone(\n  wei: bigint,\n  thresholds: { low: number; high: number }\n): GasTone {\n  const gwei = Number(formatGwei(wei));\n  if (gwei < thresholds.low) return \"low\";\n  if (gwei > thresholds.high) return \"high\";\n  return \"medium\";\n}\n\n/** Current gas price, refreshed on an interval. */\nexport function useGasPriceInfo({\n  chainId,\n  refreshInterval = 12_000,\n  thresholds,\n}: Pick<GasPriceProps, \"chainId\" | \"refreshInterval\" | \"thresholds\"> = {}) {\n  const { data, isError, isPending } = useGasPrice({\n    chainId,\n    query: { refetchInterval: refreshInterval },\n  });\n  return {\n    gasPrice: data,\n    tone: data !== undefined && thresholds ? gasTone(data, thresholds) : undefined,\n    isError,\n    isPending,\n  };\n}\n\nconst toneClass: Record<GasTone, string> = {\n  low: \"text-emerald-600 dark:text-emerald-400\",\n  medium: \"text-amber-600 dark:text-amber-400\",\n  high: \"text-destructive\",\n};\n\n/** Current gas price in gwei, optionally colored low/medium/high. */\nexport function GasPrice({\n  chainId,\n  refreshInterval,\n  thresholds,\n  icon,\n  locale,\n  className,\n}: GasPriceProps) {\n  const { gasPrice, tone, isError } = useGasPriceInfo({\n    chainId,\n    refreshInterval,\n    thresholds,\n  });\n  const Icon = icon === false ? null : (icon ?? FuelIcon);\n\n  return (\n    <span\n      data-slot=\"gas-price\"\n      data-tone={tone}\n      className={cn(\n        \"inline-flex items-center gap-1.5 text-sm tabular-nums text-muted-foreground\",\n        tone && toneClass[tone],\n        className\n      )}\n    >\n      {Icon && <Icon aria-hidden className=\"size-3.5 shrink-0\" />}\n      {isError ? (\n        <span>Gas unavailable</span>\n      ) : gasPrice === undefined ? (\n        <span>\n          {/* About the width of \"12.3 gwei\". */}\n          <SkeletonBox width=\"9ch\" height=\"1em\" style={inlineBox} />\n          <span className=\"sr-only\">Loading gas price</span>\n        </span>\n      ) : (\n        <span>\n          <span className=\"sr-only\">Gas price </span>\n          <MorphText>{`${formatGasPrice(gasPrice, locale)} gwei`}</MorphText>\n          {tone && <span className=\"sr-only\">, {tone}</span>}\n        </span>\n      )}\n    </span>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "docs": "Docs: https://0xui.io/components/gas-price.md",
  "categories": [
    "network"
  ],
  "type": "registry:component"
}