useWeb3Transfer onSuccess not working

I am trying to run functions after the transfer is sent successfully and on error I was looking to send a toast with the error. I have tried a few different ways to get it to work but I can’t. The onSuccess and onError work for authenticate but not when i’m trying it with the useWeb3Transfer.

The problem is that when I hit my send button to open the web3 modal, the toast will load when it opens the web3 modal, not after I press reject or send on the web3 modal.

const {fetch, error, isFetching} = useWeb3Transfer({
  amount: Moralis.Units.ETH(0.5),
  receiver: "0x0000000000000000000000000000000000000000",
  type: "native"
  }); 
  
  async function submit(){
    try {
       fetch({
throwOnError: true, 
onSuccess: toast('sent successfully', 
onError: toast('error')
)});
    } catch (error) {
      console.log(error);

    }
  }

Hey you should listen for onColmplete instead of onSucess. It Fires when a request finishes (regardless of a success/error response). So to check if there was an error you can just add some conditional logic. Maybe try something like

 async function submit(){
    try {
       fetch({
              throwOnError: true, 
              onComplete: ()=>{
                     if (error){ return}
                     toast("Sucess")
              }, 
             onError: toast('error')
    )});
    } catch (error) {
      console.log(error);
    }
  }

Sorry for the format, my fourm is acting wierd tdy

Thanks for the reply. I tried it and it kind of works, it will send the error early (on load of the module) and then onComplete sends success toast later. I tried to play around with it a bunch of different ways from the way you wrote it and still couldn’t get it to send the toast correctly.