wallet-core: order transactions by descending timestamp

This commit is contained in:
Florian Dold 2023-10-10 12:14:09 +02:00
parent 4e11051d9f
commit adda4f8ce3
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B

View File

@ -1291,10 +1291,12 @@ export async function getTransactions(
const txNotPending = transactions.filter((x) => !isPending(x)); const txNotPending = transactions.filter((x) => !isPending(x));
const txCmp = (h1: Transaction, h2: Transaction) => { const txCmp = (h1: Transaction, h2: Transaction) => {
const tsCmp = AbsoluteTime.cmp( // Order transactions by timestamp. Newest transactions come first.
const tsCmp = -AbsoluteTime.cmp(
AbsoluteTime.fromPreciseTimestamp(h1.timestamp), AbsoluteTime.fromPreciseTimestamp(h1.timestamp),
AbsoluteTime.fromPreciseTimestamp(h2.timestamp), AbsoluteTime.fromPreciseTimestamp(h2.timestamp),
); );
// If the timestamp is exactly the same, order by transaction type.
if (tsCmp === 0) { if (tsCmp === 0) {
return Math.sign(txOrder[h1.type] - txOrder[h2.type]); return Math.sign(txOrder[h1.type] - txOrder[h2.type]);
} }