2022-03-07 11:22:54 +01:00
|
|
|
import { ChangeDetectionStrategy, Component, Inject, LOCALE_ID, OnDestroy, OnInit } from '@angular/core';
|
|
|
|
import { map } from 'rxjs/operators';
|
2022-02-24 20:20:18 +09:00
|
|
|
import { SeoService } from 'src/app/services/seo.service';
|
2022-03-07 11:22:54 +01:00
|
|
|
import { StateService } from 'src/app/services/state.service';
|
|
|
|
import { Observable } from 'rxjs';
|
2022-02-16 17:32:12 +09:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-mining-dashboard',
|
|
|
|
templateUrl: './mining-dashboard.component.html',
|
2022-02-17 17:10:20 +09:00
|
|
|
styleUrls: ['./mining-dashboard.component.scss'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
2022-02-16 17:32:12 +09:00
|
|
|
})
|
|
|
|
export class MiningDashboardComponent implements OnInit {
|
2022-03-07 11:22:54 +01:00
|
|
|
private blocks = [];
|
2022-02-16 17:32:12 +09:00
|
|
|
|
2022-03-07 11:22:54 +01:00
|
|
|
public $rewardStats: Observable<any>;
|
|
|
|
public totalReward = 0;
|
|
|
|
public rewardPerTx = '~';
|
|
|
|
public feePerTx = '~';
|
|
|
|
|
|
|
|
constructor(private seoService: SeoService,
|
|
|
|
public stateService: StateService,
|
|
|
|
@Inject(LOCALE_ID) private locale: string,
|
|
|
|
) {
|
2022-02-24 20:20:18 +09:00
|
|
|
this.seoService.setTitle($localize`:@@mining.mining-dashboard:Mining Dashboard`);
|
|
|
|
}
|
2022-02-16 17:32:12 +09:00
|
|
|
|
|
|
|
ngOnInit(): void {
|
2022-03-07 11:22:54 +01:00
|
|
|
this.$rewardStats = this.stateService.blocks$.pipe(
|
|
|
|
map(([block]) => {
|
2022-03-07 17:16:26 +01:00
|
|
|
this.blocks.unshift(block);
|
2022-03-07 11:22:54 +01:00
|
|
|
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);
|
2022-02-16 17:32:12 +09:00
|
|
|
|
2022-03-07 11:22:54 +01:00
|
|
|
return {
|
|
|
|
'totalReward': totalReward,
|
2022-03-07 18:19:02 +01:00
|
|
|
'rewardPerTx': totalReward / totalTx,
|
|
|
|
'feePerTx': totalFee / totalTx,
|
2022-03-07 11:22:54 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2022-02-16 17:32:12 +09:00
|
|
|
}
|