2022-03-22 12:34:29 +09:00
|
|
|
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
|
|
|
|
import { Observable } from 'rxjs';
|
2022-03-22 18:07:26 +09:00
|
|
|
import { map, skip, switchMap } from 'rxjs/operators';
|
2022-03-22 12:34:29 +09:00
|
|
|
import { ApiService } from 'src/app/services/api.service';
|
2022-03-22 18:07:26 +09:00
|
|
|
import { StateService } from 'src/app/services/state.service';
|
2022-03-22 12:34:29 +09:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-reward-stats',
|
|
|
|
templateUrl: './reward-stats.component.html',
|
|
|
|
styleUrls: ['./reward-stats.component.scss'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
|
|
})
|
|
|
|
export class RewardStatsComponent implements OnInit {
|
|
|
|
public $rewardStats: Observable<any>;
|
|
|
|
|
2022-03-22 18:07:26 +09:00
|
|
|
constructor(private apiService: ApiService, private stateService: StateService) { }
|
2022-03-22 12:34:29 +09:00
|
|
|
|
|
|
|
ngOnInit(): void {
|
2022-03-22 18:07:26 +09:00
|
|
|
this.$rewardStats = this.stateService.blocks$
|
2022-03-22 12:34:29 +09:00
|
|
|
.pipe(
|
2022-03-22 18:07:26 +09:00
|
|
|
// (we always receives some blocks at start so only trigger for the last one)
|
|
|
|
skip(this.stateService.env.MEMPOOL_BLOCKS_AMOUNT - 1),
|
|
|
|
switchMap(() => {
|
|
|
|
return this.apiService.getRewardStats$()
|
|
|
|
.pipe(
|
|
|
|
map((stats) => {
|
|
|
|
return {
|
|
|
|
totalReward: stats.totalReward,
|
|
|
|
rewardPerTx: stats.totalReward / stats.totalTx,
|
|
|
|
feePerTx: stats.totalFee / stats.totalTx,
|
|
|
|
};
|
|
|
|
})
|
|
|
|
);
|
2022-03-22 12:34:29 +09:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|