From 9d867ce352573ca7edccd0867f69d4e532935782 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20Mi=C3=B1o?= Date: Fri, 7 Jun 2024 23:41:14 -0400 Subject: [PATCH] fix: parse tx to address in activity (#1567) --- lavamoat/build-webpack/policy.json | 9 +++++++-- src/core/utils/transactions.ts | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lavamoat/build-webpack/policy.json b/lavamoat/build-webpack/policy.json index 377dcd8214..8d15a9aa99 100644 --- a/lavamoat/build-webpack/policy.json +++ b/lavamoat/build-webpack/policy.json @@ -1156,8 +1156,13 @@ "define": true }, "packages": { - "jest>@jest/core>jest-snapshot>@babel/traverse>@babel/generator>@jridgewell/trace-mapping>@jridgewell/sourcemap-codec": true, - "webpack>terser-webpack-plugin>@jridgewell/trace-mapping>@jridgewell/resolve-uri": true + "jest>@jest/core>jest-snapshot>@babel/traverse>@babel/generator>@jridgewell/trace-mapping>@jridgewell/resolve-uri": true, + "jest>@jest/core>jest-snapshot>@babel/traverse>@babel/generator>@jridgewell/trace-mapping>@jridgewell/sourcemap-codec": true + } + }, + "jest>@jest/core>jest-snapshot>@babel/traverse>@babel/generator>@jridgewell/trace-mapping>@jridgewell/resolve-uri": { + "globals": { + "define": true } }, "jest>@jest/core>jest-snapshot>@babel/traverse>@babel/generator>@jridgewell/trace-mapping>@jridgewell/sourcemap-codec": { diff --git a/src/core/utils/transactions.ts b/src/core/utils/transactions.ts index f5e97cee3c..9e77b688e8 100644 --- a/src/core/utils/transactions.ts +++ b/src/core/utils/transactions.ts @@ -173,6 +173,19 @@ const getAssetFromChanges = ( return changes[0]?.asset; }; +const getAddressToFromChanges = ( + changes: { + direction: TransactionDirection; + asset: ParsedUserAsset; + address_to: Address; + }[], + type: TransactionType, +) => { + if (type === 'sale') + return changes?.find((c) => c?.direction === 'out')?.address_to; + return changes[0]?.address_to; +}; + const getDescription = ( asset: ParsedAsset | undefined, type: TransactionType, @@ -253,6 +266,10 @@ export function parseTransaction({ ? parseAsset({ asset: meta.asset, currency }) : getAssetFromChanges(changes, type); + const addressTo = asset + ? getAddressToFromChanges(changes, type) + : tx.address_to; + const direction = tx.direction || getDirection(type); const description = getDescription(asset, type, meta); @@ -285,7 +302,7 @@ export function parseTransaction({ return { from: tx.address_from, - to: tx.address_to, + to: addressTo, title: i18n.t(`transactions.${type}.${status}`), description, hash,