From 45a138dec12144ccc9d059805bb2f2d719e70d93 Mon Sep 17 00:00:00 2001 From: cartcrom <39385577+cartcrom@users.noreply.github.com> Date: Fri, 1 Sep 2023 14:55:42 -0400 Subject: [PATCH] fix: detect refunds on exact_out native swaps (#7227) * fix: detect refunds on exact_out native swaps * fix: correct comment --- .../MiniPortfolio/Activity/parseRemote.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/components/AccountDrawer/MiniPortfolio/Activity/parseRemote.tsx b/src/components/AccountDrawer/MiniPortfolio/Activity/parseRemote.tsx index 51f8e5fc26..4c0bc49f5a 100644 --- a/src/components/AccountDrawer/MiniPortfolio/Activity/parseRemote.tsx +++ b/src/components/AccountDrawer/MiniPortfolio/Activity/parseRemote.tsx @@ -159,10 +159,16 @@ function parseSwap(changes: TransactionChanges) { } // Some swaps may have more than 2 transfers, e.g. swaps with fees on tranfer if (changes.TokenTransfer.length >= 2) { - const sent = changes.TokenTransfer.find((t) => t?.__typename === 'TokenTransfer' && t.direction === 'OUT') - const received = changes.TokenTransfer.find((t) => t?.__typename === 'TokenTransfer' && t.direction === 'IN') + const sent = changes.TokenTransfer.find((t) => t.direction === 'OUT') + // Any leftover native token is refunded on exact_out swaps where the input token is native + const refund = changes.TokenTransfer.find( + (t) => t.direction === 'IN' && t.asset.id === sent?.asset.id && t.asset.standard === 'NATIVE' + ) + const received = changes.TokenTransfer.find((t) => t.direction === 'IN' && t !== refund) + if (sent && received) { - const inputAmount = formatNumberOrString(sent.quantity, NumberType.TokenNonTx) + const adjustedInput = parseFloat(sent.quantity) - parseFloat(refund?.quantity ?? '0') + const inputAmount = formatNumberOrString(adjustedInput, NumberType.TokenNonTx) const outputAmount = formatNumberOrString(received.quantity, NumberType.TokenNonTx) return { title: getSwapTitle(sent, received),