-
Couldn't load subscription status.
- Fork 169
Open
Description
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
- Remove the network from your Metamask
- Execute
switchNetworkfrom theuseChain()hook - Confirm the prompt to add the new network
- 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
Metadata
Metadata
Assignees
Labels
No labels