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

switchNetwork bug when rejecting switch right after adding network #265

Open
thomasvalera opened this issue Jul 26, 2022 · 0 comments
Open

Comments

@thomasvalera
Copy link

Issue Description

The switchNetwork function of the useChain() hook has a bug when the user rejects the switch after adding the network.
The switchNetwork function should return a Promise.reject but instead returns Promise.resolve making it seem like the network was switched.

This is a serious bug as it will continue execution and could send a payment from the wrong wallet on the wrong chain without anybody noticing.

Steps + code to reproduce

  1. Remove the network from your Metamask
  2. Execute switchNetwork from the useChain() hook
  3. Confirm the prompt to add the new network
  4. Reject the prompt to switch

The code is pretty simple:

const {switchNetwork} = useChain();

return switchNetwork(POLYGON_CHAIN_ID)
.then(() => {
    // The network has been added and switched, continue execution
}).catch((error) => {
    // The network has not been added or has not been switched, handle error
})

Actual Outcome

The then clause is executed, making it seems like the network was switched successfully

Expected Outcome

The catch clause should be executed as the network was not switched

Environment

Client

  • react-moralis version: 1.4.0
  • Moralis SDK version: 1.10.0
  • Operating system: MacOs 12.4
  • Browser: Brave v1.41.100
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

1 participant