ChangoMan / web3modal-example

Example using web3modal and Next.js
web3modal-example.vercel.app
MIT License
104 stars 49 forks source link

Bug in handleChainChanged #5

Closed rootulp closed 2 years ago

rootulp commented 2 years ago

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

https://github.com/ChangoMan/web3modal-example/blob/e4cae617039adff40f35c64282ddddbf8128b280/pages/index.tsx#L174-L180

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();
      }
ChangoMan commented 2 years ago

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

ChangoMan commented 2 years ago

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