@0xsequence/connect
Version:
Connect package for Sequence Web SDK
79 lines • 3.04 kB
TypeScript
import type { FeeOption } from '@0xsequence/waas';
/**
* Extended FeeOption type that includes balance information
*/
export type FeeOptionExtended = FeeOption & {
/** Raw balance string */
balance: string;
/** Formatted balance with proper decimals */
balanceFormatted: string;
/** Indicates if the wallet has enough balance to pay the fee */
hasEnoughBalanceForFee: boolean;
};
/**
* Fee option confirmation data structure
*/
export type WaasFeeOptionConfirmation = {
/** Unique identifier for the fee confirmation */
id: string;
/** Available fee options with balance information */
options: FeeOptionExtended[] | FeeOption[];
/** Chain ID where the transaction will be executed */
chainId: number;
};
/**
* Return type for the useWaasFeeOptions hook
*/
export type UseWaasFeeOptionsReturnType = [
pendingFeeOptionConfirmation: WaasFeeOptionConfirmation | undefined,
confirmPendingFeeOption: (id: string, feeTokenAddress: string | null) => void,
rejectPendingFeeOption: (id: string) => void
];
/**
* Options for the useWaasFeeOptions hook
*
* @property {boolean} skipFeeBalanceCheck - Whether to skip checking token balances (default: false)
*/
export interface WaasFeeOptionsConfig {
/** Whether to skip checking token balances (default: false) */
skipFeeBalanceCheck?: boolean;
chainIdOverride?: number;
}
/**
* Hook for handling WaaS (Wallet as a Service) fee options for unsponsored transactions
*
* This hook provides functionality to:
* - Get available fee options for a transaction in Native Token and ERC20's
* - Provide user wallet balances for each fee option
* - Confirm or reject fee selections
*
* @param options - Configuration options for the hook {@link WaasFeeOptionsConfig}
* @returns Array containing the confirmation state and control functions {@link UseWaasFeeOptionsReturnType}
*
* @example
* ```tsx
* // Use the hook with default balance checking, this will fetch the user's wallet balances for each fee option and provide them in the UseWaasFeeOptionsReturn
* const [
* pendingFeeOptionConfirmation,
* confirmPendingFeeOption,
* rejectPendingFeeOption
* ] = useWaasFeeOptions();
*
* // Or skip balance checking if needed
* // const [pendingFeeOptionConfirmation, confirmPendingFeeOption, rejectPendingFeeOption] =
* // useWaasFeeOptions({ skipFeeBalanceCheck: true });
*
* const [selectedFeeOptionTokenName, setSelectedFeeOptionTokenName] = useState<string>();
* const [feeOptionAlert, setFeeOptionAlert] = useState<AlertProps>();
*
* // Initialize with first option when fee options become available
* useEffect(() => {
* if (pendingFeeOptionConfirmation) {
* console.log('Pending fee options: ', pendingFeeOptionConfirmation.options)
* }
* }, [pendingFeeOptionConfirmation]);
*
* ```
*/
export declare function useWaasFeeOptions(options?: WaasFeeOptionsConfig): UseWaasFeeOptionsReturnType;
//# sourceMappingURL=useWaasFeeOptions.d.ts.map