Skip to content

Commit

Permalink
fix(suite-native): pending transactions at the beginning of the list …
Browse files Browse the repository at this point in the history
…in one separate group as before
  • Loading branch information
matejkriz committed Jul 25, 2024
1 parent 3b0cb27 commit 4bd66f5
Showing 1 changed file with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@ const sectionListContainerStyle = prepareNativeStyle(utils => ({
paddingVertical: utils.spacings.small,
}));

const sortKeysPendingFirst = (a: string, b: string) => {
if (a === 'pending') return -1;
if (b === 'pending') return 1;

const dateA = new Date(a);
const dateB = new Date(b);

return dateA.getTime() - dateB.getTime();
};

const sortPendingTransactions = (a: WalletAccountTransaction, b: WalletAccountTransaction) => {
if (a.blockTime === undefined) return -1;
if (b.blockTime === undefined) return 1;

return a.blockTime - b.blockTime;
};

const renderTransactionItem = ({
item,
isFirst,
Expand Down Expand Up @@ -163,20 +180,22 @@ export const TransactionList = ({
}, [dispatch, accountKey, fetchTransactions]);

const data = useMemo((): TransactionListItem[] => {
// groupTransactionsByDate now sorts also pending transactions, if they have blockTime set
// this is a temporary solution to emulate the original behavior here in suite-native
// TODO: display pending transactions in the correct order
// groupTransactionsByDate now sorts also pending transactions, if they have blockTime set.
// This is here to keep the original behavior of having pending transactions in one group
// at the beginning of the list.
const [pendingTxs, confirmedTxs] = arrayPartition(transactions, isPending);
const accountTransactionsByMonth = groupTransactionsByDate(confirmedTxs, 'month');
if (pendingTxs.length || accountTransactionsByMonth['no-blocktime']) {
accountTransactionsByMonth['pending'] = [
...(accountTransactionsByMonth['no-blocktime'] ?? []),
...pendingTxs,
...pendingTxs.sort(sortPendingTransactions),
];
delete accountTransactionsByMonth['no-blocktime'];
}

const transactionMonthKeys = Object.keys(accountTransactionsByMonth) as MonthKey[];
const transactionMonthKeys = Object.keys(accountTransactionsByMonth).sort(
sortKeysPendingFirst,
) as MonthKey[];

if (tokenContract) {
return transactionMonthKeys.flatMap(monthKey => [
Expand Down

0 comments on commit 4bd66f5

Please sign in to comment.