Skip to content

Commit

Permalink
chore: Log swap error (#8664)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xjojoex authored Dec 25, 2023
1 parent b69b10b commit 7bf73e6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions apps/web/src/utils/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export const logSwap = ({
}: {
input: Currency
output: Currency
inputAmount: string
outputAmount: string
inputAmount?: string
outputAmount?: string
chainId: number
account: `0x${string}`
hash: `0x${string}`
Expand Down
20 changes: 16 additions & 4 deletions apps/web/src/views/Swap/V3Swap/hooks/useSendSwapTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { ChainId } from '@pancakeswap/chains'
import { useTranslation } from '@pancakeswap/localization'
import { TradeType } from '@pancakeswap/sdk'
import { ChainId } from '@pancakeswap/chains'
import { SmartRouter, SmartRouterTrade } from '@pancakeswap/smart-router/evm'
import { formatAmount } from '@pancakeswap/utils/formatFractions'
import truncateHash from '@pancakeswap/utils/truncateHash'
import { useUserSlippage } from '@pancakeswap/utils/user'
import { SendTransactionResult } from 'wagmi/actions'
import { INITIAL_ALLOWED_SLIPPAGE } from 'config/constants'
import { useMemo } from 'react'
import { useSwapState } from 'state/swap/hooks'
Expand All @@ -18,7 +17,9 @@ import { transactionErrorToUserReadableMessage } from 'utils/transactionErrorToU
import { viemClients } from 'utils/viem'
import { Address, Hex, hexToBigInt } from 'viem'
import { useSendTransaction } from 'wagmi'
import { SendTransactionResult } from 'wagmi/actions'

import { logger } from 'utils/datadog'
import { isZero } from '../utils/isZero'

interface SwapCall {
Expand Down Expand Up @@ -51,7 +52,7 @@ export class TransactionRejectedError extends Error {}
export default function useSendSwapTransaction(
account?: Address,
chainId?: number,
trade?: SmartRouterTrade<TradeType>, // trade to execute, required
trade?: SmartRouterTrade<TradeType> | null, // trade to execute, required
swapCalls: SwapCall[] | WallchainSwapCall[] = [],
): { callback: null | (() => Promise<SendTransactionResult>) } {
const { t } = useTranslation()
Expand Down Expand Up @@ -212,7 +213,18 @@ export default function useSendSwapTransaction(
throw new TransactionRejectedError(t('Transaction rejected'))
} else {
// otherwise, the error was unexpected and we need to convey that
console.error(`Swap failed`, error, call.address, call.calldata, call.value)
logger.error(
'Swap failed',
{
chainId,
input: trade.inputAmount.currency,
output: trade.outputAmount.currency,
address: call.address,
calldata: call.calldata,
value: call.value,
},
error,
)

throw new Error(`Swap failed: ${transactionErrorToUserReadableMessage(error, t)}`)
}
Expand Down

0 comments on commit 7bf73e6

Please sign in to comment.