Problem
switchChain can hang indefinitely on mobile wallets over WalletConnect when:
- The wallet app is backgrounded
- The user ignores the chain switch prompt
- The request is dropped mid-flight
The promise never rejects, leaving users stuck with no error feedback.
In production, we work around this with Promise.race() + manual 30-second timeouts, but this forces every consumer to re-implement the same fragile workaround.
Proposed Solution
Add an optional timeout parameter (milliseconds) to switchChain. If the request doesn't resolve within that window, the promise rejects with a clear SwitchChainTimeoutError.
const { switchChainAsync } = useSwitchChain();
try {
await switchChainAsync({
chainId: 137,
timeout: 30_000 // 30 second timeout
});
} catch (error) {
if (error.name === 'SwitchChainTimeoutError') {
// Handle timeout — wallet backgrounded or request dropped
}
}
Implementation Notes
Following waitForTransactionReceipt precedent:
- Optional per-call parameter in
SwitchChainParameters
setTimeout() + Promise.race() for timeout implementation
- New
SwitchChainTimeoutError extending BaseError
- No default timeout (let consumers decide)
Use Case
DeFi apps need reliable chain switching before transaction submission. A timeout parameter eliminates the need for workarounds and gives developers control over their UX when wallets become unresponsive.
Problem
switchChaincan hang indefinitely on mobile wallets over WalletConnect when:The promise never rejects, leaving users stuck with no error feedback.
In production, we work around this with
Promise.race()+ manual 30-second timeouts, but this forces every consumer to re-implement the same fragile workaround.Proposed Solution
Add an optional
timeoutparameter (milliseconds) toswitchChain. If the request doesn't resolve within that window, the promise rejects with a clearSwitchChainTimeoutError.Implementation Notes
Following
waitForTransactionReceiptprecedent:SwitchChainParameterssetTimeout()+Promise.race()for timeout implementationSwitchChainTimeoutErrorextendingBaseErrorUse Case
DeFi apps need reliable chain switching before transaction submission. A timeout parameter eliminates the need for workarounds and gives developers control over their UX when wallets become unresponsive.