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

useChainId and useNetwork returning the wrong chainId and wrong network after switching networks with useSwitchNetwork when using web3auth wagmi connector #111

Open
Hyun2 opened this issue Dec 21, 2023 · 2 comments

Comments

@Hyun2
Copy link

Hyun2 commented Dec 21, 2023

Describe the bug

useChainId and useNetwork returning the wrong chainId and wrong network after switching networks with useSwitchNetwork when using web3auth wagmi connector.

To Reproduce

Steps to reproduce the behavior:

  1. clone web3auth-pnp-examples(https://github.com/Web3Auth/web3auth-pnp-examples) repository
  2. Go to 'web-modal-sdk/wagmi-examples/wagmi-modal-example'
  3. See bug bug gif

Code

  const { chain } = useNetwork()
  const { chains, error, pendingChainId, switchNetwork, status } =
    useSwitchNetwork()

  return (
    <div>
      {chain && <div>Using {chain.name}</div>}

      {chains.map((x) => (
        <button
          disabled={!switchNetwork || x.id === chain?.id}
          key={x.id}
          onClick={() => switchNetwork?.(x.id)}
        >
          Switch to {x.name}
          {status === 'loading' && x.id === pendingChainId && '…'}
        </button>
      ))}

      <div>{error && (error?.message ?? 'Failed to switch')}</div>
    </div>
  )

Expected behavior

After clicking the Switch to Ethereum button, the chain data should be Ethereum, and Using Goerli should be changed to Using Ethereum on the screen.
(The chain data obtained through useNetwork() should be the changed network data).

Screenshots

https://imgur.com/5b0Am18

Note

If I use other connectors (provided by rainbowkit), it works fine, but if I use web3auth-wagmi-connector, it works abnormally.

Device Info (please complete the following information):

  • Device: macbook
  • OS: mac os
  • Browser: chrome
  • Version
    "@web3auth/base": "^7.2.0",
    "@web3auth/ethereum-provider": "^7.2.0",
    "@web3auth/modal": "^7.2.0",
    "@web3auth/openlogin-adapter": "^7.2.0",
    "@web3auth/torus-wallet-connector-plugin": "^7.2.0",
    "@web3auth/web3auth-wagmi-connector": "^5.0.1",
@W3stside
Copy link

W3stside commented Jan 6, 2024

@Hyun2 this fixes it for me testing locally. Hopefully they can see it and approve.

#113

@barenfels
Copy link

+1, experiencing the same bug

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

3 participants