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:
- clone
web3auth-pnp-examples
(GitHub - Web3Auth/web3auth-pnp-examples) repository - Go to ‘web-modal-sdk/wagmi-examples/wagmi-modal-example’
- 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
Note
If I use other connectors (provided by rainbowkit), it works fine, but if I use web3auth-wagmi-connector
, it works abnormally.