2024-06-26 15:37:39 +09:00
|
|
|
import { Component, OnInit, ChangeDetectionStrategy, Input, ChangeDetectorRef, OnDestroy, Inject, LOCALE_ID } from '@angular/core';
|
2024-07-02 21:42:11 +09:00
|
|
|
import { BehaviorSubject, Observable, Subscription, catchError, filter, of, switchMap, tap, throttleTime } from 'rxjs';
|
2024-07-23 18:51:30 +02:00
|
|
|
import { Acceleration, BlockExtended, SinglePoolStats } from '../../../interfaces/node-api.interface';
|
2023-12-07 08:26:32 +00:00
|
|
|
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';
|
2024-06-26 11:42:22 +09:00
|
|
|
import { SeoService } from '../../../services/seo.service';
|
2024-06-26 15:37:39 +09:00
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
2024-07-23 18:51:30 +02:00
|
|
|
import { MiningService } from '../../../services/mining.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,
|
|
|
|
})
|
2024-05-04 00:18:33 +00:00
|
|
|
export class AccelerationsListComponent implements OnInit, OnDestroy {
|
2023-07-20 16:26:42 +09:00
|
|
|
@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);
|
2024-06-26 15:37:39 +09:00
|
|
|
keyNavigationSubscription: Subscription;
|
|
|
|
dir: 'rtl' | 'ltr' = 'ltr';
|
|
|
|
paramSubscription: Subscription;
|
2024-07-23 18:51:30 +02:00
|
|
|
pools: { [id: number]: SinglePoolStats } = {};
|
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,
|
2024-07-23 18:51:30 +02:00
|
|
|
private miningService: MiningService,
|
2023-07-20 16:26:42 +09:00
|
|
|
private cd: ChangeDetectorRef,
|
2024-06-26 11:42:22 +09:00
|
|
|
private seoService: SeoService,
|
2024-06-26 15:37:39 +09:00
|
|
|
private route: ActivatedRoute,
|
|
|
|
private router: Router,
|
|
|
|
@Inject(LOCALE_ID) private locale: string,
|
2023-07-20 16:26:42 +09:00
|
|
|
) {
|
2024-06-26 15:37:39 +09:00
|
|
|
if (this.locale.startsWith('ar') || this.locale.startsWith('fa') || this.locale.startsWith('he')) {
|
|
|
|
this.dir = 'rtl';
|
|
|
|
}
|
2023-07-20 16:26:42 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
if (!this.widget) {
|
|
|
|
this.websocketService.want(['blocks']);
|
2024-06-26 11:42:22 +09:00
|
|
|
this.seoService.setTitle($localize`:@@02573b6980a2d611b4361a2595a4447e390058cd:Accelerations`);
|
2024-07-02 15:04:54 +09:00
|
|
|
|
|
|
|
this.paramSubscription = this.route.params.pipe(
|
|
|
|
tap(params => {
|
|
|
|
this.page = +params['page'] || 1;
|
|
|
|
this.pageSubject.next(this.page);
|
|
|
|
})
|
|
|
|
).subscribe();
|
|
|
|
|
2024-07-02 21:42:11 +09:00
|
|
|
const prevKey = this.dir === 'ltr' ? 'ArrowLeft' : 'ArrowRight';
|
|
|
|
const nextKey = this.dir === 'ltr' ? 'ArrowRight' : 'ArrowLeft';
|
2024-07-02 15:04:54 +09:00
|
|
|
|
|
|
|
this.keyNavigationSubscription = this.stateService.keyNavigation$.pipe(
|
2024-07-02 21:42:11 +09:00
|
|
|
filter((event) => event.key === prevKey || event.key === nextKey),
|
2024-07-02 15:04:54 +09:00
|
|
|
tap((event) => {
|
|
|
|
if (event.key === prevKey && this.page > 1) {
|
|
|
|
this.page--;
|
|
|
|
this.isLoading = true;
|
|
|
|
this.cd.markForCheck();
|
|
|
|
}
|
|
|
|
if (event.key === nextKey && this.page * 15 < this.accelerationCount) {
|
|
|
|
this.page++;
|
|
|
|
this.isLoading = true;
|
|
|
|
this.cd.markForCheck();
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
throttleTime(1000, undefined, { leading: true, trailing: true }),
|
|
|
|
).subscribe(() => {
|
|
|
|
this.pageChange(this.page);
|
|
|
|
});
|
2024-07-23 18:51:30 +02:00
|
|
|
|
|
|
|
this.miningService.getMiningStats('1m').subscribe(stats => {
|
|
|
|
for (const pool of stats.pools) {
|
|
|
|
this.pools[pool.poolUniqueId] = pool;
|
|
|
|
}
|
|
|
|
});
|
2023-07-20 16:26:42 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
this.skeletonLines = this.widget === true ? [...Array(6).keys()] : [...Array(15).keys()];
|
|
|
|
this.paginationMaxSize = window.matchMedia('(max-width: 670px)').matches ? 3 : 5;
|
2024-06-26 15:37:39 +09:00
|
|
|
|
2024-02-26 15:54:10 +01:00
|
|
|
this.accelerationList$ = this.pageSubject.pipe(
|
|
|
|
switchMap((page) => {
|
2024-06-26 11:13:32 +09:00
|
|
|
this.isLoading = true;
|
2024-05-04 00:18:33 +00:00
|
|
|
const accelerationObservable$ = this.accelerations$ || (this.pending ? this.stateService.liveAccelerations$ : this.servicesApiService.getAccelerationHistoryObserveResponse$({ page: page }));
|
|
|
|
if (!this.accelerations$ && this.pending) {
|
|
|
|
this.websocketService.ensureTrackAccelerations();
|
|
|
|
}
|
2024-02-26 15:54:10 +01:00
|
|
|
return accelerationObservable$.pipe(
|
|
|
|
switchMap(response => {
|
2024-02-26 16:23:00 +01:00
|
|
|
let accelerations = response;
|
|
|
|
if (response.body) {
|
|
|
|
accelerations = response.body;
|
|
|
|
this.accelerationCount = parseInt(response.headers.get('x-total-count'), 10);
|
|
|
|
}
|
2024-02-26 15:54:10 +01:00
|
|
|
if (this.pending) {
|
|
|
|
for (const acceleration of accelerations) {
|
|
|
|
acceleration.status = acceleration.status || 'accelerating';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const acc of accelerations) {
|
2024-04-12 15:12:25 +09:00
|
|
|
acc.boost = acc.boostCost != null ? acc.boostCost : acc.bidBoost;
|
2024-02-26 15:54:10 +01:00
|
|
|
}
|
|
|
|
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 {
|
2024-06-26 15:37:39 +09:00
|
|
|
this.router.navigate(['acceleration', 'list', page]);
|
2024-02-26 15:54:10 +01:00
|
|
|
}
|
|
|
|
|
2023-07-20 16:26:42 +09:00
|
|
|
trackByBlock(index: number, block: BlockExtended): number {
|
|
|
|
return block.height;
|
|
|
|
}
|
2024-05-04 00:18:33 +00:00
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
this.websocketService.stopTrackAccelerations();
|
2024-06-26 15:37:39 +09:00
|
|
|
this.paramSubscription?.unsubscribe();
|
|
|
|
this.keyNavigationSubscription?.unsubscribe();
|
2024-05-04 00:18:33 +00:00
|
|
|
}
|
2023-07-20 16:26:42 +09:00
|
|
|
}
|