Skip to content

Commit

Permalink
fix: only show memo for sent transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
friedger committed Jun 20, 2023
1 parent c99e4af commit bbfeb04
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
isDelegatedStackingTx,
inferSendManyTransferOperation,
isSendManyTx,
getMemoForTx,
} from '@utils/tx-utils';
import { toHumanReadableStx } from '@utils/unit-convert';
import React, {
Expand Down Expand Up @@ -106,12 +107,8 @@ export const TransactionListItem: FC<TransactionListItemProps> = props => {
}, [direction, poxInfo?.contract_id, tx]);

const sumPrefix = direction === 'sent' && !isStackingTx(tx, poxInfo?.contract_id) ? '−' : '';
const memo =
tx.tx_type === 'token_transfer' &&
Buffer.from(
tx.token_transfer.memo.replace('0x', '').replace(/^(0{2})+|(0{2})+$/g, ''),
'hex'
).toString('utf8');
const memo = getMemoForTx(tx, direction);

const txDate = new Date(tx.burn_block_time_iso || (tx as any).parent_burn_block_time_iso);
const txDateShort = txDate.toLocaleString();

Expand Down
13 changes: 13 additions & 0 deletions app/utils/tx-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,16 @@ export const truncateMiddle = (input: string, offset = 5): string => {
return `${start}${end}`;
}
};

export const getMemoForTx = (tx: Transaction, direction: StxTxDirection) => {
if (tx.tx_type !== 'token_transfer' || direction !== 'sent') {
return undefined;
}

const utf8Memo = Buffer.from(
tx.token_transfer.memo.replace('0x', '').replace(/^(0{2})+|(0{2})+$/g, ''),
'hex'
).toString('utf8');

return utf8Memo;
};

0 comments on commit bbfeb04

Please sign in to comment.