Skip to content

Commit

Permalink
fix: add retry/timeout strategy for injected connector initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Dec 7, 2023
1 parent e8ba4f5 commit e9080ff
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/core/src/connectors/injected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
UserRejectedRequestError,
getAddress,
numberToHex,
withRetry,
withTimeout,
} from 'viem'

import { ChainNotConfiguredError } from '../errors/config.js'
Expand Down Expand Up @@ -305,7 +307,13 @@ export function injected(parameters: InjectedParameters = {}) {
throw new ProviderNotFoundError()
}

const accounts = await this.getAccounts()
// We are applying a retry & timeout strategy here as some injected wallets (ie. MetaMask) fail to
// immediately resolve a JSON-RPC request on page load.
const accounts = await withRetry(() =>
withTimeout(() => this.getAccounts(), {
timeout: 100,
}),
)
return !!accounts.length
} catch {
return false
Expand Down

0 comments on commit e9080ff

Please sign in to comment.