Web3Auth / web3auth-wagmi-connector

Web3Auth connector for wagmi
25 stars 24 forks source link

[BUG] connector.switchChain sets chain blockExplorer incorrectly #112

Open W3stside opened 9 months ago

W3stside commented 9 months ago

Issue

async switchChain(chainId: number) {
    try {
      const chain = this.chains.find((x) => x.id === chainId);
      if (!chain) throw new SwitchChainError(new Error("chain not found on connector."));

      await this.web3AuthInstance.addChain({
        chainNamespace: CHAIN_NAMESPACES.EIP155,
        chainId: `0x${chain.id.toString(16)}`,
        rpcTarget: chain.rpcUrls.default.http[0],
        displayName: chain.name,

        // This returns the first character of the string URL since type change
        // chain.blockExplorers?.default is not an array. it is a string
        blockExplorer: chain.blockExplorers?.default.url[0] || "",
       // blockExplorer: chain.blockExplorers?.default.url || "", // should be instead

        ticker: chain.nativeCurrency?.symbol || "ETH",
        tickerName: chain.nativeCurrency?.name || "Ethereum",
        decimals: chain.nativeCurrency.decimals || 18,
      });
      log.info("Chain Added: ", chain.name);
      await this.web3AuthInstance.switchChain({ chainId: `0x${chain.id.toString(16)}` });
      log.info("Chain Switched to ", chain.name);
      return chain;
    } catch (error: unknown) {
      log.error("Error: Cannot change chain", error);
      throw new SwitchChainError(error as Error);
    }
  }

On a side and related note, Wagmi's switchChain no longer works (at least in testnet) with Web3AuthConnector on versions:

    "@web3auth/base": "7.2.1",
    "@web3auth/modal": "7.3.0",
    "@web3auth/openlogin-adapter": "7.2.1",
    "@web3auth/web3auth-wagmi-connector": "5.0.1",
brianonchain commented 8 months ago

Any updates on this? I believe I am having the same issues.

W3stside commented 2 months ago

@brianonchain was fixed in latest 8.x

W3stside commented 2 months ago

actually it wasn't -- see #148