blocknative / web3-onboard

Client library to onboard users to web3 apps
https://onboard.blocknative.com/
MIT License
854 stars 510 forks source link

[Bug]: Changing accounts in wallet connect changes account then instantly changes back #1640

Closed dweng0 closed 1 year ago

dweng0 commented 1 year ago

Current Behavior

Using a minimal reproducible stackblitz example (This is a stripped down fork of your react-demo branch).

  1. Select - Connect using wallet connect
  2. open metamask app on mobile phone
  3. scan using QR code to connect
  4. on metmask app, change account

UI updates but immediately updates back to previous account.

It is hard to debug from this end. But it looks like an RXJS event is firing twice, as one of the subs picks up a wallet change, and then picks up the account change inside the wallet, but the ordering is the wrong way round. (new account first then old account last)

Expected Behavior

  1. Select - Connect using wallet connect
  2. open metamask app on mobile phone
  3. scan using QR code to connect
  4. on metmask app, change account
  5. Account updates.

Steps To Reproduce

View code on stackblitz

View application on stackblitz

What package is effected by this issue?

@web3-onboard/core

Is this a build or a runtime issue?

Runtime

Package Version

6.1.9

Node Version

No response

What browsers are you seeing the problem on?

Chrome

Relevant log output

No response

Anything else?

No response

Sanity Check

dweng0 commented 1 year ago

Here's a video, but not sure how much help it will be, given i'm changing the account on metamask (so you can't see the interaction). But it gives you an idea of what it does atleast.

The sudden change of address (Then change back) occurs around 20 seconds in.

https://user-images.githubusercontent.com/5268627/231763897-034d7370-ab34-4da4-869e-b1f542ea5058.mp4

Adamj1232 commented 1 year ago

Thanks for reporting @dweng0 we will have a look! Are you using WalletConnect v1 or v2?

hlopes-ledger commented 1 year ago

I couldn't get the example links above to work but I'm having this issue as well on my side.

When using WalletConnect v1 to connect to Ledger Live (and I suppose any other wallet), if you switch to a different account you can only see it flash for a second on the dApp, and it goes back to the previous one. Switching chains works but the address will always be the first one it connects to.

This works as intended when using the Ledger Extension. When you switch to a new address from the Extension it is added to the web3-onboard list and you can use the "Set Primary Account" menu item to switch on the dApp.

On WalletConnect v2 I'm not sure there is a way to set an active account.

dweng0 commented 1 year ago

Thanks for reporting @dweng0 we will have a look! Are you using WalletConnect v1 or v2?

its this one: "@web3-onboard/walletconnect": "2.2.2", i dont pass any options into it either (can see it in the stackblitz IDE)

Adamj1232 commented 1 year ago

@dweng0 @hlopes-ledger this is fixed in alpha version 2.3.6-alpha.1 of @web3-onboard/walletconnect if you would like to give it a test. Prod release will be out later this week.