2023-07-20 16:26:42 +09:00
|
|
|
import { Component, OnInit, ChangeDetectionStrategy, Input, ChangeDetectorRef } from '@angular/core';
|
2023-12-07 08:26:32 +00:00
|
|
|
import { Observable, catchError, of, switchMap, tap } from 'rxjs';
|
|
|
|
import { Acceleration, BlockExtended } from '../../../interfaces/node-api.interface';
|
|
|
|
import { ApiService } from '../../../services/api.service';
|
|
|
|
import { StateService } from '../../../services/state.service';
|
|
|
|
import { WebsocketService } from '../../../services/websocket.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;
|
|
|
|
lastPage = 1;
|
|
|
|
maxSize = window.innerWidth <= 767.98 ? 3 : 5;
|
|
|
|
skeletonLines: number[] = [];
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private apiService: ApiService,
|
|
|
|
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;
|
|
|
|
|
2023-12-07 11:12:20 +00:00
|
|
|
const accelerationObservable$ = this.accelerations$ || (this.pending ? this.apiService.getAccelerations$() : this.apiService.getAccelerationHistory$({ timeframe: '1m' }));
|
|
|
|
this.accelerationList$ = accelerationObservable$.pipe(
|
2023-07-21 14:13:18 +09:00
|
|
|
switchMap(accelerations => {
|
2023-12-07 11:12:20 +00:00
|
|
|
if (this.pending) {
|
|
|
|
for (const acceleration of accelerations) {
|
|
|
|
acceleration.status = acceleration.status || 'accelerating';
|
|
|
|
}
|
|
|
|
}
|
2023-07-21 14:13:18 +09:00
|
|
|
if (this.widget) {
|
2023-08-30 22:24:27 +09:00
|
|
|
return of(accelerations.slice(-6).reverse());
|
2023-07-21 14:13:18 +09:00
|
|
|
} else {
|
2023-08-30 22:24:27 +09:00
|
|
|
return of(accelerations.reverse());
|
2023-07-21 14:13:18 +09:00
|
|
|
}
|
|
|
|
}),
|
2023-07-20 16:26:42 +09:00
|
|
|
catchError((err) => {
|
|
|
|
this.isLoading = false;
|
|
|
|
return of([]);
|
2023-12-07 08:26:32 +00:00
|
|
|
}),
|
|
|
|
tap(() => {
|
|
|
|
this.isLoading = false;
|
2023-07-20 16:26:42 +09:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
trackByBlock(index: number, block: BlockExtended): number {
|
|
|
|
return block.height;
|
|
|
|
}
|
|
|
|
}
|