2019-08-15 14:50:05 +03:00
|
|
|
import { Component, OnInit, LOCALE_ID, Inject, Renderer2 } from '@angular/core';
|
2019-07-27 18:43:17 +03:00
|
|
|
import { formatDate } from '@angular/common';
|
2020-02-16 22:15:07 +07:00
|
|
|
import { VbytesPipe } from '../../pipes/bytes-pipe/vbytes.pipe';
|
2019-07-27 18:43:17 +03:00
|
|
|
|
|
|
|
import * as Chartist from 'chartist';
|
2020-02-16 22:15:07 +07:00
|
|
|
import { WebsocketService } from 'src/app/services/websocket.service';
|
2020-02-17 00:26:57 +07:00
|
|
|
import { OptimizedMempoolStats } from '../../interfaces/node-api.interface';
|
2020-02-16 22:15:07 +07:00
|
|
|
import { StateService } from 'src/app/services/state.service';
|
|
|
|
import { ApiService } from 'src/app/services/api.service';
|
2019-07-27 18:43:17 +03:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-television',
|
|
|
|
templateUrl: './television.component.html',
|
|
|
|
styleUrls: ['./television.component.scss']
|
|
|
|
})
|
|
|
|
export class TelevisionComponent implements OnInit {
|
|
|
|
loading = true;
|
|
|
|
|
2020-02-17 00:26:57 +07:00
|
|
|
mempoolStats: OptimizedMempoolStats[] = [];
|
2019-07-27 18:43:17 +03:00
|
|
|
mempoolVsizeFeesData: any;
|
|
|
|
mempoolVsizeFeesOptions: any;
|
|
|
|
|
|
|
|
constructor(
|
2020-02-16 22:15:07 +07:00
|
|
|
private websocketService: WebsocketService,
|
2019-07-27 18:43:17 +03:00
|
|
|
@Inject(LOCALE_ID) private locale: string,
|
2019-11-21 11:58:29 +08:00
|
|
|
private vbytesPipe: VbytesPipe,
|
2020-02-16 22:15:07 +07:00
|
|
|
private apiService: ApiService,
|
|
|
|
private stateService: StateService,
|
2019-07-27 18:43:17 +03:00
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit() {
|
2020-03-14 13:48:01 +07:00
|
|
|
this.websocketService.want(['blocks', 'live-2h-chart', 'mempool-blocks']);
|
2019-08-15 14:50:05 +03:00
|
|
|
|
2019-07-27 18:43:17 +03:00
|
|
|
const labelInterpolationFnc = (value: any, index: any) => {
|
|
|
|
return index % 6 === 0 ? formatDate(value, 'HH:mm', this.locale) : null;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.mempoolVsizeFeesOptions = {
|
|
|
|
showArea: true,
|
|
|
|
showLine: false,
|
|
|
|
fullWidth: true,
|
|
|
|
showPoint: false,
|
|
|
|
low: 0,
|
|
|
|
axisX: {
|
|
|
|
labelInterpolationFnc: labelInterpolationFnc,
|
|
|
|
offset: 40
|
|
|
|
},
|
|
|
|
axisY: {
|
|
|
|
labelInterpolationFnc: (value: number): any => {
|
2019-11-21 11:58:29 +08:00
|
|
|
return this.vbytesPipe.transform(value, 2);
|
2019-07-27 18:43:17 +03:00
|
|
|
},
|
2019-08-21 08:33:38 +02:00
|
|
|
offset: 160
|
2019-07-27 18:43:17 +03:00
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
Chartist.plugins.ctTargetLine({
|
|
|
|
value: 1000000
|
|
|
|
}),
|
2019-08-21 08:33:38 +02:00
|
|
|
Chartist.plugins.legend({
|
|
|
|
legendNames: [1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100, 125, 150, 175, 200,
|
|
|
|
250, 300, 350, 400].map((sats, i, arr) => {
|
|
|
|
if (sats === 400) {
|
|
|
|
return '350+';
|
|
|
|
}
|
|
|
|
if (i === 0) {
|
|
|
|
return '1 sat/vbyte';
|
|
|
|
}
|
|
|
|
return arr[i - 1] + ' - ' + sats;
|
|
|
|
})
|
|
|
|
})
|
2019-07-27 18:43:17 +03:00
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
this.apiService.list2HStatistics$()
|
|
|
|
.subscribe((mempoolStats) => {
|
|
|
|
this.mempoolStats = mempoolStats;
|
|
|
|
this.handleNewMempoolData(this.mempoolStats.concat([]));
|
|
|
|
this.loading = false;
|
|
|
|
});
|
|
|
|
|
2020-02-16 22:15:07 +07:00
|
|
|
this.stateService.live2Chart$
|
2019-07-27 18:43:17 +03:00
|
|
|
.subscribe((mempoolStats) => {
|
|
|
|
this.mempoolStats.unshift(mempoolStats);
|
|
|
|
this.mempoolStats = this.mempoolStats.slice(0, this.mempoolStats.length - 1);
|
|
|
|
this.handleNewMempoolData(this.mempoolStats.concat([]));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-02-17 00:26:57 +07:00
|
|
|
handleNewMempoolData(mempoolStats: OptimizedMempoolStats[]) {
|
2019-07-27 18:43:17 +03:00
|
|
|
mempoolStats.reverse();
|
|
|
|
const labels = mempoolStats.map(stats => stats.added);
|
|
|
|
|
|
|
|
const finalArrayVbyte = this.generateArray(mempoolStats);
|
|
|
|
|
|
|
|
// Remove the 0-1 fee vbyte since it's practially empty
|
|
|
|
finalArrayVbyte.shift();
|
|
|
|
|
|
|
|
this.mempoolVsizeFeesData = {
|
|
|
|
labels: labels,
|
|
|
|
series: finalArrayVbyte
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-02-17 00:26:57 +07:00
|
|
|
generateArray(mempoolStats: OptimizedMempoolStats[]) {
|
2019-07-27 18:43:17 +03:00
|
|
|
const finalArray: number[][] = [];
|
|
|
|
let feesArray: number[] = [];
|
|
|
|
|
2020-02-17 00:26:57 +07:00
|
|
|
for (let index = 37; index > -1; index--) {
|
2019-07-27 18:43:17 +03:00
|
|
|
feesArray = [];
|
|
|
|
mempoolStats.forEach((stats) => {
|
2020-02-17 00:26:57 +07:00
|
|
|
const theFee = stats.vsizes[index].toString();
|
2019-07-27 18:43:17 +03:00
|
|
|
if (theFee) {
|
|
|
|
feesArray.push(parseInt(theFee, 10));
|
|
|
|
} else {
|
|
|
|
feesArray.push(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (finalArray.length) {
|
|
|
|
feesArray = feesArray.map((value, i) => value + finalArray[finalArray.length - 1][i]);
|
|
|
|
}
|
|
|
|
finalArray.push(feesArray);
|
2020-02-17 00:26:57 +07:00
|
|
|
}
|
2019-07-27 18:43:17 +03:00
|
|
|
finalArray.reverse();
|
|
|
|
return finalArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|