-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the switchChain error encountered when using the "metaMask" connector #4227
Conversation
🦋 Changeset detectedLatest commit: 8a0e3b1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
packages/connectors/src/metaMask.ts
Outdated
provider.request({ | ||
method: 'wallet_addEthereumChain', | ||
params: [addEthereumChain], | ||
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also have the additional then
block to fire the change event if its needed?
wagmi/packages/connectors/src/metaMask.ts
Lines 230 to 239 in ceadbbe
// During `'wallet_switchEthereumChain'`, MetaMask makes a `'net_version'` RPC call to the target chain. | |
// If this request fails, MetaMask does not emit the `'chainChanged'` event, but will still switch the chain. | |
// To counter this behavior, we request and emit the current chain ID to confirm the chain switch either via | |
// this callback or an externally emitted `'chainChanged'` event. | |
// https://github.com/MetaMask/metamask-extension/issues/24247 | |
.then(async () => { | |
const currentChainId = await this.getChainId() | |
if (currentChainId === chainId) | |
config.emitter.emit('change', { chainId }) | |
}), |
026feab
to
9b7cc38
Compare
Calling |
fix #4223