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