useDApp
useDApp copied to clipboard
Switching Accounts in Metamask Mobile causes unstable behaviour
Describe the bug
Using Metamask Mobile, if we connect to the website using useDapp (i.e. Account A), then switch to another account (i.e. Account B), a bug occurs once we make a wallet interaction (e.g. sign message). As far as I can tell, as soon as we run a function which causes wallet interaction, the account pulled from useEthers() will immediately glitch back to Account A (despite Account B being selected in Metamask Mobile), assuming we are signing a message, the Metamask Popup will actually show Account B when asking if you want to sign the message (so account via useEthers glitches back to the account which was selected when first connecting, despite the Metamask Mobile dialogue showing Account B, furthermore, upon signing the message and running an ecrecover on the signed message, we will see that it was signed by Account A).
To Reproduce
For the sake of this description, let's imagine a user has Account A and Account B stored within the same Metamask Mobile instance.
- User initially connects to a website using
Account A - User switches to
Account B(bug is now locked and loaded, ready to show) - User tries to sign a message using
Account B accountfromuseEthersglitches back toAccount A- Metamask Mobile confirms if user wants to sign message using
Account B ecrecoveron the signed message shows that it was signed byAccount A, instead ofAccount B
Software versions
useDappversion:1.1.5- yarn
- Node version:
v14.16.0
Additional context
Video demonstration using https://example.usedapp.io/ - unfortunately the example website isn't mobile friendly but I've done my best to add some basic annotations as to what is happening
https://user-images.githubusercontent.com/14224459/196252756-9608d169-6f68-48ef-892c-3ee85727b190.mp4