What event listener used when user closes metamask transaction page without confirming or rejecting transaction

Viewed 30

I'm working on a marketplace using React that users will pay in ETH, I have the web3 function to pay and everything is working fine but I'm working on error handling, What if a user just navigates away when the metamask prompt to pay, like click somewhere else and do not neither approve or deny transaction, how do I detect that action ? is there an event listener or something that I can implement ?

below is my code for onSubmit function for payment

const onSubmit = async () => {

await deployedContract.methods.withdraw(DEPOSIT_CONTRACT_ADDRESS, inputVal).call()
.then((tx) => {
  setLoading(false)
})
.catch((error) => {
  console.log('error: ', error)
  setLoading(false)
  if (error.code === 4001) {
    // onCloseModalLoading()
    // set_wallet_action(false)
    setError("You declined an action in your wallet.")
    // setTimeout(() => {
    //   onOpenModal()
    // }, 300)
  } else {
    // onCloseModalLoading()
    if (error.message) {
      console.log(error.message)
      setError(error.message)
    } else {
      setError("Something went wrong. Transaction didn't push through.")
    }
  }
});
}
0 Answers
Related