Uniswap / Uniswap/interface

Random chain switch after connecting with WalletConnect2

Open
#7,619 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
5.5k
Forks
5.4k
PR merge metrics
No merged PRs in 30d

Description

Bug Description
When trying to connect to the interface on https://app.uniswap.org/swap from a mobile app using WalletConnect2, the connected chain changes unnecessarily after establishing the connection. The selected network icon on the top right corner doesn't change, but the network logs show a wrong Infura endpoint being queried and this prevents further operations.
Switching network manually in the frontend back and forth seem to temporarily solve the problem.

Steps to Reproduce

  1. Go to https://app.uniswap.org/swap
  2. Confirm that by default Ethereum Mainnet is selected and check network logs that mainnet.infura.io is being used as chain data provider.
  3. Click on Connect and WalletConnect that opens the QR dialog.
  4. The Session Proposal I receive is as follows (manually formatted)
id: "....", 
pairingTopic: "....",
proposer:  "Uniswap Interface", 
description: "Swap or provide liquidity on the Uniswap Protocol", 
url: "https://app.uniswap.org/", 
icons: ....
requiredNamespaces: [
  "eip155": WalletConnectSign.ProposalNamespace(
    chains: Optional(Set([eip155:1])), 
    methods: Set(["eth_sendTransaction", "personal_sign"]), 
    events: Set(["accountsChanged", "chainChanged"]))
], 
optionalNamespaces: Optional([
  "eip155": WalletConnectSign.ProposalNamespace(
    chains: Optional(Set([eip155:44787, eip155:5, eip155:42220, eip155:421613, eip155:80001, eip155:420, eip155:8453, eip155:1, eip155:137, eip155:56, eip155:11155111, eip155:42161, eip155:10, eip155:43114])), 
    methods: Set(["eth_signTypedData_v4", "eth_sign", "eth_signTypedData", "eth_sendTransaction", "personal_sign"]), 
    events: Set(["disconnect", "message", "chainChanged", "accountsChanged", "connect"]))
]), 
sessionProperties: nil,
  1. Approve the Session with the following supportedNamespaces
sessionProposal: sessionProposal,
chains: [Blockchain("eip155:1")!, Blockchain("eip155:10")!, Blockchain("eip155:137")!, Blockchain("eip155:324")!, Blockchain("eip155:8453")!, Blockchain("eip155:42161")!, Blockchain("eip155:43114")!],
methods: ["eth_sign", "personal_sign", "eth_signTransaction", "eth_sendTransaction", "eth_signTypedData", "eth_signTypedData_v4"],
events: ["chainChanged", "accountsChanged"],
accounts: [
  WalletConnectUtils.Account(blockchain: Blockchain("eip155:1")!, address: connectedAddress)!,   // Ethereum Mainnet
  WalletConnectUtils.Account(blockchain: Blockchain("eip155:10")!, address: connectedAddress)!,  // Optimism
  WalletConnectUtils.Account(blockchain: Blockchain("eip155:137")!, address: connectedAddress)!,  // Polygon
  WalletConnectUtils.Account(blockchain: Blockchain("eip155:324")!, address: connectedAddress)!,  // zkSync Era
  WalletConnectUtils.Account(blockchain: Blockchain("eip155:8453")!, address: connectedAddress)!, // Base
  WalletConnectUtils.Account(blockchain: Blockchain("eip155:42161")!, address: connectedAddress)!, // Arbitrum
  WalletConnectUtils.Account(blockchain: Blockchain("eip155:43114")!, address: connectedAddress)!, // Avalanche C-Chain
]

Most notably this returns a list of supported chains and the same address on each of those chains.

  1. Session is established and interface seems connected. The network doesn't seem to be switched, as still the Ethereum Mainnet icon is displayed in the interface.

  2. Check network logs to confirm that another Infura endpoint is queried now, such as polygon-mainnet.infura.io. This seems like random between the returned chains. (sometimes it switches to Arbitrum, sometimes Polygon, ..). So maybe you were lucky and stayed in Ethereum Mainnet. Try again and again before concluding there is no error.

  3. Switch networks manually in the interface and confirm it switches back to the correct Infura endpoint.

Expected Behavior
The connected chain should stay the same after connection. The Infura requests should be sent to the correct endpoint.

Additional Context
This could be due to an error or undeterministic handling of the supportedNamespaces response.
Note that in WalletConnect2 context there is no "chain selection" in the wallet anymore. Wallets only provide a list of chains they support and it is up to do the dApp to choose, use and send requests on the correct chain. It may / should still handle chainChanged events from the wallet, but it should not expect the wallet to send a limited supportedNamespaces response based on what chain is active at the moment.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the WalletConnect2 connection and session-approval path, focusing on how the supportedNamespaces chains are handled after connection. Reproduce the issue against app.uniswap.org/swap with the listed steps and inspect Infura requests; done means the selected Ethereum chain remains active and requests consistently use its endpoint.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
blockchain, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.