rainbow-me / browser-extension

An Ethereum wallet built for speed 🌈
https://rainbow.me/
GNU General Public License v3.0
170 stars 40 forks source link

Unable to switch networks #1597

Closed AlexBHarley closed 4 months ago

AlexBHarley commented 5 months ago

Description

Wagmi's wallet.data.switchChain does nothing when using the Rainbow browser extension. It works correctly with MetaMask.

Dependencies

    "@wagmi/core": "^2.11.5",
    "wagmi": "^2.10.5",
    "@rainbow-me/rainbowkit": "^2.1.2",

Reproduction

import { Chain } from "viem";
import { useWalletClient } from "wagmi";

export const useSwitchChain = () => {
  const wallet = useWalletClient();

  return async (chain: Chain) => {
    try {
      await wallet.data?.switchChain({ id: chain.id });
    } catch (e: any) {
      if (e.message.includes("Unrecognized chain ID")) {
        await wallet.data?.addChain({ chain });
      }
    }
  };
};

Alternatively you can navigate to Superbridge and try bridge an ERC20 token. There you will see the Switch to approve button does nothing.

DanielSinclair commented 4 months ago

@AlexBHarley Tested against the dApp, and it looks like everything is working as expected. Network switches don't require an approval in Rainbow, so you'll see a notification at the top right that the network has been changed. You can always design around this in your app by automatically performing a switch without a user interaction for Rainbow. You can detect the wallet with our rdns me.rainbow for EIP-6963, or window.ethereum.isRainbow.