New base code for mempool blockchain explorerer

This commit is contained in:
Simon Lindh
2020-02-16 22:15:07 +07:00
committed by wiz
parent ca40fc7045
commit ac95c09ea6
204 changed files with 6959 additions and 14341 deletions

View File

@@ -0,0 +1,25 @@
<div id="tv-wrapper">
<div *ngIf="loading" class="text-center">
<div class="spinner-border text-light"></div>
</div>
<div class="chart-holder" *ngIf="mempoolVsizeFeesData">
<app-chartist
[data]="mempoolVsizeFeesData"
[type]="'Line'"
[options]="mempoolVsizeFeesOptions">
</app-chartist>
</div>
<div class="text-center" class="blockchain-wrapper">
<div class="position-container">
<app-mempool-blocks></app-mempool-blocks>
<app-blockchain-blocks></app-blockchain-blocks>
<div id="divider"></div>
</div>
</div>
</div>

View File

@@ -0,0 +1,49 @@
#tv-wrapper {
height: 100%;
margin: 10px;
margin-top: 20px;
}
.blockchain-wrapper {
overflow: hidden;
}
.position-container {
position: absolute;
left: 50%;
bottom: 150px;
}
.chart-holder {
height: calc(100% - 220px);
}
#divider {
width: 3px;
height: 175px;
left: 0;
top: -40px;
background-image: url('/assets/divider-new.png');
background-repeat: repeat-y;
position: absolute;
}
#divider > img {
position: absolute;
left: -100px;
top: -28px;
}
@media (min-width: 1920px) {
.position-container {
transform: scale(1.3);
bottom: 190px;
}
.chart-holder {
height: calc(100% - 280px);
}
}
:host ::ng-deep .ct-legend {
top: 25px;
}

View File

@@ -0,0 +1,135 @@
import { Component, OnInit, LOCALE_ID, Inject, Renderer2 } from '@angular/core';
import { formatDate } from '@angular/common';
import { VbytesPipe } from '../../pipes/bytes-pipe/vbytes.pipe';
import * as Chartist from 'chartist';
import { WebsocketService } from 'src/app/services/websocket.service';
import { MempoolStats } from '../../interfaces/node-api.interface';
import { StateService } from 'src/app/services/state.service';
import { ApiService } from 'src/app/services/api.service';
@Component({
selector: 'app-television',
templateUrl: './television.component.html',
styleUrls: ['./television.component.scss']
})
export class TelevisionComponent implements OnInit {
loading = true;
mempoolStats: MempoolStats[] = [];
mempoolVsizeFeesData: any;
mempoolVsizeFeesOptions: any;
constructor(
private websocketService: WebsocketService,
@Inject(LOCALE_ID) private locale: string,
private vbytesPipe: VbytesPipe,
private renderer: Renderer2,
private apiService: ApiService,
private stateService: StateService,
) { }
ngOnInit() {
this.websocketService.want(['live-2h-chart']);
this.renderer.addClass(document.body, 'disable-scroll');
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 => {
return this.vbytesPipe.transform(value, 2);
},
offset: 160
},
plugins: [
Chartist.plugins.ctTargetLine({
value: 1000000
}),
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;
})
})
]
};
this.apiService.list2HStatistics$()
.subscribe((mempoolStats) => {
this.mempoolStats = mempoolStats;
this.handleNewMempoolData(this.mempoolStats.concat([]));
this.loading = false;
});
this.stateService.live2Chart$
.subscribe((mempoolStats) => {
this.mempoolStats.unshift(mempoolStats);
this.mempoolStats = this.mempoolStats.slice(0, this.mempoolStats.length - 1);
this.handleNewMempoolData(this.mempoolStats.concat([]));
});
}
handleNewMempoolData(mempoolStats: MempoolStats[]) {
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
};
}
generateArray(mempoolStats: MempoolStats[]) {
const logFees = [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, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000];
logFees.reverse();
const finalArray: number[][] = [];
let feesArray: number[] = [];
logFees.forEach((fee) => {
feesArray = [];
mempoolStats.forEach((stats) => {
// @ts-ignore
const theFee = stats['vsize_' + fee];
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);
});
finalArray.reverse();
return finalArray;
}
}