Move reward stats to component - Add /api/v1/mining/reward-stats/{blockCount}
This commit is contained in:
@@ -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),
|
||||
};
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user