2023-07-20 16:26:42 +09:00
|
|
|
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
|
|
|
|
import { SeoService } from '../../services/seo.service';
|
|
|
|
import { WebsocketService } from '../../services/websocket.service';
|
2023-07-21 14:13:18 +09:00
|
|
|
import { Acceleration, BlockExtended } from '../../interfaces/node-api.interface';
|
|
|
|
import { StateService } from '../../services/state.service';
|
|
|
|
import { Observable, catchError, combineLatest, of, switchMap } from 'rxjs';
|
|
|
|
import { ApiService } from '../../services/api.service';
|
|
|
|
|
|
|
|
interface AccelerationBlock extends BlockExtended {
|
|
|
|
accelerationCount: number,
|
|
|
|
}
|
2023-07-20 16:26:42 +09:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-accelerator-dashboard',
|
|
|
|
templateUrl: './accelerator-dashboard.component.html',
|
|
|
|
styleUrls: ['./accelerator-dashboard.component.scss'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
|
|
})
|
|
|
|
export class AcceleratorDashboardComponent implements OnInit {
|
2023-07-21 14:13:18 +09:00
|
|
|
blocks$: Observable<AccelerationBlock[]>;
|
|
|
|
|
|
|
|
loadingBlocks: boolean = true;
|
|
|
|
|
2023-07-20 16:26:42 +09:00
|
|
|
constructor(
|
|
|
|
private seoService: SeoService,
|
|
|
|
private websocketService: WebsocketService,
|
2023-07-21 14:13:18 +09:00
|
|
|
private apiService: ApiService,
|
|
|
|
private stateService: StateService,
|
2023-07-20 16:26:42 +09:00
|
|
|
) {
|
|
|
|
this.seoService.setTitle($localize`:@@a681a4e2011bb28157689dbaa387de0dd0aa0c11:Accelerator Dashboard`);
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.websocketService.want(['blocks', 'mempool-blocks', 'stats']);
|
2023-07-21 14:13:18 +09:00
|
|
|
|
|
|
|
this.blocks$ = combineLatest([
|
|
|
|
this.stateService.blocks$.pipe(
|
|
|
|
switchMap((blocks) => {
|
|
|
|
if (this.stateService.env.MINING_DASHBOARD === true) {
|
|
|
|
for (const block of blocks) {
|
|
|
|
// @ts-ignore: Need to add an extra field for the template
|
|
|
|
block.extras.pool.logo = `/resources/mining-pools/` +
|
|
|
|
block.extras.pool.name.toLowerCase().replace(' ', '').replace('.', '') + '.svg';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return of(blocks as AccelerationBlock[]);
|
|
|
|
})
|
|
|
|
),
|
2023-07-22 15:30:48 +09:00
|
|
|
this.apiService.getAccelerationHistory$('24h').pipe(
|
2023-07-21 14:13:18 +09:00
|
|
|
catchError((err) => {
|
|
|
|
this.loadingBlocks = false;
|
|
|
|
return of([]);
|
|
|
|
})
|
|
|
|
)
|
|
|
|
]).pipe(
|
|
|
|
switchMap(([blocks, accelerations]) => {
|
|
|
|
const accelerationsByBlock: { [ hash: string ]: Acceleration[] } = {};
|
|
|
|
for (const acceleration of accelerations) {
|
2023-08-30 22:24:27 +09:00
|
|
|
if (['mined', 'completed'].includes(acceleration.status) && !accelerationsByBlock[acceleration.blockHash]) {
|
2023-07-22 15:30:48 +09:00
|
|
|
accelerationsByBlock[acceleration.blockHash] = [];
|
2023-07-21 14:13:18 +09:00
|
|
|
}
|
2023-08-30 22:24:27 +09:00
|
|
|
if (['mined', 'completed'].includes(acceleration.status)) {
|
2023-07-22 15:30:48 +09:00
|
|
|
accelerationsByBlock[acceleration.blockHash].push(acceleration);
|
2023-07-21 14:13:18 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return of(blocks.slice(0, 6).map(block => {
|
|
|
|
block.accelerationCount = (accelerationsByBlock[block.id] || []).length;
|
|
|
|
return block;
|
|
|
|
}));
|
|
|
|
})
|
|
|
|
);
|
2023-07-20 16:26:42 +09:00
|
|
|
}
|
|
|
|
}
|