Skip to content
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

After reload page, the chainId is different from the one in the Metamask. #4386

Closed
1 task done
AliceW-03 opened this issue Nov 7, 2024 · 7 comments
Closed
1 task done

Comments

@AliceW-03
Copy link

AliceW-03 commented Nov 7, 2024

Check existing issues

Describe the bug

When I connect metamask in my telegram webapp, switch chains, and then reload the page, the chainId is different from the one in the wallet.

I noticed that metamask store a .MMSDK_cached_chainId in the localStorage to persist the chain info. After switching chains, this field retains the old chainId. When the page is reloaded, the retrieved chainId becomes the old value, even though the wallet has already switched to the new chain.

I have raised an issue on the metamask-sdk, but after testing the metamask-sdk demo provided, I found that directly using metamask-sdk, rather than connecting through wagmi, did not have this issue. It seems that after switching chains, the original callback for updating the cache either didn’t execute or was overridden by your code.

Link to Minimal Reproducible Example

https://metamask-cache-chain-id.vercel.app/
https://github.com/AliceW-03/metamask-cacheChainId.git

Steps To Reproduce

Please read my description carefully first.

I deployed a reproduction in my test bot. You can enter the bot and type /metamask.

  1. connect wallet
  2. switch chain
  3. reload in the top right corner.
  4. check localStorage

What Wagmi package(s) are you using?

wagmi, @wagmi/connectors

Wagmi Package(s) Version(s)

2.12.25

Viem Version

2.21.37

TypeScript Version

5.5.3

Anything else?

No response

@AliceW-03
Copy link
Author

@AliceW-03
Copy link
Author

@imaksp
Copy link

imaksp commented Nov 9, 2024

is this specific to injected connector ? have you tried using wagmi's metaMask connector (which uses metamask's sdk)?

@AliceW-03
Copy link
Author

@imaksp I'm using wagmi's metaMask connector of course🙂

@roshan-synquote
Copy link

Any updates here?

@tmm
Copy link
Member

tmm commented Nov 27, 2024

#4422 should take care of that

@tmm tmm closed this as completed Nov 27, 2024
Copy link
Contributor

This issue has been locked since it has been closed for more than 14 days.

If you found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Wagmi version. If you have any questions or comments you can create a new discussion thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@imaksp @tmm @AliceW-03 @roshan-synquote and others