ChangoMan / web3modal-example

Example using web3modal and Next.js

Home Page:web3modal-example.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug in handleChainChanged

rootulp opened this issue · comments

I observed a bug while auditing this code. handleChainChanged currently doesn't dispatch a SET_CHAIN_ID action. It looks like a copy + paste mistake from handleAccountsChanged

const handleChainChanged = (accounts: string[]) => {
// eslint-disable-next-line no-console
console.log('accountsChanged', accounts)
dispatch({
type: 'SET_ADDRESS',
address: accounts[0],
})

Per https://docs.ethers.io/v5/concepts/best-practices/#best-practices--network-changes I think it would be preferable to hard refresh the website if the chain changes. Happy to create a PR for this. The diff looks like:

      // https://docs.ethers.io/v5/concepts/best-practices/#best-practices--network-changes
      const handleChainChanged = (_hexChainId: string) => {
        window.location.reload();
      }

@rootulp Oh yes, thanks for catching that. Indeed looks like a copy/paste mistake! A PR would be much appreciated.

I've actually patched this up just now, also updated the dependencies for the repo. Thanks again for the help!