diff --git a/src/views/issuance/components/zap/state/ui-atoms.ts b/src/views/issuance/components/zap/state/ui-atoms.ts index e4e2d0a19..bcb38c7d7 100644 --- a/src/views/issuance/components/zap/state/ui-atoms.ts +++ b/src/views/issuance/components/zap/state/ui-atoms.ts @@ -509,7 +509,6 @@ const signAndSendTx: ZapperAction = async ( set, { signer, provider, rToken, quote, inputToken } ) => { - let resp try { const permit = get(permit2ToSignAtom) if (permit == null) { @@ -539,18 +538,33 @@ const signAndSendTx: ZapperAction = async ( from: tx.tx.from, value: tx.tx.value, }) - resp = await signer.sendTransaction({ + const resp = await signer.sendTransaction({ ...tx.tx, gasLimit: limit, }) + + const receipt = await resp.wait(1) + + if (receipt.status === 0) { + notifyError('Zap failed', 'Transaction reverted on chain') + mixpanel.track('Zap on-chain transaction reverted', { + RToken: rToken.address.toString().toLowerCase() ?? '', + inputToken: inputToken.symbol, + }) + } else { + notifySuccess( + 'Zap successful', + `Zapped ${inputToken.symbol} for ${rToken.symbol}` + ) + mixpanel.track('Zap Success', { + RToken: rToken.address.toString().toLowerCase() ?? '', + inputToken: inputToken.symbol, + }) + } set(permitSignature, null) set(zapTxHash, resp.hash) set(zapInputString, '') set(addTransactionAtom, [resp.hash, `Easy mint ${rToken.symbol}`]) - mixpanel.track('Zap Success', { - RToken: rToken.address.toString().toLowerCase() ?? '', - inputToken: inputToken.symbol, - }) } catch (e: any) { if (e.code === 'ACTION_REJECTED') { mixpanel.track('User Rejected Zap', { @@ -567,12 +581,6 @@ const signAndSendTx: ZapperAction = async ( notifyError('Zap failed', 'Unknown error ' + e.code) } } finally { - if ((await resp.wait(1)).status === 0) { - mixpanel.track('Zap on-chain transaction failed', { - RToken: rToken.address.toString().toLowerCase() ?? '', - inputToken: inputToken.symbol, - }) - } resetTxAtoms(set) } } @@ -588,13 +596,31 @@ const sendTx: ZapperAction = async ( return } set(zapIsPending, true) - let resp try { - resp = await signer.sendTransaction({ + const resp = await signer.sendTransaction({ ...zapTx.transaction.tx, gasLimit, }) + const receipt = await resp.wait(1) + + if (receipt.status === 0) { + notifyError('Zap failed', 'Transaction reverted on chain') + mixpanel.track('Zap on-chain transaction reverted', { + RToken: rToken.address.toString().toLowerCase() ?? '', + inputToken: inputToken.symbol, + }) + } else { + notifySuccess( + 'Zap successful', + `Zapped ${inputToken.symbol} for ${rToken.symbol}` + ) + mixpanel.track('Zap Success', { + RToken: rToken.address.toString().toLowerCase() ?? '', + inputToken: inputToken.symbol, + }) + } + set(zapTxHash, resp.hash) set(permitSignature, null) set(zapInputString, '') @@ -615,12 +641,6 @@ const sendTx: ZapperAction = async ( notifyError('Zap failed', 'Unknown error ' + e.code) } } finally { - if ((await resp.wait(1)).status === 0) { - mixpanel.track('Zap on-chain transaction failed', { - RToken: rToken.address.toString().toLowerCase() ?? '', - inputToken: inputToken.symbol, - }) - } resetTxAtoms(set) } }