Skip to content

Commit

Permalink
Merge pull request #1713 from sushi-labs/sentry
Browse files Browse the repository at this point in the history
sentry: add breadcrumbs for swap execution and set context
  • Loading branch information
matthewlilley authored Oct 1, 2024
2 parents 3604efd + 9b8dc03 commit 78f46a8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ const useSimpleSwapTrade = () => {
[slippagePercent, tokenTax],
)

const apiTrade = useApiTrade({
const trade = useApiTrade({
chainId,
fromToken: token0,
toToken: token1,
Expand All @@ -430,7 +430,7 @@ const useSimpleSwapTrade = () => {
setTokenTax(undefined)
}, [token0, token1, setTokenTax])

return apiTrade
return trade
}

export {
Expand Down
47 changes: 44 additions & 3 deletions apps/web/src/ui/swap/simple/simple-swap-trade-review-dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client'

import * as Sentry from '@sentry/nextjs'
import { createErrorToast, createToast } from '@sushiswap/notifications'
import {
BrowserEvent,
Expand Down Expand Up @@ -42,7 +43,7 @@ import { useApproved } from 'src/lib/wagmi/systems/Checker/Provider'
import { Chain, ChainId } from 'sushi/chain'
import { Native } from 'sushi/currency'
import { shortenAddress } from 'sushi/format'
import { ZERO } from 'sushi/math'
import { Percent, ZERO } from 'sushi/math'
import {
SendTransactionReturnType,
UserRejectedRequestError,
Expand Down Expand Up @@ -85,6 +86,23 @@ export const SimpleSwapTradeReviewDialog: FC<{

const refetchBalances = useBalanceWeb3Refetch()

useEffect(() => {
if (!trade) return
Sentry.setContext('swap-context', {
chainId,
amountIn: trade?.amountIn?.toSignificant(6),
amountOut: trade?.amountOut?.toSignificant(6),
minAmountOut: trade?.minAmountOut?.toSignificant(6),
fromToken: trade?.route?.fromToken,
toToken: trade?.route?.toToken,
priceImpact: trade?.priceImpact?.toPercentageString(),
tokenTax:
trade?.tokenTax instanceof Percent
? trade.tokenTax.toPercentageString()
: trade?.tokenTax,
})
}, [trade, chainId])

const isWrap =
token0?.isNative &&
token1?.wrapped.address === Native.onChain(chainId).wrapped.address
Expand Down Expand Up @@ -133,7 +151,10 @@ export const SimpleSwapTradeReviewDialog: FC<{

try {
const ts = new Date().getTime()
const receiptPromise = client.waitForTransactionReceipt({ hash })
const receiptPromise = client.waitForTransactionReceipt({
hash,
retryCount: 30,
})

sendAnalyticsEvent(SwapEventName.SWAP_SIGNED, {
...trace,
Expand Down Expand Up @@ -253,15 +274,35 @@ export const SimpleSwapTradeReviewDialog: FC<{

return async (confirm: () => void) => {
try {
Sentry.addBreadcrumb({
category: 'swap',
message: 'Swap execution in progress',
level: 'info',
})
await sendTransactionAsync(simulation)
// Add breadcrumb for successful swap
Sentry.addBreadcrumb({
category: 'swap',
message: 'Swap completed successfully',
level: 'info',
})
confirm()
} catch {}
} catch (e) {
Sentry.addBreadcrumb({
category: 'swap',
message: 'Swap failed',
level: 'error',
})
Sentry.captureException(e)
throw e
}
}
}, [simulation, sendTransactionAsync])

const { status } = useWaitForTransactionReceipt({
chainId: chainId,
hash: data,
retryCount: 30,
})

return (
Expand Down

0 comments on commit 78f46a8

Please sign in to comment.