{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "transaction-status",
  "title": "Transaction Status",
  "description": "Inline card for one transaction hash: what it does (children), steps from submitted to included in block N to N of M confirmations, the hash with copy, and an explorer link. Reverted transactions are shown with their receipt instead of throwing like wagmi's useWaitForTransactionReceipt. Exports useTransactionStatus, useMinedReceipt and StepIcon. data-phase: pending | confirming | confirmed | reverted | error.",
  "dependencies": [
    "wagmi",
    "viem",
    "@tanstack/react-query",
    "lucide-react"
  ],
  "registryDependencies": [
    "@0xui/copy-button",
    "@0xui/explorer-link",
    "@0xui/0xui-utils"
  ],
  "files": [
    {
      "path": "registry/default/components/transaction-status.tsx",
      "content": "// Docs: https://0xui.io/components/transaction-status.md\nimport { useQuery } from \"@tanstack/react-query\";\nimport { CheckIcon, CircleIcon, Loader2Icon, XIcon } from \"lucide-react\";\nimport { useEffect, useRef, type ReactNode } from \"react\";\nimport type { Hash, TransactionReceipt } from \"viem\";\nimport { useChainId, usePublicClient, useTransactionConfirmations } from \"wagmi\";\nimport { CopyButton } from \"@/components/copy-button\";\nimport { ExplorerLink } from \"@/components/explorer-link\";\nimport { errorCode, truncateAddress } from \"@/lib/0xui-utils\";\nimport { cn } from \"@/lib/utils\";\n\nexport type TxStatusPhase = \"pending\" | \"confirming\" | \"confirmed\" | \"reverted\" | \"error\";\n\n/**\n * Wait for a transaction to be mined. Unlike wagmi's\n * useWaitForTransactionReceipt, a reverted transaction resolves with its\n * receipt (`status: \"reverted\"`) instead of throwing, so the UI can show it.\n */\nexport function useMinedReceipt({\n  hash,\n  chainId,\n}: {\n  hash: Hash | undefined;\n  chainId: number | undefined;\n}) {\n  const client = usePublicClient({ chainId });\n  return useQuery({\n    queryKey: [\"0xui\", \"mined-receipt\", chainId, hash],\n    queryFn: () => client!.waitForTransactionReceipt({ hash: hash! }),\n    enabled: Boolean(hash && client),\n    staleTime: Infinity,\n    retry: false,\n  });\n}\n\nexport type UseTransactionStatusParameters = {\n  hash: Hash;\n  /** Chain the transaction was sent on. Defaults to the current chain. */\n  chainId?: number;\n  /** Confirmations required before the transaction counts as confirmed. */\n  confirmations?: number;\n};\n\n/** Track a transaction from submitted to confirmed, with a live confirmation count. */\nexport function useTransactionStatus({\n  hash,\n  chainId: chainIdProp,\n  confirmations = 1,\n}: UseTransactionStatusParameters) {\n  const currentChainId = useChainId();\n  const chainId = chainIdProp ?? currentChainId;\n\n  const receipt = useMinedReceipt({ hash, chainId });\n  const mined = receipt.data;\n  const count = useTransactionConfirmations({\n    hash,\n    chainId,\n    query: {\n      enabled: Boolean(mined) && mined?.status === \"success\" && confirmations > 1,\n      refetchInterval: 4_000,\n    },\n  });\n\n  const confirmationCount = mined ? (confirmations > 1 ? Number(count.data ?? 1n) : 1) : 0;\n\n  const phase: TxStatusPhase = receipt.isError\n    ? \"error\"\n    : !mined\n      ? \"pending\"\n      : mined.status === \"reverted\"\n        ? \"reverted\"\n        : confirmationCount >= confirmations\n          ? \"confirmed\"\n          : \"confirming\";\n\n  return {\n    phase,\n    chainId,\n    receipt: mined,\n    confirmations: Math.min(confirmationCount, confirmations),\n    required: confirmations,\n    error: receipt.error,\n  };\n}\n\nexport type TransactionStatusProps = UseTransactionStatusParameters & {\n  /** Heading. Defaults to a phase description such as \"Transaction pending\". */\n  title?: ReactNode;\n  /** What the transaction does, e.g. \"Send 0.5 ETH to vitalik.eth\". */\n  children?: ReactNode;\n  /** Called once when the transaction reaches the required confirmations. */\n  onConfirmed?: (receipt: TransactionReceipt) => void;\n  className?: string;\n};\n\nconst headings: Record<TxStatusPhase, string> = {\n  pending: \"Transaction pending\",\n  confirming: \"Confirming\",\n  confirmed: \"Transaction confirmed\",\n  reverted: \"Transaction reverted\",\n  error: \"Couldn't track transaction\",\n};\n\n/**\n * Inline card for one transaction: what it does, a step list from submitted\n * to confirmed, the hash, and an explorer link. Never a bare spinner.\n */\nexport function TransactionStatus({\n  hash,\n  chainId,\n  confirmations,\n  title,\n  children,\n  onConfirmed,\n  className,\n}: TransactionStatusProps) {\n  const status = useTransactionStatus({ hash, chainId, confirmations });\n  const { phase, receipt } = status;\n\n  const reported = useRef(false);\n  useEffect(() => {\n    if (phase === \"confirmed\" && receipt && !reported.current) {\n      reported.current = true;\n      onConfirmed?.(receipt);\n    }\n    // Only a phase change should fire the callback.\n  }, [phase, receipt]);\n\n  const steps: { label: ReactNode; state: StepState }[] = [\n    { label: \"Submitted\", state: \"done\" },\n    {\n      label: receipt\n        ? `Included in block ${receipt.blockNumber.toLocaleString()}`\n        : \"Waiting to be included in a block\",\n      state: receipt\n        ? receipt.status === \"reverted\"\n          ? \"failed\"\n          : \"done\"\n        : phase === \"error\"\n          ? \"failed\"\n          : \"active\",\n    },\n  ];\n  if (status.required > 1 && phase !== \"reverted\") {\n    steps.push({\n      label: `${status.confirmations} of ${status.required} confirmations`,\n      state: phase === \"confirmed\" ? \"done\" : phase === \"confirming\" ? \"active\" : \"todo\",\n    });\n  }\n\n  return (\n    <div\n      data-slot=\"transaction-status\"\n      data-phase={phase}\n      data-error={errorCode(phase, status.error)}\n      className={cn(\"flex flex-col gap-3 rounded-xl border p-4 text-sm\", className)}\n    >\n      <div className=\"flex flex-col gap-1\">\n        <p\n          role=\"status\"\n          className={cn(\n            \"font-medium\",\n            phase === \"confirmed\" && \"text-emerald-600 dark:text-emerald-400\",\n            (phase === \"reverted\" || phase === \"error\") && \"text-destructive\",\n          )}\n        >\n          {title ?? headings[phase]}\n        </p>\n        {children && <div className=\"text-muted-foreground\">{children}</div>}\n      </div>\n\n      <ol className=\"flex flex-col gap-2\">\n        {steps.map((step, i) => (\n          <li key={i} className=\"flex items-center gap-2\">\n            <StepIcon state={step.state} />\n            <span className={cn(step.state === \"todo\" && \"text-muted-foreground\")}>\n              {step.label}\n            </span>\n          </li>\n        ))}\n      </ol>\n\n      {phase === \"error\" && (\n        <p role=\"alert\" className=\"text-destructive\">\n          The transaction wasn't found or the RPC stopped responding. Check the explorer for its\n          current state.\n        </p>\n      )}\n\n      <div className=\"flex items-center justify-between gap-2 border-t pt-3\">\n        <span className=\"flex items-center gap-1 font-mono text-xs text-muted-foreground\">\n          {truncateAddress(hash, { start: 10, end: 8 })}\n          <CopyButton value={hash} label=\"Copy transaction hash\" />\n        </span>\n        <ExplorerLink tx={hash} chainId={status.chainId} className=\"text-xs\" />\n      </div>\n    </div>\n  );\n}\n\nexport type StepState = \"done\" | \"active\" | \"failed\" | \"todo\";\n\n/** Icon for one step of a status list: a check, a spinner, a cross or an empty circle. */\nexport function StepIcon({ state }: { state: StepState }) {\n  const className = \"size-4 shrink-0\";\n  if (state === \"done\")\n    return <CheckIcon aria-label=\"Done\" className={cn(className, \"text-emerald-500\")} />;\n  if (state === \"failed\")\n    return <XIcon aria-label=\"Failed\" className={cn(className, \"text-destructive\")} />;\n  if (state === \"active\")\n    return (\n      <Loader2Icon\n        aria-label=\"In progress\"\n        className={cn(className, \"animate-spin text-muted-foreground\")}\n      />\n    );\n  return <CircleIcon aria-label=\"Not started\" className={cn(className, \"text-muted-foreground\")} />;\n}\n",
      "type": "registry:component"
    }
  ],
  "docs": "Docs: https://0xui.io/components/transaction-status.md",
  "categories": [
    "transactions"
  ],
  "type": "registry:component"
}