You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 switchNetwork from the useChain() 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
The text was updated successfully, but these errors were encountered:
Issue Description
The
switchNetwork
function of theuseChain()
hook has a bug when the user rejects the switch after adding the network.The
switchNetwork
function should return aPromise.reject
but instead returnsPromise.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
switchNetwork
from theuseChain()
hookThe code is pretty simple:
Actual Outcome
The
then
clause is executed, making it seems like the network was switched successfullyExpected Outcome
The
catch
clause should be executed as the network was not switchedEnvironment
Client
1.4.0
1.10.0
MacOs 12.4
Brave v1.41.100
The text was updated successfully, but these errors were encountered: