Skip to content

Commit

Permalink
logTxToDB updated
Browse files Browse the repository at this point in the history
  • Loading branch information
lufaque committed Dec 16, 2023
1 parent e9ea309 commit 36e3111
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
23 changes: 13 additions & 10 deletions src/components/cards/SwapCard/swapExecution/handleResponses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,36 @@ import { Dispatch } from 'react'
import { logTxToDB } from '../../../../utils/logTxToDB'
import { action, category } from '../../../../constants/tracking'
import { trackEvent } from '../../../../hooks/useTracking'
import { Route } from '@lifi/types'
import { TransactionStatusResponse } from 'rango-sdk/src/types'
import { StandardRoute } from '../../../../types/StandardRoute'

export const handleRangoResponse = (executedRoute, swapDispatch: Dispatch<SwapAction>, provider: 'lifi' | 'rango') => {
export const handleRangoResponse = (executedRoute: TransactionStatusResponse, swapDispatch: Dispatch<SwapAction>, stdRoute: StandardRoute) => {
swapDispatch({ type: 'UPDATE_LAST_SWAP_STEP' })

if (executedRoute.status === TransactionStatus.FAILED) {
swapDispatch({ type: 'SET_SWAP_STAGE', payload: SwapCardStage.failed })
logTxToDB({ tx_id: executedRoute.diagnosisUrl, status: 'failure', provider: 'rango', tx_data: executedRoute })
trackEvent({ category: category.SwapCard, action: action.SwapFailed, label: 'swap_failed', data: { provider: 'rango', executedRoute } })
logTxToDB({ tx_id: executedRoute.diagnosisUrl, status: 'failure', provider: 'rango', tx_data: stdRoute })
trackEvent({ category: category.SwapCard, action: action.SwapFailed, label: 'swap_failed', data: { provider: 'rango', stdRoute } })
} else if (executedRoute.status === 'success') {
swapDispatch({ type: 'SET_SWAP_STAGE', payload: SwapCardStage.success })
logTxToDB({ tx_id: executedRoute.diagnosisUrl, status: 'success', provider: 'rango', tx_data: executedRoute })
trackEvent({ category: category.SwapCard, action: action.SwapSuccess, label: 'swap_success', data: { provider: 'rango', executedRoute } })
logTxToDB({ tx_id: executedRoute.diagnosisUrl, status: 'success', provider: 'rango', tx_data: stdRoute })
trackEvent({ category: category.SwapCard, action: action.SwapSuccess, label: 'swap_success', data: { provider: 'rango', stdRoute } })
}
}

export const handleLifiResponse = (executedRoute, swapDispatch: Dispatch<SwapAction>, provider: 'lifi' | 'rango') => {
export const handleLifiResponse = (executedRoute: Route, swapDispatch: Dispatch<SwapAction>) => {
const stdRoute = standardiseLifiRoute(executedRoute)
const lastExecutionStep = stdRoute.execution[stdRoute.execution.length - 1]
swapDispatch({ type: 'UPDATE_LAST_SWAP_STEP' })

if (lastExecutionStep?.status.toLowerCase() === 'done') {
swapDispatch({ type: 'SET_SWAP_STAGE', payload: SwapCardStage.success })
logTxToDB({ tx_id: executedRoute.id, status: 'success', provider: 'lifi', tx_data: executedRoute })
trackEvent({ category: category.SwapCard, action: action.SwapSuccess, label: 'swap_success', data: { provider: 'lifi', executedRoute } })
logTxToDB({ tx_id: executedRoute.id, status: 'success', provider: 'lifi', tx_data: stdRoute })
trackEvent({ category: category.SwapCard, action: action.SwapSuccess, label: 'swap_success', data: { provider: 'lifi', stdRoute } })
} else if (lastExecutionStep?.status.toLowerCase() === 'failed') {
swapDispatch({ type: 'SET_SWAP_STAGE', payload: SwapCardStage.failed })
logTxToDB({ tx_id: executedRoute.id, status: 'failure', provider: 'lifi', tx_data: executedRoute })
trackEvent({ category: category.SwapCard, action: action.SwapFailed, label: 'swap_failed', data: { provider: 'lifi', executedRoute } })
logTxToDB({ tx_id: executedRoute.id, status: 'failure', provider: 'lifi', tx_data: stdRoute })
trackEvent({ category: category.SwapCard, action: action.SwapFailed, label: 'swap_failed', data: { provider: 'lifi', stdRoute } })
}
}
4 changes: 2 additions & 2 deletions src/components/cards/SwapCard/swapExecution/handleSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const handleSwap = async ({ swapState, swapDispatch, address, switchChain
if (provider === 'rango') {
trackEvent({ category: category.SwapCard, action: action.BeginSwap, label: 'rango_begin_swap', data: originalRoute })
const response = await executeRangoRoute({ route: originalRoute, address, from, settings, swapDispatch, switchChainHook, getChainByProviderSymbol })
handleRangoResponse(response, swapDispatch, provider)
handleRangoResponse(response, swapDispatch)
} else if (provider === 'lifi') {
trackEvent({ category: category.SwapCard, action: action.BeginSwap, label: 'lifi_begin_swap', data: originalRoute })
updateLifiSteps({ swapDispatch, selectedRoute })
Expand All @@ -48,7 +48,7 @@ export const handleSwap = async ({ swapState, swapDispatch, address, switchChain
const acceptExchangeRateUpdateHook = () => Promise.resolve(true)

const response = await executeLifiRoute(signer, originalRoute, { updateRouteHook, switchChainHook, acceptExchangeRateUpdateHook })
handleLifiResponse(response, swapDispatch, provider)
handleLifiResponse(response, swapDispatch)
}
} catch (error: Error) {
console.error('ERROR: ', error)
Expand Down

0 comments on commit 36e3111

Please sign in to comment.