[X] I checked there isn't already an issue for the bug I encountered.
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.
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.
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