Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
W3stside opened this issue Jan 5, 2024 · 3 comments
Open

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

W3stside opened this issue Jan 5, 2024 · 3 comments

Comments

@W3stside
Copy link

W3stside commented Jan 5, 2024

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
Copy link

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

@W3stside
Copy link
Author

@brianonchain was fixed in latest 8.x

@W3stside
Copy link
Author

actually it wasn't -- see #148

@W3stside W3stside reopened this Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants