mirror of
https://github.com/mempool/mempool.git
synced 2026-08-13 12:33:11 +02:00
Fix update accelerator dashboard stats in real time #6601
This commit is contained in:
parent
f3ef789d32
commit
574048eed5
1 changed files with 31 additions and 7 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { ChangeDetectionStrategy, Component, Input, OnChanges, OnInit } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { BehaviorSubject, EMPTY, Observable, merge, catchError, debounceTime, distinctUntilChanged, filter, switchMap, tap } from 'rxjs';
|
||||
import { ServicesApiServices } from '@app/services/services-api.service';
|
||||
import { StateService } from '@app/services/state.service';
|
||||
|
||||
export type AccelerationStats = {
|
||||
totalRequested: number;
|
||||
|
|
@ -21,21 +22,44 @@ export class AccelerationStatsComponent implements OnInit, OnChanges {
|
|||
@Input() timespan: '24h' | '1m' | '1y' | 'all' = '1y';
|
||||
accelerationStats$: Observable<AccelerationStats>;
|
||||
blocksInPeriod: number = 7 * 144;
|
||||
private timespan$ = new BehaviorSubject<'24h' | '1m' | '1y' | 'all'>(
|
||||
this.timespan
|
||||
);
|
||||
|
||||
constructor(
|
||||
private servicesApiService: ServicesApiServices
|
||||
) { }
|
||||
private servicesApiService: ServicesApiServices,
|
||||
private stateService: StateService
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.updateStats();
|
||||
const websocketRefresh$ = this.stateService.accelerations$.pipe(
|
||||
filter(
|
||||
(delta) =>
|
||||
!delta.reset && (!!delta.added.length || !!delta.removed.length)
|
||||
),
|
||||
debounceTime(2000)
|
||||
);
|
||||
|
||||
this.accelerationStats$ = merge(
|
||||
this.timespan$.pipe(tap(() => this.updateBlocksInPeriod())),
|
||||
websocketRefresh$,
|
||||
this.stateService.chainTip$.pipe(distinctUntilChanged())
|
||||
).pipe(
|
||||
switchMap(() =>
|
||||
this.servicesApiService
|
||||
.getAccelerationStats$({ timeframe: this.timespan })
|
||||
.pipe(
|
||||
catchError(() => EMPTY)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
ngOnChanges(): void {
|
||||
this.updateStats();
|
||||
this.timespan$.next(this.timespan);
|
||||
}
|
||||
|
||||
updateStats(): void {
|
||||
this.accelerationStats$ = this.servicesApiService.getAccelerationStats$({ timeframe: this.timespan });
|
||||
private updateBlocksInPeriod(): void {
|
||||
switch (this.timespan) {
|
||||
case '24h':
|
||||
this.blocksInPeriod = 144;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue