import { GetTransactionReceiptResponse } from 'starknet'; /** Arguments for the `useTransactionReceipt` hook. */ export interface UseTransactionReceiptProps { /** The transaction hash. */ hash?: string; /** Refresh data at every block. */ watch?: boolean; /** * @optional * Callback function that will handle the transaction given the status "ACCEPTED_ON_L1". */ onAcceptedOnL1?: (transaction: GetTransactionReceiptResponse) => void; /** * @optional * Callback function that will handle the transaction given the status "ACCEPTED_ON_L2". */ onAcceptedOnL2?: (transaction: GetTransactionReceiptResponse) => void; /** * @optional * Callback function that will handle the transaction given the status "PENDING". */ onPending?: (transaction: GetTransactionReceiptResponse) => void; /** * @optional * Callback function that will handle the transaction given the status "REJECTED". */ onRejected?: (transaction: GetTransactionReceiptResponse) => void; /** * @optional * Callback function that will handle the transaction given the status "RECEIVED". */ onReceived?: (transaction: GetTransactionReceiptResponse) => void; /** * @optional * Callback function that will handle the transaction given the status "NOT_RECEIVED". */ onNotReceived?: (transaction: GetTransactionReceiptResponse) => void; } /** Value returned from `useTransactionReceipt`. */ export interface UseTransactionReceiptResult { /** The transaction receipt data. */ data?: GetTransactionReceiptResponse; /** True if fetching data. */ loading: boolean; /** Error while fetching the transaction receipt. */ error?: unknown; /** Manually trigger refresh of data. */ refresh: () => void; } /** * Hook to fetch a single transaction receipt. * * @remarks * * This hook keeps a cache of receipts by chain and transaction hash * so that you can use the hook freely in your application without worrying * about sending duplicate network requests. * * If you need to refresh the transaction receipt data, set `watch: true` in * the props. The hook will periodically refresh the transaction data in the * background. * * @example * This hook shows how to fetch a transaction receipt. * ```tsx * function Component() { * const { data, loading, error } = useTransactionReceipt({ hash: txHash }) * * if (loading) return Loading... * if (error) return Error: {JSON.stringify(error)} * return {data.status} * } * ``` * * @example * This example shows how to submit a transaction and load its status. * ```tsx * function Component() { * const { address } = useAccount() * const [hash, setHash] = useState(undefined) * * const { data, loading, error } = useTransactionReceipt({ hash, watch: true }) * * const { execute } = useStarknetExecute({ * calls: [{ * contractAddress: ethAddress, * entrypoint: 'transfer', * calldata: [address, 1, 0] * }] * }) * * const handleClick = () => { * execute().then(tx => setHash(tx.transaction_hash)) * } * * return ( *