mirror of
https://github.com/mempool/mempool.git
synced 2025-02-22 22:25:34 +01:00
Fix fees vs subsidy graph when blocks are not fully indexed
This commit is contained in:
parent
6d595dcdb6
commit
d0cba30543
2 changed files with 41 additions and 20 deletions
|
@ -9,16 +9,18 @@
|
|||
</button>
|
||||
</div>
|
||||
|
||||
<div class="formRadioGroup" ngbDropdown *ngIf="(statsObservable$ | async) as stats">
|
||||
<button class="btn btn-primary btn-sm dropdown-toggle" id="endBlockDropdown" ngbDropdownToggle>
|
||||
{{ endBlockToSelector(radioGroupForm.get('endBlock').value) }}
|
||||
</button>
|
||||
<div ngbDropdownMenu class="scrollable-dropdown">
|
||||
<button [ngClass]="{'selected': option === endBlock}" class="dropdown-item" *ngFor="let option of dropdownOptions" (click)="selectBlockSpan(option)">
|
||||
{{ endBlockToSelector(option) }}
|
||||
<ng-container *ngIf="(statsObservable$ | async) as stats">
|
||||
<div class="formRadioGroup" ngbDropdown *ngIf="stats.indexedBlocksInterval.end !== -1">
|
||||
<button class="btn btn-primary btn-sm dropdown-toggle" id="endBlockDropdown" ngbDropdownToggle>
|
||||
Blocks {{ lowerBound }} - {{ upperBound }}
|
||||
</button>
|
||||
<div ngbDropdownMenu class="scrollable-dropdown">
|
||||
<button [ngClass]="{'selected': option === endBlock}" class="dropdown-item" *ngFor="let option of dropdownOptions" (click)="selectBlockSpan(option)">
|
||||
{{ endBlockToSelector(option) }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
</div>
|
||||
|
||||
<div class="chart" *browserOnly echarts [initOpts]="chartInitOptions" [options]="chartOptions"
|
||||
|
|
|
@ -41,7 +41,9 @@ export class BlockFeesSubsidyGraphComponent implements OnInit {
|
|||
isLoading = true;
|
||||
formatNumber = formatNumber;
|
||||
endBlock = '';
|
||||
blockCount = 0;
|
||||
indexedBlocksInterval = { start: 0, end: 0 };
|
||||
lowerBound = 0;
|
||||
upperBound = 0;
|
||||
chartInstance: any = undefined;
|
||||
showFiat = false;
|
||||
dropdownOptions = [];
|
||||
|
@ -84,6 +86,10 @@ export class BlockFeesSubsidyGraphComponent implements OnInit {
|
|||
return this.apiService.getHistoricalExactBlockFees$(endBlock === '' ? undefined : endBlock)
|
||||
.pipe(
|
||||
tap((response) => {
|
||||
if (response.body.length === 0) {
|
||||
this.isLoading = false;
|
||||
return;
|
||||
}
|
||||
let blockReward = 50 * 100_000_000;
|
||||
const subsidies = {};
|
||||
for (let i = 0; i <= 33; i++) {
|
||||
|
@ -121,18 +127,25 @@ export class BlockFeesSubsidyGraphComponent implements OnInit {
|
|||
this.isLoading = false;
|
||||
}),
|
||||
map((response) => {
|
||||
this.blockCount = parseInt(response.headers.get('x-total-count'), 10);
|
||||
if (this.radioGroupForm.controls.endBlock.value === '') this.radioGroupForm.controls.endBlock.setValue((this.blockCount - 1).toString(), { emitEvent: false });
|
||||
this.dropdownOptions = [(this.blockCount - 1).toString()];
|
||||
if (this.blockCount) {
|
||||
let i = this.blockCount - 1 - this.step;
|
||||
while (i >= 0) {
|
||||
this.dropdownOptions.push(i.toString());
|
||||
i -= this.step;
|
||||
const blockCount = parseInt(response.headers.get('x-total-count'), 10);
|
||||
const chainTip = this.stateService.latestBlockHeight;
|
||||
|
||||
this.indexedBlocksInterval = {
|
||||
start: chainTip - blockCount,
|
||||
end: chainTip,
|
||||
};
|
||||
|
||||
if (this.radioGroupForm.controls.endBlock.value === '') this.radioGroupForm.controls.endBlock.setValue((this.indexedBlocksInterval.end).toString(), { emitEvent: false });
|
||||
this.dropdownOptions = [(this.indexedBlocksInterval.end).toString()];
|
||||
if (this.indexedBlocksInterval.end - this.step > this.indexedBlocksInterval.start) {
|
||||
let newEndBlock = this.indexedBlocksInterval.end - this.step;
|
||||
while (newEndBlock > this.indexedBlocksInterval.start) {
|
||||
this.dropdownOptions.push(newEndBlock.toString());
|
||||
newEndBlock -= this.step;
|
||||
}
|
||||
}
|
||||
return {
|
||||
blockCount: this.blockCount,
|
||||
indexedBlocksInterval: this.indexedBlocksInterval,
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
@ -155,6 +168,9 @@ export class BlockFeesSubsidyGraphComponent implements OnInit {
|
|||
};
|
||||
}
|
||||
|
||||
this.lowerBound = data.blockHeight[0];
|
||||
this.upperBound = data.blockHeight[data.blockHeight.length - 1];
|
||||
|
||||
this.chartOptions = {
|
||||
title: title,
|
||||
color: [
|
||||
|
@ -426,7 +442,10 @@ export class BlockFeesSubsidyGraphComponent implements OnInit {
|
|||
}
|
||||
|
||||
endBlockToSelector(value: string): string {
|
||||
if (parseInt(value, 10) > this.blockCount) value = (this.blockCount).toString();
|
||||
return `Blocks ${Math.max(0, parseInt(value, 10) - this.step)} - ` + value;
|
||||
let upperBound = Math.min(this.indexedBlocksInterval.end, parseInt(value, 10));
|
||||
let lowerBound = Math.max(0, parseInt(value, 10) - this.step);
|
||||
if (lowerBound < this.indexedBlocksInterval.start) lowerBound = this.indexedBlocksInterval.start + 1;
|
||||
if (lowerBound > upperBound) lowerBound = upperBound;
|
||||
return `Blocks ${lowerBound} - ${upperBound}`;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue