Subscribe to blocks and mempool updates in the mining dashboard

fixes #1414
This commit is contained in:
softsimon 2022-03-19 23:32:01 +04:00
parent 91d55e02d6
commit 4f441d3f30
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7
2 changed files with 14 additions and 9 deletions

View File

@ -34,7 +34,9 @@ export class BlocksList implements OnInit {
}
ngOnInit(): void {
this.websocketService.want(['blocks']);
if (!this.widget) {
this.websocketService.want(['blocks']);
}
this.skeletonLines = this.widget === true ? [...Array(5).keys()] : [...Array(15).keys()];
this.paginationMaxSize = window.matchMedia('(max-width: 670px)').matches ? 3 : 5;

View File

@ -1,9 +1,9 @@
import { ChangeDetectionStrategy, Component, Inject, LOCALE_ID, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { map } from 'rxjs/operators';
import { SeoService } from 'src/app/services/seo.service';
import { StateService } from 'src/app/services/state.service';
import { formatNumber } from '@angular/common';
import { Observable } from 'rxjs';
import { WebsocketService } from 'src/app/services/websocket.service';
@Component({
selector: 'app-mining-dashboard',
@ -19,27 +19,30 @@ export class MiningDashboardComponent implements OnInit {
public rewardPerTx = '~';
public feePerTx = '~';
constructor(private seoService: SeoService,
constructor(
private seoService: SeoService,
public stateService: StateService,
@Inject(LOCALE_ID) private locale: string,
private websocketService: WebsocketService,
) {
this.seoService.setTitle($localize`:@@mining.mining-dashboard:Mining Dashboard`);
}
ngOnInit(): void {
this.websocketService.want(['blocks', 'mempool-blocks']);
this.$rewardStats = this.stateService.blocks$.pipe(
map(([block]) => {
this.blocks.unshift(block);
this.blocks = this.blocks.slice(0, 8);
const totalTx = this.blocks.reduce((acc, block) => acc + block.tx_count, 0);
const totalFee = this.blocks.reduce((acc, block) => acc + block.extras?.totalFees ?? 0, 0);
const totalReward = this.blocks.reduce((acc, block) => acc + block.extras?.reward ?? 0, 0);
const totalTx = this.blocks.reduce((acc, b) => acc + b.tx_count, 0);
const totalFee = this.blocks.reduce((acc, b) => acc + b.extras?.totalFees ?? 0, 0);
const totalReward = this.blocks.reduce((acc, b) => acc + b.extras?.reward ?? 0, 0);
return {
'totalReward': totalReward,
'rewardPerTx': Math.round(totalReward / totalTx),
'feePerTx': Math.round(totalFee / totalTx),
}
};
})
);
}