Skip to content

Commit

Permalink
feat: cow swapper simplify status detection (#8568)
Browse files Browse the repository at this point in the history
  • Loading branch information
gomesalexandre authored Jan 15, 2025
1 parent 6afc9d3 commit 96f4df0
Showing 1 changed file with 11 additions and 36 deletions.
47 changes: 11 additions & 36 deletions packages/swapper/src/swappers/CowSwapper/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,10 @@ import type {
TradeRate,
} from '../../types'
import { SwapperName } from '../../types'
import {
checkSafeTransactionStatus,
createDefaultStatusResponse,
getHopByIndex,
isExecutableTradeQuote,
} from '../../utils'
import { checkSafeTransactionStatus, getHopByIndex, isExecutableTradeQuote } from '../../utils'
import { getCowSwapTradeQuote } from './getCowSwapTradeQuote/getCowSwapTradeQuote'
import { getCowSwapTradeRate } from './getCowSwapTradeRate/getCowSwapTradeRate'
import type { CowSwapGetTradesResponse, CowSwapGetTransactionsResponse } from './types'
import type { CowSwapGetTradesResponse } from './types'
import { cowService } from './utils/cowService'
import { deductAffiliateFeesFromAmount, deductSlippageFromAmount } from './utils/helpers/helpers'

Expand Down Expand Up @@ -184,38 +179,18 @@ export const cowApi: SwapperApi = {
const { data: trades } = maybeTradesResponse.unwrap()
const buyTxHash = trades[0]?.txHash

if (!buyTxHash) return createDefaultStatusResponse(undefined)

const maybeGetOrdersResponse = await cowService.get<CowSwapGetTransactionsResponse>(
`${config.REACT_APP_COWSWAP_BASE_URL}/${network}/api/v1/transactions/${buyTxHash}/orders`,
)

if (maybeGetOrdersResponse.isErr()) throw maybeGetOrdersResponse.unwrapErr()

const {
data: [{ status: rawStatus }],
} = maybeGetOrdersResponse.unwrap()

// https://api.cow.fi/docs/#/default/get_api_v1_orders__UID_
const status = (() => {
switch (rawStatus) {
case 'fulfilled':
return TxStatus.Confirmed
case 'presignaturePending':
case 'open':
return TxStatus.Pending
case 'cancelled':
case 'expired':
return TxStatus.Failed
default:
return TxStatus.Unknown
if (buyTxHash) {
return {
status: TxStatus.Confirmed,
buyTxHash,
message: 'fulfilled',
}
})()
}

return {
status,
buyTxHash,
message: rawStatus,
status: TxStatus.Pending,
buyTxHash: undefined,
message: 'open',
}
},
}

0 comments on commit 96f4df0

Please sign in to comment.