Skip to content

Commit

Permalink
chore: move logging into main block
Browse files Browse the repository at this point in the history
  • Loading branch information
larrythecucumber321 committed Oct 19, 2023
1 parent e178c5f commit 2746590
Showing 1 changed file with 40 additions and 20 deletions.
60 changes: 40 additions & 20 deletions src/views/issuance/components/zap/state/ui-atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ const signAndSendTx: ZapperAction = async (
set,
{ signer, provider, rToken, quote, inputToken }
) => {
let resp
try {
const permit = get(permit2ToSignAtom)
if (permit == null) {
Expand Down Expand Up @@ -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', {
Expand All @@ -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)
}
}
Expand All @@ -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, '')
Expand All @@ -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)
}
}

0 comments on commit 2746590

Please sign in to comment.