2023-07-20 16:26:42 +09:00
|
|
|
import { Component, OnInit, ChangeDetectionStrategy, Input, ChangeDetectorRef } from '@angular/core';
|
2024-02-26 15:54:10 +01:00
|
|
|
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';
|
2023-12-12 17:24:58 +01:00
|
|
|
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;
|
2024-02-26 15:54:10 +01:00
|
|
|
accelerationCount: number;
|
2023-07-20 16:26:42 +09:00
|
|
|
maxSize = window.innerWidth <= 767.98 ? 3 : 5;
|
|
|
|
skeletonLines: number[] = [];
|
2024-02-26 15:54:10 +01:00
|
|
|
pageSubject: BehaviorSubject<number> = new BehaviorSubject(this.page);
|
2023-07-20 16:26:42 +09:00
|
|
|
|
|
|
|
constructor(
|
2023-12-12 17:24:58 +01:00
|
|
|
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;
|
2024-02-26 15:54:10 +01:00
|
|
|
|
|
|
|
this.accelerationList$ = this.pageSubject.pipe(
|
|
|
|
switchMap((page) => {
|
|
|
|
const accelerationObservable$ = this.accelerations$ || (this.pending ? this.servicesApiService.getAccelerations$() : this.servicesApiService.getAccelerationHistoryObserveResponse$({ timeframe: '1m', page: page }));
|
|
|
|
return accelerationObservable$.pipe(
|
|
|
|
switchMap(response => {
|
|
|
|
const accelerations = response.body;
|
|
|
|
this.accelerationCount = parseInt(response.headers.get('x-total-count'), 10);
|
|
|
|
console.log(this.accelerationCount);
|
|
|
|
if (this.pending) {
|
|
|
|
for (const acceleration of accelerations) {
|
|
|
|
acceleration.status = acceleration.status || 'accelerating';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const acc of accelerations) {
|
|
|
|
acc.boost = 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
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-02-26 15:54:10 +01: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;
|
|
|
|
}
|
|
|
|
}
|