From e434559df0461901e73632e7c8f1386f822368c3 Mon Sep 17 00:00:00 2001 From: Thibaut Sardan <33178835+Tbaut@users.noreply.github.com> Date: Thu, 17 Aug 2023 17:53:05 +0100 Subject: [PATCH] Change transaction's sorting order (#299) Co-authored-by: Anton Lykhoyda --- .../components/Transactions/TransactionList.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/ui/src/components/Transactions/TransactionList.tsx b/packages/ui/src/components/Transactions/TransactionList.tsx index 420e4a05..8ab56e34 100644 --- a/packages/ui/src/components/Transactions/TransactionList.tsx +++ b/packages/ui/src/components/Transactions/TransactionList.tsx @@ -29,6 +29,12 @@ export interface AggregatedData { type AggGroupedByDate = { [index: string]: AggregatedData[] } +const sortByLatest = (a: AggregatedData, b: AggregatedData) => { + if (!a.timestamp || !b.timestamp) return 0 + + return b.timestamp.valueOf() - a.timestamp.valueOf() +} + interface Props { className?: string } @@ -160,12 +166,8 @@ const TransactionList = ({ className }: Props) => { const filtered = res.filter((agg) => agg !== undefined) as AggregatedData[] const timestampObj: AggGroupedByDate = {} - // sort by date - const sorted = filtered.sort((a, b) => { - if (!a.timestamp || !b.timestamp) return 0 - - return a.timestamp.valueOf() - b.timestamp.valueOf() - }) + // sort by date, the newest first + const sorted = filtered.sort(sortByLatest) // populate the object sorted.forEach((data) => {