Skip to content

Commit

Permalink
fix(database-row-adapters.ts): modify sortAndFilterBlocks function to…
Browse files Browse the repository at this point in the history
… sort data by block height in descending order
  • Loading branch information
MartinMinkov committed Nov 20, 2023
1 parent 340cc54 commit da4b474
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/services/data-adapters/database-row-adapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,14 @@ function getFieldValuesFromElementIds(

function sortAndFilterBlocks<T extends { blockInfo: BlockInfo }>(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);
Expand Down

0 comments on commit da4b474

Please sign in to comment.