WalletConnect / walletconnect-monorepo

WalletConnect Monorepo
Apache License 2.0
1.47k stars 715 forks source link

iPhone metmask switch walletconnect not work #1004

Closed agiledev624 closed 1 year ago

agiledev624 commented 2 years ago

I'm going to connect metamask via walletconnect on iOS 15. When I was going to switch chains, it does nothing. Web3modal + walletconnect were used. I tried to get logs on safari but sometimes it says no rpc for chainId 250 or web socket error. Not sure how to resolve it. Maybe is it because we need to adjust some dependency modules along specific iPhone model? Really weird.

mubarakone commented 2 years ago

ChainId 250 I think is Fantom Wallet, this is most likely a rpc connection issue from their end.

Few Questions: Did you find anyone else using Fantom having this problem? If not... Are you already connected to Metamask, and tried to switch chains on your application while being connected? What did you use to switch chains, web3.js or ethers.js? Show the code below so I can see what you implemented.

agiledev624 commented 2 years ago

I'm using web3modal and walletconnect provider on react. I put this providerOptions for web3modal. (I show the fantom only here)

      case 250:
      return {
        network: 'fantom',
        // cacheProvider: true,
        providerOptions: {
          injected: {
            display: {
              name: 'MetaMask',
            },
          },
          'custom-wc-ftm': {
            display: {
              logo: require(`images/wallets/wallet-connect.svg`),
              name: 'Wallet Connect',
              description: t('Scan your WalletConnect to Connect'),
            },
            package: WalletConnectProvider,
            options: {
              rpc: {
                // 1: 'https://rpc.ftm.tools/',
                // 250: 'https://rpc.ftm.tools/',
                1: 'https://rpc.ankr.com/eth/',
                56: 'https://bsc-dataseed.binance.org/',
                128: 'https://http-mainnet.hecochain.com',
                43114: 'https://api.avax.network/ext/bc/C/rpc',
                137: 'https://polygon-rpc.com/',
                250: 'https://rpc.ftm.tools/',
                1666600000: 'https://api.harmony.one/',
                42161: 'https://arb1.arbitrum.io/rpc',
                1285: 'https://rpc.moonriver.moonbeam.network',
                42220: 'https://forno.celo.org',
                25: 'https://evm-cronos.crypto.org/',
                122: 'https://rpc.fuse.io',
                1088: 'https://andromeda.metis.io/?owner=1088',
                1284: 'https://rpc.api.moonbeam.network',
              },
            },
            connector: async (ProviderPackage, options) => {
              const provider = new ProviderPackage(options);

              await provider.enable();

              return provider;
            },
          },

And it seems like connecting is working. Metamask popup but switching not working.

export const networkSetup = chainId => {
  return new Promise((resolve, reject) => {
    const provider = window.ethereum;
    if (provider) {
      if (networkSettings.hasOwnProperty(chainId)) {
        try {
          provider
            .request({
              method: 'wallet_switchEthereumChain',
              params: [{ chainId: networkSettings[chainId].chainId }],
            })
            .then(resolve);
        } catch (switchError) {
          console.log(switchError);
          // if (switchError.code === 4902) {
          try {
            provider
              .request({
                method: 'wallet_addEthereumChain',
                params: [networkSettings[chainId]],
              })
              .then(resolve)
              .catch(reject);
            // await ethereum.request({
            //   method: 'wallet_addEthereumChain',
            //   params: [{ chainId: '0xf00', rpcUrl: 'https://...' /* ... */ }],
            // });
          } catch (addError) {
            // handle "add" error
          }
          // }
          // handle other "switch" errors
        }
      } else {
        reject(new Error(`No network settings configured for chainId: '${chainId}'`));
      }
    } else {
      reject(new Error(`window.ethereum is '${typeof provider}'`));
    }
  });
};
ihorbond commented 2 years ago

@agiledev624 it works fine in my dapp. Click Mint then Wallet Connect then scan QR code from metamask wallet app on iOS. It prompted me to add new network and then switch to it. https://mint.zerocodenft.com/?siteId=5f9895aa-eaf5-439b-f666-08da189e14b0

transonhy96 commented 1 year ago

It's because your metamask was not added the Fantom chain yet, you need to call provider .request({ method: 'wallet_addEthereumChain', params: [networkSettings[chainId]], } And in wallet connect the provider is not window.ethereum

finessevanes commented 1 year ago

@agiledev624 is still this an issue?