Skip to content

Commit

Permalink
fix transaction details "To" (#1733)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-schrammel authored Oct 21, 2024
1 parent 1009d6a commit 055e774
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/core/utils/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,18 @@ const getAssetFromChanges = (
return changes[0]?.asset;
};

const getAddressTo = (
meta: PaginatedTransactionsApiResponse['meta'],
changes: {
direction: TransactionDirection;
asset: ParsedUserAsset;
address_to: Address;
}[],
) => {
if (meta.type === 'approve') {
return meta?.approval_to;
const getAddressTo = (tx: PaginatedTransactionsApiResponse) => {
switch (tx.meta.type) {
case 'approve':
return tx.meta.approval_to;
case 'sale':
return tx.changes.find((c) => c?.direction === 'out')?.address_to;
case 'receive':
case 'airdrop':
return tx.changes[0]?.address_to;
default:
return tx.address_to;
}
if (meta.type === 'sale')
return changes?.find((c) => c?.direction === 'out')?.address_to;
return changes[0]?.address_to;
};

const getDescription = (
Expand Down Expand Up @@ -274,7 +272,7 @@ export function parseTransaction({
? parseAsset({ asset: meta.asset, currency })
: getAssetFromChanges(changes, type);

const addressTo = asset ? getAddressTo(meta, changes) : tx.address_to;
const addressTo = getAddressTo(tx);

const direction = tx.direction || getDirection(type);

Expand Down

0 comments on commit 055e774

Please sign in to comment.