Move reward stats to component - Add /api/v1/mining/reward-stats/{blockCount}

This commit is contained in:
nymkappa
2022-03-22 12:34:29 +09:00
parent 5c629dfe98
commit 2644f2fb07
15 changed files with 202 additions and 110 deletions

View File

@@ -14,14 +14,8 @@ import { WebsocketService } from 'src/app/services/websocket.service';
export class MiningDashboardComponent implements OnInit {
private blocks = [];
public $rewardStats: Observable<any>;
public totalReward = 0;
public rewardPerTx = '~';
public feePerTx = '~';
constructor(
private seoService: SeoService,
public stateService: StateService,
private websocketService: WebsocketService,
) {
this.seoService.setTitle($localize`:@@mining.mining-dashboard:Mining Dashboard`);
@@ -29,21 +23,5 @@ export class MiningDashboardComponent implements OnInit {
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, 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),
};
})
);
}
}