Uniswap / interface

🦄 Open source interfaces for the Uniswap protocol
https://app.uniswap.org
GNU General Public License v3.0
4.88k stars 4.96k forks source link

Request wallet to match the app network upon connect #3181

Open willhennessy opened 2 years ago

willhennessy commented 2 years ago

Steps to Reproduce

  1. Visit app.uniswap.org
  2. Disconnect your wallet from the app
  3. Switch your wallet to Ethereum
  4. Switch the app to Polygon
  5. Now click 'Connect wallet' in the app

Actual Behavior The wallet connects on Ethereum and completely overrides the app state = Polygon.

Expected Behavior The app says Polygon and I'm looking at a price quote on Polygon, so I expect my wallet to connect to Polygon network.

This bug was made more prevalent by two recent launches

  1. The ability to switch networks in the unconnected state. It's not very easy for the user's wallet to mismatch the app.
  2. Chainid as a URL param. Users will now be pointed directly to a particular chain
willhennessy commented 2 years ago

this is how wallet connect works, for better and worse!

muratogat commented 2 years ago

This is only partly true. Yes, for WC connections, the wallet decides at the end for which chainId the connection is going to be established. However it is also possible to specify a chainId during session request, which the wallet can capture and respect. In OP case, if Uniswap correctly specified that the selected network is Polygon, since the wallet also supports Polygon, it would be able to capture and use the correct chainId. I am having the same problem with my wallet supporting WC when connecting to Uniswap and try to use Optimism.

Steps:

  1. Open https://app.uniswap.org/ . No wallets connected at this point.
  2. Switch to Optimism
  3. "Connect Wallet" -> "WalletConnect"
  4. Scan QR and approve in the wallet supporting Optimism.

Expected Behavior:

Actual Behavior:

import WalletConnectProvider from "@walletconnect/web3-provider";

const provider = new WalletConnectProvider({
  ...
  chainId: 10,   // <--- this is supported although not very clearly documented
  ...
});
this.wcProvider.enable();
willhennessy commented 2 years ago

Thanks! I’ll reopen this