From da4b4741495ab439b0a91cd9574157094d08541e Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Mon, 20 Nov 2023 12:12:02 -0800 Subject: [PATCH] fix(database-row-adapters.ts): modify sortAndFilterBlocks function to sort data by block height in descending order --- src/services/data-adapters/database-row-adapters.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/services/data-adapters/database-row-adapters.ts b/src/services/data-adapters/database-row-adapters.ts index eaab350..e8c74a0 100644 --- a/src/services/data-adapters/database-row-adapters.ts +++ b/src/services/data-adapters/database-row-adapters.ts @@ -237,10 +237,14 @@ function getFieldValuesFromElementIds( function sortAndFilterBlocks(data: T[]) { data.sort((a, b) => { - if (a.blockInfo.height < b.blockInfo.height) return -1; - if (a.blockInfo.height > b.blockInfo.height) return 1; + // Sort by height in descending order + if (a.blockInfo.height > b.blockInfo.height) return -1; + if (a.blockInfo.height < b.blockInfo.height) return 1; + + // If heights are equal, sort by timestamp (assuming ascending order) if (a.blockInfo.timestamp < b.blockInfo.timestamp) return -1; if (a.blockInfo.timestamp > b.blockInfo.timestamp) return 1; + return 0; }); filterBestTip(data);