@@ -9,20 +9,24 @@ export const useConfigurableAccount = () => {
99 const webauthnValidatorAddress = contractsByChain [ defaultChain . id ] . webauthnValidator ;
1010
1111 // Get current block to calculate safe fromBlock (avoid RPC block range limits)
12- // Add timeout to prevent hanging RPC calls in CI (4s to leave room for event queries )
12+ // Add timeout to prevent hanging RPC calls (5s should be sufficient )
1313 const currentBlockPromise = publicClient . getBlockNumber ( ) ;
14- const timeoutPromise = new Promise < never > ( ( _ , reject ) =>
15- setTimeout ( ( ) => reject ( new Error ( "Timeout getting block number after 4 seconds" ) ) , 4000 ) ,
14+ const blockTimeoutPromise = new Promise < never > ( ( _ , reject ) =>
15+ setTimeout ( ( ) => reject ( new Error ( "Timeout getting block number after 5 seconds" ) ) , 5000 ) ,
1616 ) ;
17- const currentBlock = await Promise . race ( [ currentBlockPromise , timeoutPromise ] ) ;
17+ const currentBlock = await Promise . race ( [ currentBlockPromise , blockTimeoutPromise ] ) ;
1818
19- // Query last 100k blocks or from genesis, whichever is more recent
20- const fromBlock = currentBlock > 100000n ? currentBlock - 100000n : 0n ;
19+ // Use smaller block range for faster queries (10k blocks should cover recent activity)
20+ // This significantly improves performance - 100k blocks was causing 10s+ query times
21+ const blockRange = 10000n ;
22+ const fromBlock = currentBlock > blockRange ? currentBlock - blockRange : 0n ;
2123
2224 // FIXME: events should be scoped to the origin domain
2325 // As well, this doesn't seem to be a reliable way of retrieving a `credentialId`
2426 // but works for now.
25- const [ events , removedEvents ] = await Promise . all ( [
27+
28+ // Add timeout to event queries to prevent hanging (10s to handle multiple accounts in test environments)
29+ const eventsPromise = Promise . all ( [
2630 publicClient . getContractEvents ( {
2731 address : webauthnValidatorAddress ,
2832 abi : WebAuthnValidatorAbi ,
@@ -45,6 +49,12 @@ export const useConfigurableAccount = () => {
4549 } ) ,
4650 ] ) ;
4751
52+ const eventsTimeoutPromise = new Promise < never > ( ( _ , reject ) =>
53+ setTimeout ( ( ) => reject ( new Error ( "Timeout querying PasskeyCreated/PasskeyRemoved events after 10 seconds" ) ) , 10000 ) ,
54+ ) ;
55+
56+ const [ events , removedEvents ] = await Promise . race ( [ eventsPromise , eventsTimeoutPromise ] ) ;
57+
4858 if ( ! events || events . length === 0 ) {
4959 throw new Error ( "Account not found" ) ;
5060 }
0 commit comments