Skip to content

Commit

Permalink
Change transaction's sorting order (#299)
Browse files Browse the repository at this point in the history
Co-authored-by: Anton Lykhoyda <[email protected]>
  • Loading branch information
Tbaut and Lykhoyda authored Aug 17, 2023
1 parent 4409ad8 commit e434559
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/ui/src/components/Transactions/TransactionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit e434559

Please sign in to comment.