Skip to content

Commit

Permalink
fix: metaMask switchChain
Browse files Browse the repository at this point in the history
  • Loading branch information
xianchenxc committed Aug 25, 2024
1 parent 34df0c8 commit ceadbbe
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/connectors/src/metaMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,17 @@ export function metaMask(parameters: MetaMaskParameters = {}) {
rpcUrls,
} satisfies AddEthereumChainParameter

await provider.request({
method: 'wallet_addEthereumChain',
params: [addEthereumChain],
})

await Promise.all([
provider.request({
method: 'wallet_addEthereumChain',
params: [addEthereumChain],
}),
new Promise<void>((resolve) =>
config.emitter.once('change', ({ chainId: currentChainId }) => {
if (currentChainId === chainId) resolve()
}),
),
])
const currentChainId = await this.getChainId()
if (currentChainId !== chainId)
throw new UserRejectedRequestError(
Expand Down

0 comments on commit ceadbbe

Please sign in to comment.