88 lines
3.1 KiB
TypeScript
Raw Normal View History

2023-07-20 16:26:42 +09:00
import { Component, OnInit, ChangeDetectionStrategy, Input, ChangeDetectorRef } from '@angular/core';
import { combineLatest, BehaviorSubject, Observable, catchError, of, switchMap, tap } from 'rxjs';
2023-12-07 08:26:32 +00:00
import { Acceleration, BlockExtended } from '../../../interfaces/node-api.interface';
import { StateService } from '../../../services/state.service';
import { WebsocketService } from '../../../services/websocket.service';
import { ServicesApiServices } from '../../../services/services-api.service';
2023-07-20 16:26:42 +09:00
@Component({
selector: 'app-accelerations-list',
templateUrl: './accelerations-list.component.html',
styleUrls: ['./accelerations-list.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AccelerationsListComponent implements OnInit {
@Input() widget: boolean = false;
2023-12-07 11:12:20 +00:00
@Input() pending: boolean = false;
2023-12-07 08:26:32 +00:00
@Input() accelerations$: Observable<Acceleration[]>;
2023-07-20 16:26:42 +09:00
2023-12-07 08:26:32 +00:00
accelerationList$: Observable<Acceleration[]> = undefined;
2023-07-20 16:26:42 +09:00
isLoading = true;
paginationMaxSize: number;
page = 1;
accelerationCount: number;
2023-07-20 16:26:42 +09:00
maxSize = window.innerWidth <= 767.98 ? 3 : 5;
skeletonLines: number[] = [];
pageSubject: BehaviorSubject<number> = new BehaviorSubject(this.page);
2023-07-20 16:26:42 +09:00
constructor(
private servicesApiService: ServicesApiServices,
2023-07-20 16:26:42 +09:00
private websocketService: WebsocketService,
public stateService: StateService,
private cd: ChangeDetectorRef,
) {
}
ngOnInit(): void {
if (!this.widget) {
this.websocketService.want(['blocks']);
}
this.skeletonLines = this.widget === true ? [...Array(6).keys()] : [...Array(15).keys()];
this.paginationMaxSize = window.matchMedia('(max-width: 670px)').matches ? 3 : 5;
this.accelerationList$ = this.pageSubject.pipe(
switchMap((page) => {
const accelerationObservable$ = this.accelerations$ || (this.pending ? this.servicesApiService.getAccelerations$() : this.servicesApiService.getAccelerationHistoryObserveResponse$({ page: page }));
return accelerationObservable$.pipe(
switchMap(response => {
let accelerations = response;
if (response.body) {
accelerations = response.body;
this.accelerationCount = parseInt(response.headers.get('x-total-count'), 10);
}
if (this.pending) {
for (const acceleration of accelerations) {
acceleration.status = acceleration.status || 'accelerating';
}
}
for (const acc of accelerations) {
2024-04-08 11:21:45 +00:00
acc.boost = acc.boostCost != null ? acc.boostCost : (acc.feePaid - acc.baseFee - acc.vsizeFee);
}
if (this.widget) {
return of(accelerations.slice(0, 6));
} else {
return of(accelerations);
}
}),
catchError((err) => {
this.isLoading = false;
return of([]);
}),
tap(() => {
this.isLoading = false;
})
);
2023-07-20 16:26:42 +09:00
})
);
}
pageChange(page: number): void {
this.pageSubject.next(page);
}
2023-07-20 16:26:42 +09:00
trackByBlock(index: number, block: BlockExtended): number {
return block.height;
}
}