Skip to content

Commit a174454

Browse files
authored
fix: useWaasFeeOptions (#308)
1 parent 9ff6e6b commit a174454

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

packages/react-connect/src/hooks/useWaasFeeOptions.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,37 @@ export type UseWaasFeeOptionsReturn = [
4444
rejectPendingFeeOption: (id: string) => void
4545
]
4646

47+
/**
48+
* Options for the useWaasFeeOptions hook
49+
*/
50+
export interface WaasFeeOptionsConfig {
51+
/** Whether to skip checking token balances (default: false) */
52+
skipFeeBalanceCheck?: boolean;
53+
}
54+
4755
/**
4856
* Hook for handling WaaS (Wallet as a Service) fee options for unsponsored transactions
4957
*
5058
* This hook provides functionality to:
5159
* - Get available fee options for a transaction in Native Token and ERC20's
52-
* - Check wallet balances for each fee option
60+
* - Provide user wallet balances for each fee option
5361
* - Confirm or reject fee selections
5462
*
55-
* @param chainId - The chain ID for which to get fee options
63+
* @param options - Configuration options for the hook
5664
* @returns {UseWaasFeeOptionsReturn} Array containing the confirmation state and control functions
5765
*
5866
* @example
5967
* ```tsx
60-
* const chainId = 137 // Polygon mainnet
68+
* // 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
6169
* const [
6270
* pendingFeeOptionConfirmation,
6371
* confirmPendingFeeOption,
6472
* rejectPendingFeeOption
65-
* ] = useWaasFeeOptions(chainId);
73+
* ] = useWaasFeeOptions();
74+
*
75+
* // Or skip balance checking if needed
76+
* // const [pendingFeeOptionConfirmation, confirmPendingFeeOption, rejectPendingFeeOption] =
77+
* // useWaasFeeOptions({ skipFeeBalanceCheck: true });
6678
*
6779
* const [selectedFeeOptionTokenName, setSelectedFeeOptionTokenName] = useState<string>();
6880
* const [feeOptionAlert, setFeeOptionAlert] = useState<AlertProps>();
@@ -76,9 +88,10 @@ export type UseWaasFeeOptionsReturn = [
7688
*
7789
* ```
7890
*/
79-
export function useWaasFeeOptions(skipFeeBalanceCheck = false): UseWaasFeeOptionsReturn {
91+
export function useWaasFeeOptions(options?: WaasFeeOptionsConfig): UseWaasFeeOptionsReturn {
92+
const { skipFeeBalanceCheck = false } = options || {}
8093
const connections = useConnections()
81-
const waasConnector: Connector | undefined = connections.find(c => c.connector.id.includes('waas'))?.connector
94+
const waasConnector: Connector | undefined = connections.find((c: any) => c.connector.id.includes('waas'))?.connector
8295
const [pendingFeeOptionConfirmation, setPendingFeeOptionConfirmation] = useState<WaasFeeOptionConfirmation | undefined>()
8396
const pendingConfirmationRef = useRef<
8497
Deferred<{ id: string; feeTokenAddress?: string | null; confirmed: boolean }> | undefined

0 commit comments

Comments
 (0)