wevm / references

Collection of Chains & Connectors for wagmi
MIT License
97 stars 204 forks source link

bug: incorrect initialization of chains for WalletConnect V2 ethereum provider #469

Closed ElvisKrop closed 1 year ago

ElvisKrop commented 1 year ago

Is there an existing issue for this?

Current Behavior

This is applicable to the connection between any dapp that supports more than one network and wallet that doesn't support the first network from the list of supported networks by the previously mentioned dapp.

Expected Behavior

WalletConnect Connector from Wagmi should not pass any chain id to the array of chains during initialization of WalletConnect. In this case all chain ids will be optional. I will allow to initiate the connection even if wallet supports on network from the list of supported networks by the dapp.

Steps To Reproduce

At first let's go to the Revoke Cash:

  1. open revoke.cash in one tab (it uses wagmi)
  2. click "Connect Wallet"
  3. choose "WalletConnect"

The second part:

  1. open app.safe.global
  2. switch to any network supported by revoke.cash, except Ethereum mainnet
  3. open WalletConnect safe app

Then copy the connection link from Revoke Cash and paste on the pre-opened WalletConnect Safe App.

The error in console says:

Connection refused: This Safe Account is in Goerli but the Wallet Connect session proposal is not valid because it contains: 1) A required chain different than Goerli 2) Does not include Goerli between the optional chains 3) No EVM compatible chain is included

What happened:

WalletConnect Safe App is a safe app that allows to use safe as a wallet. However, each safe exists only on one network. Therefore WalletConnect Safe App initiates the connection with only one allowed network. While dapp supports multiple networks. During initialization of WalletConnect connector from Wagmi dapp passes all chain ids as an argument. Then Wagmi takes all these networks and passes only the first chain id to the Ethereum provider from WalletConnect package. It is not correct, because this array should include required chain ids (see the comment):

The Chains your app intents to use and the peer MUST support. If the peer does not support these chains, the connection will be rejected. In our case the first chain id is 1 (Ethereum Mainnet), but we need 5 (Goerli Testnet)

Link to Minimal Reproducible Example (CodeSandbox, StackBlitz, etc.)

No response

Anything else?

No response

tmm commented 1 year ago

If this issue still exists in the current version of Wagmi, please create a new issue on the Wagmi repo. Connectors are moving over there.