UNPKG

@saberhq/sail

Version:

Account caching and batched loading for React-based Solana applications.

122 lines 4.05 kB
import type { Network, PendingTransaction, TransactionEnvelope } from "@saberhq/solana-contrib"; import type { ConfirmOptions, Finality } from "@solana/web3.js"; import type { OperationOptions } from "retry"; import type { UseAccounts } from ".."; import { SailError } from "../errors"; /** * Response when transactions are handled. */ export interface HandleTXResponse { success: boolean; pending: PendingTransaction | null; errors?: readonly SailError[]; } export interface HandleTXsResponse { success: boolean; pending: readonly PendingTransaction[]; errors?: readonly SailError[]; } export interface UseHandleTXsArgs extends Pick<UseAccounts, "refetchMany"> { /** * Delay for the writable accounts to be refetched into the cache after a transaction. */ txRefetchDelayMs?: number; /** * Called right before a {@link TransactionEnvelope} is sent. */ onBeforeTxSend?: (args: { /** * Unique identifier for the bundle of transactions. */ bundleID: string; /** * The {@link Network} this transaction is taking place on. */ network: Network; /** * The {@link TransactionEnvelope}s about to be sent. */ txs: readonly TransactionEnvelope[]; /** * Message identifying the transaction. */ message?: string; }) => void; /** * Called whenever a {@link TransactionEnvelope} is sent. */ onTxSend?: (args: { /** * Unique identifier for the bundle of transactions. */ bundleID: string; /** * The {@link Network} this transaction is taking place on. */ network: Network; /** * The {@link TransactionEnvelope}s that were sent. */ txs: readonly TransactionEnvelope[]; /** * Pending transactions. */ pending: readonly PendingTransaction[]; /** * Message identifying the transaction. */ message?: string; }) => void; /** * Called whenever an error occurs. */ onError: (err: SailError) => void; /** * If true, waits for a confirmation before proceeding to the next transaction. */ waitForConfirmation?: boolean; } export interface HandleTXOptions extends ConfirmOptions { /** * Options to pass in after a refetch has occured. */ refetchAfterTX?: OperationOptions & { /** * Commitment of the confirmed transaction to fetch. */ commitment?: Finality; /** * Delay for the writable accounts to be refetched into the cache after a transaction. */ refetchDelayMs?: number; /** * Whether or not to use websockets for awaiting confirmation. Defaults to `false`. */ useWebsocket?: boolean; }; /** * Whether or not to handle the TX envelope in debug mode. */ debugMode?: boolean; } /** * Function which signs and sends a {@link TransactionEnvelope}. */ export declare type HandleTX = (txEnv: TransactionEnvelope, msg?: string, options?: HandleTXOptions) => Promise<HandleTXResponse>; /** * Function which signs and sends a set of {@link TransactionEnvelope}. */ export declare type HandleTXs = (txEnv: readonly TransactionEnvelope[], msg?: string, options?: HandleTXOptions) => Promise<HandleTXsResponse>; export interface UseHandleTXs { /** * Signs and sends a transaction using the provider on the {@link TransactionEnvelope}. */ handleTX: HandleTX; /** * Signs and sends multiple transactions using the provider on the first {@link TransactionEnvelope}. * These transactions are only sent if all of them are signed. */ handleTXs: HandleTXs; } export declare const useHandleTXsInternal: ({ refetchMany, onBeforeTxSend, onTxSend, onError, txRefetchDelayMs, waitForConfirmation, }: UseHandleTXsArgs) => UseHandleTXs; //# sourceMappingURL=useHandleTXs.d.ts.map