-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: metamask chain switch with missing net_version #3859
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
Conversation
🦋 Changeset detectedLatest commit: 2045037 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 ↗︎
|
config.emitter.once('change', ({ chainId: currentChainId }) => { | ||
if (currentChainId === chainId) resolve() | ||
}), | ||
), |
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.
I switched this to use the internal emitter rather than binding to the provider's emitter so that we can emit our own changed
event in the workaround case. This also matches the MetaMask connector:
wagmi/packages/connectors/src/metaMask.ts
Lines 180 to 184 in 72a25ee
new Promise<void>((resolve) => | |
config.emitter.once('change', ({ chainId: currentChainId }) => { | |
if (currentChainId === chainId) resolve() | |
}), | |
), |
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.
I believe that either approach can leave this listener open indefinitely if we never get a chain switch event. Should we time out after some time and remove the listener?
0cd6af9
to
230a2b4
Compare
230a2b4
to
d3e8866
Compare
…metamask-chain-switch-workaround
const currentChainId = await this.getChainId() | ||
if (currentChainId === chainId) | ||
config.emitter.emit('change', { chainId }) | ||
}), |
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.
If this doesn't have the target chain ID right away, we could wait and try again, maybe a couple times?
Description
This is a workaround for the issue described in MetaMask/metamask-extension#24247.
I've left a big inline comment explaining everything.