{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "transaction-toast",
  "title": "Transaction Toast",
  "description": "useTransactionToast() returns toastTransaction(hash, options): one Sonner toast that goes from 'Transaction pending' to 'Transaction confirmed' or 'Transaction reverted' (or 'Couldn't track transaction'), with a View-on-explorer action and your description in every state. Waits with viem directly so reverted receipts are handled. Needs the shadcn Toaster mounted once.",
  "dependencies": [
    "wagmi",
    "viem",
    "sonner"
  ],
  "registryDependencies": [
    "sonner",
    "@0xui/0xui-utils"
  ],
  "files": [
    {
      "path": "registry/default/components/transaction-toast.tsx",
      "content": "// Docs: https://0xui.io/components/transaction-toast.md\nimport { useCallback, type ReactNode } from \"react\";\nimport { toast } from \"sonner\";\nimport type { Hash, TransactionReceipt } from \"viem\";\nimport { useConfig } from \"wagmi\";\nimport { getPublicClient } from \"wagmi/actions\";\nimport { getExplorerUrl } from \"@/lib/0xui-utils\";\n\nexport type TransactionToastOptions = {\n  /** Chain the transaction was sent on. Defaults to the current chain. */\n  chainId?: number;\n  /** What the transaction does, e.g. \"Swap 1 ETH for 3,150 USDC\". Shown in every state. */\n  description?: ReactNode;\n  /** Headings per state. */\n  titles?: { pending?: string; success?: string; reverted?: string; error?: string };\n  onConfirmed?: (receipt: TransactionReceipt) => void;\n};\n\n/**\n * Returns a function that follows a transaction in a toast: \"Transaction\n * pending\" until it is mined, then \"Transaction confirmed\" or \"Transaction\n * reverted\", each with an explorer link. Needs a Sonner `<Toaster />`\n * mounted once in your app.\n *\n *   const toastTransaction = useTransactionToast();\n *   <TransactionButton onSubmitted={(hash) => toastTransaction(hash)} … />\n */\nexport function useTransactionToast() {\n  const config = useConfig();\n\n  return useCallback(\n    (hash: Hash, options: TransactionToastOptions = {}) => {\n      const { chainId, description, titles = {}, onConfirmed } = options;\n      const client = getPublicClient(config, { chainId });\n      const url = getExplorerUrl(client?.chain, { tx: hash });\n      const action = url\n        ? {\n            label: \"View\",\n            onClick: () => window.open(url, \"_blank\", \"noopener,noreferrer\"),\n          }\n        : undefined;\n\n      const id = toast.loading(titles.pending ?? \"Transaction pending\", {\n        description,\n        action,\n        // Stay up until the transaction settles.\n        duration: Number.POSITIVE_INFINITY,\n      });\n\n      if (!client) {\n        toast.error(titles.error ?? \"Couldn't track transaction\", {\n          id,\n          description,\n          action,\n          duration: 8_000,\n        });\n        return id;\n      }\n\n      client\n        .waitForTransactionReceipt({ hash })\n        .then((receipt) => {\n          if (receipt.status === \"success\") {\n            toast.success(titles.success ?? \"Transaction confirmed\", {\n              id,\n              description,\n              action,\n              duration: 6_000,\n            });\n            onConfirmed?.(receipt);\n          } else {\n            toast.error(titles.reverted ?? \"Transaction reverted\", {\n              id,\n              description: \"Nothing changed except the gas fee.\",\n              action,\n              duration: 10_000,\n            });\n          }\n        })\n        .catch(() => {\n          toast.error(titles.error ?? \"Couldn't track transaction\", {\n            id,\n            description: \"Check the explorer for its current state.\",\n            action,\n            duration: 10_000,\n          });\n        });\n\n      return id;\n    },\n    [config]\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "docs": "Docs: https://0xui.io/components/transaction-toast.md",
  "categories": [
    "transactions"
  ],
  "type": "registry:component"
}