mirror of
https://github.com/mempool/mempool.git
synced 2024-12-28 01:04:28 +01:00
Refresh reward stats when a new block is mined
This commit is contained in:
parent
2644f2fb07
commit
8cc005cb2c
@ -1,7 +1,8 @@
|
|||||||
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
|
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map, skip, switchMap } from 'rxjs/operators';
|
||||||
import { ApiService } from 'src/app/services/api.service';
|
import { ApiService } from 'src/app/services/api.service';
|
||||||
|
import { StateService } from 'src/app/services/state.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-reward-stats',
|
selector: 'app-reward-stats',
|
||||||
@ -12,17 +13,24 @@ import { ApiService } from 'src/app/services/api.service';
|
|||||||
export class RewardStatsComponent implements OnInit {
|
export class RewardStatsComponent implements OnInit {
|
||||||
public $rewardStats: Observable<any>;
|
public $rewardStats: Observable<any>;
|
||||||
|
|
||||||
constructor(private apiService: ApiService) { }
|
constructor(private apiService: ApiService, private stateService: StateService) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.$rewardStats = this.apiService.getRewardStats$()
|
this.$rewardStats = this.stateService.blocks$
|
||||||
.pipe(
|
.pipe(
|
||||||
map((res) => {
|
// (we always receives some blocks at start so only trigger for the last one)
|
||||||
return {
|
skip(this.stateService.env.MEMPOOL_BLOCKS_AMOUNT - 1),
|
||||||
totalReward: res.totalReward,
|
switchMap(() => {
|
||||||
rewardPerTx: res.totalReward / res.totalTx,
|
return this.apiService.getRewardStats$()
|
||||||
feePerTx: res.totalFee / res.totalTx,
|
.pipe(
|
||||||
};
|
map((stats) => {
|
||||||
|
return {
|
||||||
|
totalReward: stats.totalReward,
|
||||||
|
rewardPerTx: stats.totalReward / stats.totalTx,
|
||||||
|
feePerTx: stats.totalFee / stats.totalTx,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user