2020-09-26 22:46:26 +07:00
|
|
|
import { ChangeDetectionStrategy, Component, Inject, LOCALE_ID, OnInit } from '@angular/core';
|
2021-07-17 08:58:16 -03:00
|
|
|
import { combineLatest, merge, Observable, of, timer } from 'rxjs';
|
2020-09-28 23:05:42 +07:00
|
|
|
import { filter, map, scan, share, switchMap, tap } from 'rxjs/operators';
|
2020-09-26 02:11:30 +07:00
|
|
|
import { Block } from '../interfaces/electrs.interface';
|
2021-11-19 00:10:12 +04:00
|
|
|
import { OptimizedMempoolStats } from '../interfaces/node-api.interface';
|
2020-09-26 02:11:30 +07:00
|
|
|
import { MempoolInfo, TransactionStripped } from '../interfaces/websocket.interface';
|
2020-09-26 22:46:26 +07:00
|
|
|
import { ApiService } from '../services/api.service';
|
2020-09-21 19:41:12 +07:00
|
|
|
import { StateService } from '../services/state.service';
|
2020-09-26 22:46:26 +07:00
|
|
|
import { WebsocketService } from '../services/websocket.service';
|
2020-09-28 16:32:48 +07:00
|
|
|
import { SeoService } from '../services/seo.service';
|
2020-10-27 02:58:29 +07:00
|
|
|
import { StorageService } from '../services/storage.service';
|
2020-09-21 19:41:12 +07:00
|
|
|
|
|
|
|
interface MempoolBlocksData {
|
|
|
|
blocks: number;
|
|
|
|
size: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface MempoolInfoData {
|
|
|
|
memPoolInfo: MempoolInfo;
|
|
|
|
vBytesPerSecond: number;
|
|
|
|
progressWidth: string;
|
2021-08-21 01:46:28 -03:00
|
|
|
progressColor: string;
|
2020-09-21 19:41:12 +07:00
|
|
|
}
|
|
|
|
|
2020-09-26 22:46:26 +07:00
|
|
|
interface MempoolStatsData {
|
|
|
|
mempool: OptimizedMempoolStats[];
|
|
|
|
weightPerSecond: any;
|
|
|
|
}
|
|
|
|
|
2020-09-21 19:41:12 +07:00
|
|
|
@Component({
|
|
|
|
selector: 'app-dashboard',
|
|
|
|
templateUrl: './dashboard.component.html',
|
|
|
|
styleUrls: ['./dashboard.component.scss'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
|
|
|
})
|
|
|
|
export class DashboardComponent implements OnInit {
|
2020-10-27 16:34:27 +07:00
|
|
|
collapseLevel: string;
|
2020-09-21 19:41:12 +07:00
|
|
|
network$: Observable<string>;
|
|
|
|
mempoolBlocksData$: Observable<MempoolBlocksData>;
|
|
|
|
mempoolInfoData$: Observable<MempoolInfoData>;
|
2021-01-05 18:57:06 +07:00
|
|
|
mempoolLoadingStatus$: Observable<number>;
|
2020-09-21 19:41:12 +07:00
|
|
|
vBytesPerSecondLimit = 1667;
|
2020-09-26 02:11:30 +07:00
|
|
|
blocks$: Observable<Block[]>;
|
|
|
|
transactions$: Observable<TransactionStripped[]>;
|
|
|
|
latestBlockHeight: number;
|
2020-09-26 22:46:26 +07:00
|
|
|
mempoolTransactionsWeightPerSecondData: any;
|
|
|
|
mempoolStats$: Observable<MempoolStatsData>;
|
|
|
|
transactionsWeightPerSecondOptions: any;
|
2021-07-26 20:47:08 -03:00
|
|
|
isLoadingWebSocket$: Observable<boolean>;
|
2021-09-25 03:13:07 +04:00
|
|
|
liquidPegsMonth$: Observable<any>;
|
2020-09-21 19:41:12 +07:00
|
|
|
|
|
|
|
constructor(
|
2020-09-26 22:46:26 +07:00
|
|
|
@Inject(LOCALE_ID) private locale: string,
|
2021-08-05 02:03:52 +03:00
|
|
|
public stateService: StateService,
|
2020-09-26 22:46:26 +07:00
|
|
|
private apiService: ApiService,
|
|
|
|
private websocketService: WebsocketService,
|
2020-09-28 16:32:48 +07:00
|
|
|
private seoService: SeoService,
|
2020-10-27 02:58:29 +07:00
|
|
|
private storageService: StorageService,
|
2020-09-21 19:41:12 +07:00
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2021-07-26 20:47:08 -03:00
|
|
|
this.isLoadingWebSocket$ = this.stateService.isLoadingWebSocket$;
|
2020-09-28 16:32:48 +07:00
|
|
|
this.seoService.resetTitle();
|
2020-09-26 22:46:26 +07:00
|
|
|
this.websocketService.want(['blocks', 'stats', 'mempool-blocks', 'live-2h-chart']);
|
2020-09-21 19:41:12 +07:00
|
|
|
this.network$ = merge(of(''), this.stateService.networkChanged$);
|
2020-10-27 16:34:27 +07:00
|
|
|
this.collapseLevel = this.storageService.getValue('dashboard-collapsed') || 'one';
|
2021-08-21 01:46:28 -03:00
|
|
|
this.mempoolLoadingStatus$ = this.stateService.loadingIndicators$
|
|
|
|
.pipe(
|
|
|
|
map((indicators) => indicators.mempool !== undefined ? indicators.mempool : 100)
|
|
|
|
);
|
2020-09-21 19:41:12 +07:00
|
|
|
|
|
|
|
this.mempoolInfoData$ = combineLatest([
|
|
|
|
this.stateService.mempoolInfo$,
|
|
|
|
this.stateService.vbytesPerSecond$
|
|
|
|
])
|
|
|
|
.pipe(
|
|
|
|
map(([mempoolInfo, vbytesPerSecond]) => {
|
|
|
|
const percent = Math.round((Math.min(vbytesPerSecond, this.vBytesPerSecondLimit) / this.vBytesPerSecondLimit) * 100);
|
|
|
|
|
2021-08-21 01:46:28 -03:00
|
|
|
let progressColor = '#7CB342';
|
|
|
|
if (vbytesPerSecond > 1667) {
|
|
|
|
progressColor = '#FDD835';
|
|
|
|
}
|
|
|
|
if (vbytesPerSecond > 2000) {
|
|
|
|
progressColor = '#FFB300';
|
|
|
|
}
|
|
|
|
if (vbytesPerSecond > 2500) {
|
|
|
|
progressColor = '#FB8C00';
|
|
|
|
}
|
|
|
|
if (vbytesPerSecond > 3000) {
|
|
|
|
progressColor = '#F4511E';
|
|
|
|
}
|
|
|
|
if (vbytesPerSecond > 3500) {
|
|
|
|
progressColor = '#D81B60';
|
2020-09-21 19:41:12 +07:00
|
|
|
}
|
|
|
|
|
2021-06-06 17:07:04 -03:00
|
|
|
const mempoolSizePercentage = (mempoolInfo.usage / mempoolInfo.maxmempool * 100);
|
2021-01-12 20:45:41 +07:00
|
|
|
let mempoolSizeProgress = 'bg-danger';
|
|
|
|
if (mempoolSizePercentage <= 50) {
|
|
|
|
mempoolSizeProgress = 'bg-success';
|
|
|
|
} else if (mempoolSizePercentage <= 75) {
|
|
|
|
mempoolSizeProgress = 'bg-warning';
|
|
|
|
}
|
|
|
|
|
2020-09-21 19:41:12 +07:00
|
|
|
return {
|
|
|
|
memPoolInfo: mempoolInfo,
|
|
|
|
vBytesPerSecond: vbytesPerSecond,
|
|
|
|
progressWidth: percent + '%',
|
2021-08-21 01:46:28 -03:00
|
|
|
progressColor: progressColor,
|
2021-01-12 20:45:41 +07:00
|
|
|
mempoolSizeProgress: mempoolSizeProgress,
|
2020-09-21 19:41:12 +07:00
|
|
|
};
|
|
|
|
})
|
|
|
|
);
|
2021-08-25 17:18:27 -03:00
|
|
|
|
2020-09-21 19:41:12 +07:00
|
|
|
this.mempoolBlocksData$ = this.stateService.mempoolBlocks$
|
|
|
|
.pipe(
|
|
|
|
map((mempoolBlocks) => {
|
|
|
|
const size = mempoolBlocks.map((m) => m.blockSize).reduce((a, b) => a + b, 0);
|
|
|
|
const vsize = mempoolBlocks.map((m) => m.blockVSize).reduce((a, b) => a + b, 0);
|
|
|
|
|
|
|
|
return {
|
|
|
|
size: size,
|
2021-07-31 17:30:35 +03:00
|
|
|
blocks: Math.ceil(vsize / this.stateService.blockVSize)
|
2020-09-21 19:41:12 +07:00
|
|
|
};
|
|
|
|
})
|
|
|
|
);
|
2020-09-26 02:11:30 +07:00
|
|
|
|
|
|
|
this.blocks$ = this.stateService.blocks$
|
|
|
|
.pipe(
|
|
|
|
tap(([block]) => {
|
|
|
|
this.latestBlockHeight = block.height;
|
|
|
|
}),
|
|
|
|
scan((acc, [block]) => {
|
2022-01-24 20:44:05 +01:00
|
|
|
if (acc.find((b) => b.height == block.height)) {
|
|
|
|
return acc;
|
|
|
|
}
|
2020-09-26 02:11:30 +07:00
|
|
|
acc.unshift(block);
|
2021-01-12 00:15:52 +07:00
|
|
|
acc = acc.slice(0, 6);
|
2020-09-26 02:11:30 +07:00
|
|
|
return acc;
|
|
|
|
}, []),
|
|
|
|
);
|
|
|
|
|
|
|
|
this.transactions$ = this.stateService.transactions$
|
|
|
|
.pipe(
|
|
|
|
scan((acc, tx) => {
|
|
|
|
acc.unshift(tx);
|
2021-01-12 00:15:52 +07:00
|
|
|
acc = acc.slice(0, 6);
|
2020-09-26 02:11:30 +07:00
|
|
|
return acc;
|
|
|
|
}, []),
|
|
|
|
);
|
2020-09-26 22:46:26 +07:00
|
|
|
|
2021-08-21 01:46:28 -03:00
|
|
|
this.mempoolStats$ = this.stateService.connectionState$
|
|
|
|
.pipe(
|
|
|
|
filter((state) => state === 2),
|
|
|
|
switchMap(() => this.apiService.list2HStatistics$()),
|
|
|
|
switchMap((mempoolStats) => {
|
|
|
|
return merge(
|
|
|
|
this.stateService.live2Chart$
|
|
|
|
.pipe(
|
|
|
|
scan((acc, stats) => {
|
|
|
|
acc.unshift(stats);
|
|
|
|
acc = acc.slice(0, 120);
|
|
|
|
return acc;
|
|
|
|
}, mempoolStats)
|
|
|
|
),
|
|
|
|
of(mempoolStats)
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
map((mempoolStats) => {
|
|
|
|
return {
|
|
|
|
mempool: mempoolStats,
|
|
|
|
weightPerSecond: this.handleNewMempoolData(mempoolStats.concat([])),
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
share(),
|
|
|
|
);
|
2021-09-25 03:13:07 +04:00
|
|
|
|
2021-12-27 22:54:45 +04:00
|
|
|
if (this.stateService.network === 'liquid' || this.stateService.network === 'liquidtestnet') {
|
2021-09-25 03:13:07 +04:00
|
|
|
this.liquidPegsMonth$ = this.apiService.listLiquidPegsMonth$()
|
|
|
|
.pipe(
|
|
|
|
map((pegs) => {
|
|
|
|
const labels = pegs.map(stats => stats.date);
|
|
|
|
const series = pegs.map(stats => parseFloat(stats.amount) / 100000000);
|
|
|
|
series.reduce((prev, curr, i) => series[i] = prev + curr, 0);
|
|
|
|
return {
|
|
|
|
series,
|
|
|
|
labels
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
share(),
|
|
|
|
);
|
|
|
|
}
|
2020-09-26 22:46:26 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
handleNewMempoolData(mempoolStats: OptimizedMempoolStats[]) {
|
|
|
|
mempoolStats.reverse();
|
|
|
|
const labels = mempoolStats.map(stats => stats.added);
|
|
|
|
|
|
|
|
return {
|
|
|
|
labels: labels,
|
2021-12-11 10:38:13 +09:00
|
|
|
series: [mempoolStats.map((stats) => [stats.added * 1000, stats.vbytes_per_second])],
|
2020-09-26 22:46:26 +07:00
|
|
|
};
|
2020-09-26 02:11:30 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
trackByBlock(index: number, block: Block) {
|
|
|
|
return block.height;
|
2020-09-21 19:41:12 +07:00
|
|
|
}
|
2020-10-27 02:58:29 +07:00
|
|
|
|
|
|
|
toggleCollapsed() {
|
2020-10-27 16:34:27 +07:00
|
|
|
if (this.collapseLevel === 'one') {
|
|
|
|
this.collapseLevel = 'two';
|
|
|
|
} else if (this.collapseLevel === 'two') {
|
|
|
|
this.collapseLevel = 'three';
|
|
|
|
} else {
|
|
|
|
this.collapseLevel = 'one';
|
|
|
|
}
|
|
|
|
this.storageService.setValue('dashboard-collapsed', this.collapseLevel);
|
2020-10-27 02:58:29 +07:00
|
|
|
}
|
2020-09-21 19:41:12 +07:00
|
|
|
}
|