mirror of
https://github.com/mempool/mempool.git
synced 2024-12-28 17:24:25 +01:00
Merge pull request #1376 from nymkappa/bugfix/blocks-list-pagination
Fix pagination on /mining/blocks
This commit is contained in:
commit
5bc1dfcfba
@ -350,15 +350,14 @@ class Blocks {
|
|||||||
return prepareBlock(blockExtended);
|
return prepareBlock(blockExtended);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async $getBlocksExtras(fromHeight: number, limit: number = 15,
|
public async $getBlocksExtras(fromHeight?: number, limit: number = 15): Promise<BlockExtended[]> {
|
||||||
poolId: number | undefined= undefined): Promise<BlockExtended[]> {
|
|
||||||
// Note - This API is breaking if indexing is not available. For now it is okay because we only
|
// 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.
|
// 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
|
// I'll need to fix it before we refactor the block(s) related pages
|
||||||
try {
|
try {
|
||||||
loadingIndicators.setProgress('blocks', 0);
|
loadingIndicators.setProgress('blocks', 0);
|
||||||
|
|
||||||
let currentHeight = fromHeight ? fromHeight : this.getCurrentBlockHeight();
|
let currentHeight = fromHeight !== undefined ? fromHeight : this.getCurrentBlockHeight();
|
||||||
const returnBlocks: BlockExtended[] = [];
|
const returnBlocks: BlockExtended[] = [];
|
||||||
|
|
||||||
if (currentHeight < 0) {
|
if (currentHeight < 0) {
|
||||||
|
@ -659,7 +659,8 @@ class Routes {
|
|||||||
|
|
||||||
public async getBlocksExtras(req: Request, res: Response) {
|
public async getBlocksExtras(req: Request, res: Response) {
|
||||||
try {
|
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) {
|
} catch (e) {
|
||||||
res.status(500).send(e instanceof Error ? e.message : e);
|
res.status(500).send(e instanceof Error ? e.message : e);
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ export class BlocksList implements OnInit {
|
|||||||
.pipe(
|
.pipe(
|
||||||
tap(blocks => {
|
tap(blocks => {
|
||||||
if (this.blocksCount === undefined) {
|
if (this.blocksCount === undefined) {
|
||||||
this.blocksCount = blocks[0].height;
|
this.blocksCount = blocks[0].height + 1;
|
||||||
}
|
}
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
}),
|
}),
|
||||||
@ -77,7 +77,7 @@ export class BlocksList implements OnInit {
|
|||||||
this.lastPage = this.page;
|
this.lastPage = this.page;
|
||||||
return blocks[0];
|
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
|
// @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.logo = `./resources/mining-pools/` +
|
||||||
blocks[1][0].extras.pool.name.toLowerCase().replace(' ', '').replace('.', '') + '.svg';
|
blocks[1][0].extras.pool.name.toLowerCase().replace(' ', '').replace('.', '') + '.svg';
|
||||||
@ -89,7 +89,7 @@ export class BlocksList implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pageChange(page: number) {
|
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) {
|
trackByBlock(index: number, block: BlockExtended) {
|
||||||
|
Loading…
Reference in New Issue
Block a user