Skip to content

Commit f5c0aaa

Browse files
committed
Update explorer with changes to default offset
- Must send empty offset to grab the latest blocks. - Fixes an setTimeout issue that has plagued the front page and created more traffic and more handlers every time the explorer controller has been created.
1 parent 4a168da commit f5c0aaa

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/Blockcore.Explorer/ClientApp/src/app/explorer/blocks/blocks.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class BlocksComponent implements OnInit, OnDestroy {
4040

4141
async ngOnInit() {
4242
this.subscription = this.setup.currentChain$.subscribe(async (chain) => {
43-
await this.updateBlocks('/api/query/block?limit=' + this.limit);
43+
await this.updateBlocks('/api/query/block?offset=&limit=' + this.limit);
4444
});
4545
}
4646

src/Blockcore.Explorer/ClientApp/src/app/explorer/explorer.component.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class ExplorerComponent implements OnInit, OnDestroy {
2222
errorBlocks: string;
2323
errorInfo: string;
2424
subscription: any;
25+
killed: boolean;
2526

2627
constructor(private api: ApiService, public setup: SetupService) {
2728
this.subscription = this.setup.currentChain$.subscribe(async (chain) => {
@@ -37,18 +38,32 @@ export class ExplorerComponent implements OnInit, OnDestroy {
3738
}
3839

3940
ngOnDestroy(): void {
40-
clearTimeout(this.timerInfo);
41-
clearTimeout(this.timerBlocks);
41+
this.killed = true;
42+
43+
if (this.timerInfo) {
44+
clearTimeout(this.timerInfo);
45+
this.timerInfo = null;
46+
}
47+
48+
if (this.timerBlocks) {
49+
clearTimeout(this.timerBlocks);
50+
this.timerBlocks = null;
51+
}
52+
4253
this.subscription.unsubscribe();
4354
}
4455

4556
async updateBlocks() {
57+
if (this.killed) {
58+
return;
59+
}
60+
4661
if (this.setup.isCurrentRootChain) {
4762
return;
4863
}
4964

5065
try {
51-
const list = await this.api.getBlocks(0, 5);
66+
const list = await this.api.getBlocks('', 5);
5267

5368
// When the offset is not set (0), we should reverse the order of items.
5469
list.sort((b, a) => {
@@ -75,6 +90,10 @@ export class ExplorerComponent implements OnInit, OnDestroy {
7590
}
7691

7792
async updateInfo() {
93+
if (this.killed) {
94+
return;
95+
}
96+
7897
if (this.setup.isCurrentRootChain) {
7998
return;
8099
}

src/Blockcore.Explorer/ClientApp/src/app/services/api.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class ApiService {
104104
return this.downloadRelative('/query/block/latest');
105105
}
106106

107-
async getBlocks(offset: number, limit: number) {
107+
async getBlocks(offset: number | string, limit: number) {
108108
return this.downloadRelative('/query/block?offset=' + offset + '&limit=' + limit);
109109
}
110110

0 commit comments

Comments
 (0)