From 9252a45971f23ed5efd63f082db5ad7166ccb8ed Mon Sep 17 00:00:00 2001 From: nymkappa Date: Tue, 15 Mar 2022 23:49:20 +0100 Subject: [PATCH] Fix pagination on /mining/blocks --- backend/src/api/blocks.ts | 5 ++--- backend/src/routes.ts | 3 ++- .../src/app/components/blocks-list/blocks-list.component.ts | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index b32a1689e..bff73dd54 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -350,15 +350,14 @@ class Blocks { return prepareBlock(blockExtended); } - public async $getBlocksExtras(fromHeight: number, limit: number = 15, - poolId: number | undefined= undefined): Promise { + public async $getBlocksExtras(fromHeight?: number, limit: number = 15): Promise { // Note - This API is breaking if indexing is not available. For now it is okay because we only // use it for the mining pages, and mining pages should not be available if indexing is turned off. // I'll need to fix it before we refactor the block(s) related pages try { loadingIndicators.setProgress('blocks', 0); - let currentHeight = fromHeight ? fromHeight : this.getCurrentBlockHeight(); + let currentHeight = fromHeight !== undefined ? fromHeight : this.getCurrentBlockHeight(); const returnBlocks: BlockExtended[] = []; if (currentHeight < 0) { diff --git a/backend/src/routes.ts b/backend/src/routes.ts index 870c62ab8..2f4cdff3a 100644 --- a/backend/src/routes.ts +++ b/backend/src/routes.ts @@ -659,7 +659,8 @@ class Routes { public async getBlocksExtras(req: Request, res: Response) { try { - res.json(await blocks.$getBlocksExtras(parseInt(req.params.height, 10), 15)); + const height = req.params.height === undefined ? undefined : parseInt(req.params.height, 10); + res.json(await blocks.$getBlocksExtras(height, 15)); } catch (e) { res.status(500).send(e instanceof Error ? e.message : e); } diff --git a/frontend/src/app/components/blocks-list/blocks-list.component.ts b/frontend/src/app/components/blocks-list/blocks-list.component.ts index 72727b734..ade191f7a 100644 --- a/frontend/src/app/components/blocks-list/blocks-list.component.ts +++ b/frontend/src/app/components/blocks-list/blocks-list.component.ts @@ -47,7 +47,7 @@ export class BlocksList implements OnInit { .pipe( tap(blocks => { if (this.blocksCount === undefined) { - this.blocksCount = blocks[0].height; + this.blocksCount = blocks[0].height + 1; } this.isLoading = false; }), @@ -77,7 +77,7 @@ export class BlocksList implements OnInit { this.lastPage = this.page; return blocks[0]; } - this.blocksCount = Math.max(this.blocksCount, blocks[1][0].height); + this.blocksCount = Math.max(this.blocksCount, blocks[1][0].height) + 1; // @ts-ignore: Need to add an extra field for the template blocks[1][0].extras.pool.logo = `./resources/mining-pools/` + blocks[1][0].extras.pool.name.toLowerCase().replace(' ', '').replace('.', '') + '.svg'; @@ -89,7 +89,7 @@ export class BlocksList implements OnInit { } pageChange(page: number) { - this.fromHeightSubject.next(this.blocksCount - (page - 1) * 15); + this.fromHeightSubject.next((this.blocksCount - 1) - (page - 1) * 15); } trackByBlock(index: number, block: BlockExtended) {