Fix blockchain gaps when KEEP_BLOCKS_AMOUNT > INITIAL_BLOCKS_AMOUNT

This commit is contained in:
Mononaut
2023-01-27 18:32:15 -06:00
parent 22cd20bef2
commit 92352e1453
2 changed files with 21 additions and 6 deletions

View File

@@ -22,10 +22,13 @@ export class StartComponent implements OnInit, OnDestroy {
chainTipSubscription: Subscription;
chainTip: number = -1;
markBlockSubscription: Subscription;
blockCounterSubscription: Subscription;
@ViewChild('blockchainContainer') blockchainContainer: ElementRef;
isMobile: boolean = false;
blockWidth = 155;
dynamicBlocksAmount: number = 8;
blockCount: number = 0;
blocksPerPage: number = 1;
pageWidth: number;
firstPageWidth: number;
@@ -39,7 +42,15 @@ export class StartComponent implements OnInit, OnDestroy {
) { }
ngOnInit() {
this.firstPageWidth = 40 + (this.blockWidth * this.stateService.env.KEEP_BLOCKS_AMOUNT);
this.firstPageWidth = 40 + (this.blockWidth * this.dynamicBlocksAmount);
this.blockCounterSubscription = this.stateService.blocks$.subscribe(() => {
this.blockCount++;
this.dynamicBlocksAmount = Math.min(this.blockCount, this.stateService.env.KEEP_BLOCKS_AMOUNT, 8);
this.firstPageWidth = 40 + (this.blockWidth * this.dynamicBlocksAmount);
if (this.blockCount <= Math.min(8, this.stateService.env.KEEP_BLOCKS_AMOUNT)) {
this.onResize();
}
});
this.onResize();
this.updatePages();
this.timeLtrSubscription = this.stateService.timeLtr.subscribe((ltr) => {
@@ -241,7 +252,7 @@ export class StartComponent implements OnInit, OnDestroy {
}
getPageAt(index: number) {
const height = this.chainTip - 8 - ((index - 1) * this.blocksPerPage)
const height = this.chainTip - this.dynamicBlocksAmount - ((index - 1) * this.blocksPerPage);
return {
offset: this.firstPageWidth + (this.pageWidth * (index - 1 - this.pageIndex)),
height: height,
@@ -255,7 +266,7 @@ export class StartComponent implements OnInit, OnDestroy {
}
getPageIndexOf(height: number): number {
const delta = this.chainTip - 8 - height;
const delta = this.chainTip - this.dynamicBlocksAmount - height;
return Math.max(0, Math.floor(delta / this.blocksPerPage) + 1);
}
@@ -290,5 +301,6 @@ export class StartComponent implements OnInit, OnDestroy {
this.timeLtrSubscription.unsubscribe();
this.chainTipSubscription.unsubscribe();
this.markBlockSubscription.unsubscribe();
this.blockCounterSubscription.unsubscribe();
}
}