WalletConnect / web3modal-react-native

Web3Modal React-Native SDK
https://web3modal.com
Apache License 2.0
43 stars 14 forks source link

[bug]: An error occurred when attempting to switch chain #162

Closed socheatleang closed 4 days ago

socheatleang commented 1 month ago

Description

I connected with metamask on chain 43114, Then I try to switchNetwork by using useSwitchNetwork from wagmi@1.

Web3Modal SDK version

"@web3modal/wagmi-react-native": "^1.3.0",

Output of npx react-native info

System:
    OS: macOS 14.1
    CPU: (8) x64 Apple M1 Pro
    Memory: 34.66 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 14.19.2 - ~/.nvm/versions/node/v14.19.2/bin/node
    Yarn: 1.22.18 - /opt/homebrew/bin/yarn
    npm: 6.14.17 - ~/.nvm/versions/node/v14.19.2/bin/npm
    Watchman: 2023.12.04.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.14.3 - /opt/homebrew/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 23.0, iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0
    Android SDK:
      Android NDK: 22.1.7171670
  IDEs:
    Android Studio: 2023.2 AI-232.10227.8.2321.11479570
    Xcode: 15.0.1/15A507 - /usr/bin/xcodebuild
  Languages:
    Java: 20.0.2 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0 
    react-native: 0.71.14 => 0.71.14 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Expo Version (if applies)

"expo": "~48.0.21",

Steps to reproduce

Snack, code example, screenshot, or link to a repository

import {
  useNetwork,
  useSwitchNetwork,
} from 'wagmi';

const Screen = () => {
  const { switchNetwork, chains } = useSwitchNetwork();
  const { chain } = useNetwork();

useEffect(() => {  // get the chain after wallet connected 
    if (!chain?.id) return;
    if (chain?.id !== 137) {
      const targetChain = chains?.find((cin) => cin.id === 137);
      if (!targetChain) {
        alert('Target chain not found!');
        return;
      }
      switchNetwork?.(targetChain?.id);
    }
  }, [chain, switchNetwork, chains]);

}
ignaciosantise commented 1 month ago

Hey @socheatleang what's the issue exactly? Can you provide more details? And also a video could help

ignaciosantise commented 1 month ago

@socheatleang any new about this?

ignaciosantise commented 4 days ago

closing for now. I'll reopen if we have more info