Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix swaps tx history #557

Merged
merged 5 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/app/components/transactions/stxTransaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ import StxTransferTransaction from './stxTransferTransaction';
interface TransactionHistoryItemProps {
transaction: AddressTransactionWithTransfers | Tx;
transactionCoin: CurrencyTypes;
txFilter: string | null;
}

export default function StxTransactionHistoryItem(props: TransactionHistoryItemProps) {
const { transaction, transactionCoin } = props;
const { transaction, transactionCoin, txFilter } = props;
const { selectedAccount } = useWalletSelector();
// const { t } = useTranslation('translation', { keyPrefix: 'COIN_DASHBOARD_SCREEN' });
if (!isAddressTransactionWithTransfers(transaction)) {
Expand Down Expand Up @@ -68,7 +69,7 @@ export default function StxTransactionHistoryItem(props: TransactionHistoryItemP
}
return (
<>
<TxTransfers transaction={transaction} coin={transactionCoin} />
<TxTransfers transaction={transaction} coin={transactionCoin} txFilter={txFilter} />
<StxTransferTransaction
transaction={parseStxTransactionData({
responseTx: transaction.tx,
Expand Down
76 changes: 55 additions & 21 deletions src/app/components/transactions/txTransfers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ const TransactionValue = styled.p((props) => ({
interface TxTransfersProps {
transaction: AddressTransactionWithTransfers;
coin: CurrencyTypes;
txFilter: string | null;
}

export default function TxTransfers(props: TxTransfersProps) {
const { transaction, coin } = props;
const { transaction, coin, txFilter } = props;
const { selectedAccount } = useWalletSelector();
const { t } = useTranslation('translation', { keyPrefix: 'COIN_DASHBOARD_SCREEN' });

Expand All @@ -75,26 +76,59 @@ export default function TxTransfers(props: TxTransfersProps) {
: t('TRANSACTION_SENT');
return (
<>
{transaction.stx_transfers.map((stxTransfer) => (
<TransactionContainer key={nanoid()}>
{renderTransactionIcon(stxTransfer)}
<TransactionInfoContainer>
<TransactionRow>
<TransactionTitleText>{getTokenTransferTitle(stxTransfer)}</TransactionTitleText>
<NumericFormat
value={microstacksToStx(BigNumber(stxTransfer.amount)).toString()}
displayType="text"
thousandSeparator
prefix={selectedAccount?.stxAddress === stxTransfer.recipient ? '' : '-'}
renderText={(value: string) => (
<TransactionValue>{`${value} ${coin}`}</TransactionValue>
)}
/>
</TransactionRow>
<RecipientAddress>{formatAddress(stxTransfer.recipient as string)}</RecipientAddress>
</TransactionInfoContainer>
</TransactionContainer>
))}
{coin === 'FT' && transaction.ft_transfers
? transaction.ft_transfers.map((ftTransfer) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lint error here

if (ftTransfer.asset_identifier === txFilter) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not filter on the list instead, like ft_transfers.filter().map()

return (
<TransactionContainer key={nanoid()}>
{renderTransactionIcon(ftTransfer)}
<TransactionInfoContainer>
<TransactionRow>
<TransactionTitleText>
{getTokenTransferTitle(ftTransfer)}
</TransactionTitleText>
<NumericFormat
value={microstacksToStx(BigNumber(ftTransfer.amount)).toString()}
displayType="text"
thousandSeparator
prefix={selectedAccount?.stxAddress === ftTransfer.recipient ? '' : '-'}
renderText={(value: string) => (
<TransactionValue>{`${value} ${ftTransfer.asset_identifier
.split('::')[1]
.toUpperCase()}`}</TransactionValue>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to get the ticker here instead?, e.g. MIAMICOIN should be MIA:
image

)}
/>
</TransactionRow>
<RecipientAddress>
{formatAddress(ftTransfer.recipient as string)}
</RecipientAddress>
</TransactionInfoContainer>
</TransactionContainer>
);
}
})
: transaction.stx_transfers.map((stxTransfer) => (
<TransactionContainer key={nanoid()}>
{renderTransactionIcon(stxTransfer)}
<TransactionInfoContainer>
<TransactionRow>
<TransactionTitleText>{getTokenTransferTitle(stxTransfer)}</TransactionTitleText>
<NumericFormat
value={microstacksToStx(BigNumber(stxTransfer.amount)).toString()}
displayType="text"
thousandSeparator
prefix={selectedAccount?.stxAddress === stxTransfer.recipient ? '' : '-'}
renderText={(value: string) => (
<TransactionValue>{`${value} ${coin}`}</TransactionValue>
)}
/>
</TransactionRow>
<RecipientAddress>
{formatAddress(stxTransfer.recipient as string)}
</RecipientAddress>
</TransactionInfoContainer>
</TransactionContainer>
))}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a lot of duplicated code. could you DRY it up? it looks like only the NumericFormat props change depending on whether it's a stxTransfer or ftTransfer

</>
);
}
1 change: 1 addition & 0 deletions src/app/screens/coinDashboard/transactionsHistoryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export default function TransactionsHistoryList(props: TransactionsHistoryListPr
transaction={transaction}
transactionCoin={coin}
key={transaction.tx_id}
txFilter={txFilter}
/>
);
})}
Expand Down