Merge pull request #1376 from nymkappa/bugfix/blocks-list-pagination

Fix pagination on /mining/blocks
This commit is contained in:
wiz 2022-03-16 20:17:54 +00:00 committed by GitHub
commit 5bc1dfcfba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 7 deletions

View File

@ -350,15 +350,14 @@ class Blocks {
return prepareBlock(blockExtended);
}
public async $getBlocksExtras(fromHeight: number, limit: number = 15,
poolId: number | undefined= undefined): Promise<BlockExtended[]> {
public async $getBlocksExtras(fromHeight?: number, limit: number = 15): Promise<BlockExtended[]> {
// 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) {

View File

@ -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);
}

View File

@ -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) {