"use client";
import { CustomThemeProvider } from "../../../core/design-system/CustomThemeProvider.js";
import {
type TransactionButtonProps,
useTransactionButtonMutation,
} from "../../../core/hooks/transaction/transaction-button-utils.js";
import { useActiveAccount } from "../../../core/hooks/wallets/useActiveAccount.js";
import { useSendTransaction } from "../../hooks/transaction/useSendTransaction.js";
import { Button } from "../components/buttons.js";
import { Spinner } from "../components/Spinner.js";
/**
* TransactionButton component is used to render a button that triggers a transaction.
* It shows a "Switch Network" button if the connected wallet is on a different chain than the transaction.
* @param props - The props for this component.
* Refer to [TransactionButtonProps](https://portal.thirdweb.com/references/typescript/v5/TransactionButtonProps) for details.
* @example
*
* ### Basic usage
* ```tsx
* {}}
* onTransactionConfirmed={handleSuccess}
* onError={handleError}
* >
* Confirm Transaction
*
* ```
*
* ### Customize the styling by passing the `unstyled` prop and your inline styles and/or classes:
* ```tsx
* {}}
* unstyled
* className="bg-white text-black rounded-md p-4 flex items-center justify-center"
* >
* Confirm Transaction
*
* ```
*
* ### Handle errors
* ```tsx
* ...}
* onError={(err) => {
* alert(err.message);
* // Add your own logic here
* }}
* >
* Confirm Transaction
*
* ```
*
* ### Alert when a transaction is sent
* ```tsx
* ...}
* onTransactionSent={(tx) => {
* alert("transaction sent!");
* // Add your own logic here. For example, a toast
* }}
* >
* Confirm Transaction
*
* ```
*
* ### Alert when a transaction is completed
* ```tsx
* ...}
* onTransactionConfirmed={(tx) => {
* alert("transaction sent!");
* console.log(tx);
* // Add your own logic here. For example, a toast
* }}
* >
* Confirm Transaction
*
* ```
*
* ### The onClick prop, if provided, will be called before the transaction is sent.
* ```tsx
* alert("Transaction is about to be sent")}
* transaction={...}
* >
* ...
*
* ```
*
* ### Attach custom Pay metadata
* ```tsx
*
* ...
*
* ```
*
* ### Gasless usage with [thirdweb Engine](https://portal.thirdweb.com/engine)
* ```tsx
*
* ...
*
* ```
*
* ### Gasless usage with OpenZeppelin
* ```tsx
*
* ...
*
* ```
* @component
* @transaction
*/
export function TransactionButton(props: TransactionButtonProps) {
const {
children,
// biome-ignore lint/correctness/noUnusedVariables: TODO
transaction,
// biome-ignore lint/correctness/noUnusedVariables: TODO
onTransactionSent,
// biome-ignore lint/correctness/noUnusedVariables: TODO
onTransactionConfirmed,
// biome-ignore lint/correctness/noUnusedVariables: TODO
onError,
// biome-ignore lint/correctness/noUnusedVariables: TODO
onClick,
gasless,
payModal,
disabled,
unstyled,
...buttonProps
} = props;
const account = useActiveAccount();
const sendTransaction = useSendTransaction({ gasless, payModal });
const { mutate: handleClick, isPending } = useTransactionButtonMutation(
props,
sendTransaction.mutateAsync,
);
return (
);
}