2023-12-08 13:03:08 +00:00
|
|
|
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Inject, Input, LOCALE_ID, OnDestroy, OnInit } from '@angular/core';
|
2023-07-22 15:43:52 +09:00
|
|
|
import { EChartsOption, graphic } from 'echarts';
|
2024-02-07 21:40:22 +00:00
|
|
|
import { Observable, Subscription, combineLatest, fromEvent } from 'rxjs';
|
2023-12-08 13:03:08 +00:00
|
|
|
import { map, max, startWith, switchMap, tap } from 'rxjs/operators';
|
2023-12-07 08:26:32 +00:00
|
|
|
import { ApiService } from '../../../services/api.service';
|
|
|
|
import { SeoService } from '../../../services/seo.service';
|
2023-07-22 15:43:52 +09:00
|
|
|
import { formatNumber } from '@angular/common';
|
|
|
|
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
|
2023-12-08 13:03:08 +00:00
|
|
|
import { download, formatterXAxis, formatterXAxisLabel, formatterXAxisTimeCategory } from '../../../shared/graphs.utils';
|
2023-12-07 08:26:32 +00:00
|
|
|
import { StorageService } from '../../../services/storage.service';
|
|
|
|
import { MiningService } from '../../../services/mining.service';
|
2023-07-22 15:43:52 +09:00
|
|
|
import { ActivatedRoute } from '@angular/router';
|
2023-12-07 08:26:32 +00:00
|
|
|
import { Acceleration } from '../../../interfaces/node-api.interface';
|
2023-07-22 15:43:52 +09:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-acceleration-fees-graph',
|
|
|
|
templateUrl: './acceleration-fees-graph.component.html',
|
|
|
|
styleUrls: ['./acceleration-fees-graph.component.scss'],
|
|
|
|
styles: [`
|
|
|
|
.loadingGraphs {
|
|
|
|
position: absolute;
|
|
|
|
top: 50%;
|
|
|
|
left: calc(50% - 15px);
|
|
|
|
z-index: 100;
|
|
|
|
}
|
|
|
|
`],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
|
|
})
|
2023-12-08 13:03:08 +00:00
|
|
|
export class AccelerationFeesGraphComponent implements OnInit, OnDestroy {
|
2023-07-22 15:43:52 +09:00
|
|
|
@Input() widget: boolean = false;
|
2024-02-07 21:40:22 +00:00
|
|
|
@Input() height: number | string = '200';
|
2023-07-22 15:43:52 +09:00
|
|
|
@Input() right: number | string = 45;
|
|
|
|
@Input() left: number | string = 75;
|
2023-12-07 08:26:32 +00:00
|
|
|
@Input() accelerations$: Observable<Acceleration[]>;
|
2023-07-22 15:43:52 +09:00
|
|
|
|
|
|
|
miningWindowPreference: string;
|
|
|
|
radioGroupForm: UntypedFormGroup;
|
|
|
|
|
|
|
|
chartOptions: EChartsOption = {};
|
|
|
|
chartInitOptions = {
|
|
|
|
renderer: 'svg',
|
|
|
|
};
|
|
|
|
|
2023-08-30 22:25:33 +09:00
|
|
|
hrStatsObservable$: Observable<any>;
|
2023-07-22 15:43:52 +09:00
|
|
|
statsObservable$: Observable<any>;
|
2023-12-08 13:03:08 +00:00
|
|
|
statsSubscription: Subscription;
|
2023-07-22 15:43:52 +09:00
|
|
|
isLoading = true;
|
|
|
|
formatNumber = formatNumber;
|
|
|
|
timespan = '';
|
|
|
|
chartInstance: any = undefined;
|
|
|
|
|
|
|
|
currency: string;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
@Inject(LOCALE_ID) public locale: string,
|
|
|
|
private seoService: SeoService,
|
|
|
|
private apiService: ApiService,
|
|
|
|
private formBuilder: UntypedFormBuilder,
|
|
|
|
private storageService: StorageService,
|
|
|
|
private miningService: MiningService,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private cd: ChangeDetectorRef,
|
|
|
|
) {
|
|
|
|
this.radioGroupForm = this.formBuilder.group({ dateSpan: '1y' });
|
|
|
|
this.radioGroupForm.controls.dateSpan.setValue('1y');
|
|
|
|
this.currency = 'USD';
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2023-12-08 13:03:08 +00:00
|
|
|
this.isLoading = true;
|
2023-07-22 15:43:52 +09:00
|
|
|
if (this.widget) {
|
2023-12-08 13:03:08 +00:00
|
|
|
this.miningWindowPreference = '1m';
|
2023-07-22 15:43:52 +09:00
|
|
|
this.timespan = this.miningWindowPreference;
|
2023-08-30 22:25:33 +09:00
|
|
|
|
2023-07-22 15:43:52 +09:00
|
|
|
this.statsObservable$ = combineLatest([
|
2023-12-07 08:26:32 +00:00
|
|
|
(this.accelerations$ || this.apiService.getAccelerationHistory$({ timeframe: this.miningWindowPreference })),
|
2023-07-22 15:43:52 +09:00
|
|
|
this.apiService.getHistoricalBlockFees$(this.miningWindowPreference),
|
2024-02-07 21:40:22 +00:00
|
|
|
fromEvent(window, 'resize').pipe(startWith(null)),
|
2023-07-22 15:43:52 +09:00
|
|
|
]).pipe(
|
|
|
|
tap(([accelerations, blockFeesResponse]) => {
|
|
|
|
this.prepareChartOptions(accelerations, blockFeesResponse.body);
|
|
|
|
}),
|
|
|
|
map(([accelerations, blockFeesResponse]) => {
|
|
|
|
return {
|
2024-01-15 22:52:42 +00:00
|
|
|
avgFeesPaid: accelerations.filter(acc => acc.status === 'completed').reduce((total, acc) => total + (acc.feePaid - acc.baseFee - acc.vsizeFee), 0) / accelerations.length
|
2023-07-22 15:43:52 +09:00
|
|
|
};
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
} else {
|
2024-01-27 16:45:18 +00:00
|
|
|
this.seoService.setTitle($localize`:@@bcf34abc2d9ed8f45a2f65dd464c46694e9a181e:Acceleration Fees`);
|
2023-07-22 15:43:52 +09:00
|
|
|
this.miningWindowPreference = this.miningService.getDefaultTimespan('1w');
|
|
|
|
this.radioGroupForm = this.formBuilder.group({ dateSpan: this.miningWindowPreference });
|
|
|
|
this.radioGroupForm.controls.dateSpan.setValue(this.miningWindowPreference);
|
|
|
|
this.route.fragment.subscribe((fragment) => {
|
|
|
|
if (['24h', '3d', '1w', '1m'].indexOf(fragment) > -1) {
|
|
|
|
this.radioGroupForm.controls.dateSpan.setValue(fragment, { emitEvent: false });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.statsObservable$ = combineLatest([
|
|
|
|
this.radioGroupForm.get('dateSpan').valueChanges.pipe(
|
|
|
|
startWith(this.radioGroupForm.controls.dateSpan.value),
|
|
|
|
switchMap((timespan) => {
|
|
|
|
this.isLoading = true;
|
|
|
|
this.storageService.setValue('miningWindowPreference', timespan);
|
|
|
|
this.timespan = timespan;
|
2023-12-07 08:26:32 +00:00
|
|
|
return this.apiService.getAccelerationHistory$({});
|
2023-07-22 15:43:52 +09:00
|
|
|
})
|
|
|
|
),
|
|
|
|
this.radioGroupForm.get('dateSpan').valueChanges.pipe(
|
|
|
|
startWith(this.radioGroupForm.controls.dateSpan.value),
|
|
|
|
switchMap((timespan) => {
|
|
|
|
return this.apiService.getHistoricalBlockFees$(timespan);
|
|
|
|
})
|
|
|
|
)
|
|
|
|
]).pipe(
|
|
|
|
tap(([accelerations, blockFeesResponse]) => {
|
|
|
|
this.prepareChartOptions(accelerations, blockFeesResponse.body);
|
2023-08-30 22:25:33 +09:00
|
|
|
})
|
2023-07-22 15:43:52 +09:00
|
|
|
);
|
|
|
|
}
|
2023-12-08 13:03:08 +00:00
|
|
|
this.statsSubscription = this.statsObservable$.subscribe(() => {
|
|
|
|
this.isLoading = false;
|
|
|
|
this.cd.markForCheck();
|
|
|
|
});
|
2023-07-22 15:43:52 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
prepareChartOptions(accelerations, blockFees) {
|
|
|
|
let title: object;
|
|
|
|
|
|
|
|
const blockAccelerations = {};
|
|
|
|
|
|
|
|
for (const acceleration of accelerations) {
|
2023-12-03 08:17:59 +00:00
|
|
|
if (acceleration.status === 'completed') {
|
2023-08-30 22:24:27 +09:00
|
|
|
if (!blockAccelerations[acceleration.blockHeight]) {
|
|
|
|
blockAccelerations[acceleration.blockHeight] = [];
|
2023-07-22 15:43:52 +09:00
|
|
|
}
|
2023-08-30 22:24:27 +09:00
|
|
|
blockAccelerations[acceleration.blockHeight].push(acceleration);
|
2023-07-22 15:43:52 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let last = null;
|
2023-12-08 13:03:08 +00:00
|
|
|
let minValue = Infinity;
|
|
|
|
let maxValue = 0;
|
2023-07-22 15:43:52 +09:00
|
|
|
const data = [];
|
|
|
|
for (const val of blockFees) {
|
|
|
|
if (last == null) {
|
|
|
|
last = val.avgHeight;
|
|
|
|
}
|
|
|
|
let totalFeeDelta = 0;
|
2023-12-07 08:26:32 +00:00
|
|
|
let totalFeePaid = 0;
|
2023-07-22 15:43:52 +09:00
|
|
|
let totalCount = 0;
|
2023-12-08 13:03:08 +00:00
|
|
|
let blockCount = 0;
|
2023-07-22 15:43:52 +09:00
|
|
|
while (last <= val.avgHeight) {
|
2023-12-08 13:03:08 +00:00
|
|
|
blockCount++;
|
2023-07-22 15:43:52 +09:00
|
|
|
totalFeeDelta += (blockAccelerations[last] || []).reduce((total, acc) => total + acc.feeDelta, 0);
|
2024-01-15 22:52:42 +00:00
|
|
|
totalFeePaid += (blockAccelerations[last] || []).reduce((total, acc) => total + (acc.feePaid - acc.baseFee - acc.vsizeFee), 0);
|
2023-07-22 15:43:52 +09:00
|
|
|
totalCount += (blockAccelerations[last] || []).length;
|
|
|
|
last++;
|
|
|
|
}
|
2023-12-08 13:03:08 +00:00
|
|
|
minValue = Math.min(minValue, val.avgFees);
|
|
|
|
maxValue = Math.max(maxValue, val.avgFees);
|
2023-07-22 15:43:52 +09:00
|
|
|
data.push({
|
|
|
|
...val,
|
|
|
|
feeDelta: totalFeeDelta,
|
2023-12-08 13:03:08 +00:00
|
|
|
avgFeePaid: (totalFeePaid / blockCount),
|
|
|
|
accelerations: totalCount / blockCount,
|
2023-07-22 15:43:52 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.chartOptions = {
|
|
|
|
title: title,
|
|
|
|
color: [
|
2023-12-08 13:03:08 +00:00
|
|
|
'#8F5FF6',
|
|
|
|
'#6b6b6b',
|
2023-07-22 15:43:52 +09:00
|
|
|
],
|
|
|
|
animation: false,
|
|
|
|
grid: {
|
2024-02-07 21:40:22 +00:00
|
|
|
height: this.height,
|
2023-07-22 15:43:52 +09:00
|
|
|
right: this.right,
|
|
|
|
left: this.left,
|
|
|
|
bottom: this.widget ? 30 : 80,
|
|
|
|
top: this.widget ? 20 : (this.isMobile() ? 10 : 50),
|
|
|
|
},
|
|
|
|
tooltip: {
|
|
|
|
show: !this.isMobile(),
|
|
|
|
trigger: 'axis',
|
|
|
|
axisPointer: {
|
|
|
|
type: 'line'
|
|
|
|
},
|
|
|
|
backgroundColor: 'rgba(17, 19, 31, 1)',
|
|
|
|
borderRadius: 4,
|
|
|
|
shadowColor: 'rgba(0, 0, 0, 0.5)',
|
|
|
|
textStyle: {
|
|
|
|
color: '#b1b1b1',
|
|
|
|
align: 'left',
|
|
|
|
},
|
|
|
|
borderColor: '#000',
|
|
|
|
formatter: function (data) {
|
|
|
|
if (data.length <= 0) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
let tooltip = `<b style="color: white; margin-left: 2px">
|
|
|
|
${formatterXAxis(this.locale, this.timespan, parseInt(data[0].axisValue, 10))}</b><br>`;
|
|
|
|
|
2023-12-08 13:03:08 +00:00
|
|
|
for (const tick of data.reverse()) {
|
|
|
|
if (tick.data[1] >= 1_000_000) {
|
|
|
|
tooltip += `${tick.marker} ${tick.seriesName}: ${formatNumber(tick.data[1] / 100_000_000, this.locale, '1.0-3')} BTC<br>`;
|
|
|
|
} else {
|
2023-07-22 15:43:52 +09:00
|
|
|
tooltip += `${tick.marker} ${tick.seriesName}: ${formatNumber(tick.data[1], this.locale, '1.0-0')} sats<br>`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (['24h', '3d'].includes(this.timespan)) {
|
|
|
|
tooltip += `<small>` + $localize`At block: ${data[0].data[2]}` + `</small>`;
|
|
|
|
} else {
|
|
|
|
tooltip += `<small>` + $localize`Around block: ${data[0].data[2]}` + `</small>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tooltip;
|
|
|
|
}.bind(this)
|
|
|
|
},
|
|
|
|
xAxis: data.length === 0 ? undefined :
|
|
|
|
{
|
2023-12-08 13:03:08 +00:00
|
|
|
name: this.widget ? undefined : formatterXAxisLabel(this.locale, this.timespan),
|
|
|
|
nameLocation: 'middle',
|
|
|
|
nameTextStyle: {
|
|
|
|
padding: [10, 0, 0, 0],
|
|
|
|
},
|
|
|
|
type: 'category',
|
|
|
|
boundaryGap: false,
|
|
|
|
axisLine: { onZero: true },
|
2023-07-22 15:43:52 +09:00
|
|
|
axisLabel: {
|
2023-12-08 13:03:08 +00:00
|
|
|
formatter: val => formatterXAxisTimeCategory(this.locale, this.timespan, parseInt(val, 10)),
|
|
|
|
align: 'center',
|
|
|
|
fontSize: 11,
|
|
|
|
lineHeight: 12,
|
2023-07-22 15:43:52 +09:00
|
|
|
hideOverlap: true,
|
2023-12-08 13:03:08 +00:00
|
|
|
padding: [0, 5],
|
|
|
|
},
|
2023-07-22 15:43:52 +09:00
|
|
|
},
|
2023-12-08 13:03:08 +00:00
|
|
|
legend: {
|
2023-07-22 15:43:52 +09:00
|
|
|
data: [
|
|
|
|
{
|
2023-12-08 13:03:08 +00:00
|
|
|
name: 'In-band fees per block',
|
2023-07-22 15:43:52 +09:00
|
|
|
inactiveColor: 'rgb(110, 112, 121)',
|
2023-12-08 13:03:08 +00:00
|
|
|
textStyle: {
|
2023-07-22 15:43:52 +09:00
|
|
|
color: 'white',
|
|
|
|
},
|
|
|
|
icon: 'roundRect',
|
|
|
|
},
|
|
|
|
{
|
2024-01-15 22:52:42 +00:00
|
|
|
name: 'Total bid boost per block',
|
2023-07-22 15:43:52 +09:00
|
|
|
inactiveColor: 'rgb(110, 112, 121)',
|
2023-08-30 22:25:33 +09:00
|
|
|
textStyle: {
|
2023-07-22 15:43:52 +09:00
|
|
|
color: 'white',
|
|
|
|
},
|
|
|
|
icon: 'roundRect',
|
|
|
|
},
|
|
|
|
],
|
2023-12-08 13:03:08 +00:00
|
|
|
selected: {
|
|
|
|
'In-band fees per block': false,
|
2024-01-15 22:52:42 +00:00
|
|
|
'Total bid boost per block': true,
|
2023-12-08 13:03:08 +00:00
|
|
|
},
|
|
|
|
show: !this.widget,
|
2023-07-22 15:43:52 +09:00
|
|
|
},
|
|
|
|
yAxis: data.length === 0 ? undefined : [
|
|
|
|
{
|
|
|
|
type: 'value',
|
|
|
|
axisLabel: {
|
|
|
|
color: 'rgb(110, 112, 121)',
|
|
|
|
formatter: (val) => {
|
2023-12-07 08:26:32 +00:00
|
|
|
if (val >= 100_000) {
|
|
|
|
return `${(val / 100_000_000).toFixed(3)} BTC`;
|
2023-08-30 22:25:33 +09:00
|
|
|
} else {
|
|
|
|
return `${val} sats`;
|
|
|
|
}
|
2023-07-22 15:43:52 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
splitLine: {
|
|
|
|
lineStyle: {
|
|
|
|
type: 'dotted',
|
|
|
|
color: '#ffffff66',
|
|
|
|
opacity: 0.25,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'value',
|
|
|
|
position: 'right',
|
|
|
|
axisLabel: {
|
|
|
|
color: 'rgb(110, 112, 121)',
|
|
|
|
formatter: function(val) {
|
|
|
|
return `${val}`;
|
|
|
|
}.bind(this)
|
|
|
|
},
|
|
|
|
splitLine: {
|
|
|
|
show: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
series: data.length === 0 ? undefined : [
|
2023-08-30 22:25:33 +09:00
|
|
|
{
|
|
|
|
legendHoverLink: false,
|
2023-12-08 13:03:08 +00:00
|
|
|
zlevel: 1,
|
2024-01-15 22:52:42 +00:00
|
|
|
name: 'Total bid boost per block',
|
2023-12-08 13:03:08 +00:00
|
|
|
data: data.map(block => [block.timestamp * 1000, block.avgFeePaid, block.avgHeight]),
|
|
|
|
stack: 'Total',
|
|
|
|
type: 'bar',
|
|
|
|
barWidth: '100%',
|
|
|
|
large: true,
|
2023-08-30 22:25:33 +09:00
|
|
|
},
|
2023-07-22 15:43:52 +09:00
|
|
|
{
|
|
|
|
legendHoverLink: false,
|
2023-12-08 13:03:08 +00:00
|
|
|
zlevel: 0,
|
|
|
|
name: 'In-band fees per block',
|
|
|
|
data: data.map(block => [block.timestamp * 1000, block.avgFees, block.avgHeight]),
|
|
|
|
stack: 'Total',
|
|
|
|
type: 'bar',
|
|
|
|
barWidth: '100%',
|
|
|
|
large: true,
|
2023-07-22 15:43:52 +09:00
|
|
|
},
|
|
|
|
],
|
|
|
|
dataZoom: (this.widget || data.length === 0 )? undefined : [{
|
|
|
|
type: 'inside',
|
|
|
|
realtime: true,
|
|
|
|
zoomLock: true,
|
|
|
|
maxSpan: 100,
|
|
|
|
minSpan: 5,
|
|
|
|
moveOnMouseMove: false,
|
|
|
|
}, {
|
|
|
|
showDetail: false,
|
|
|
|
show: true,
|
|
|
|
type: 'slider',
|
|
|
|
brushSelect: false,
|
|
|
|
realtime: true,
|
|
|
|
left: 20,
|
|
|
|
right: 15,
|
|
|
|
selectedDataBackground: {
|
|
|
|
lineStyle: {
|
|
|
|
color: '#fff',
|
|
|
|
opacity: 0.45,
|
|
|
|
},
|
|
|
|
areaStyle: {
|
|
|
|
opacity: 0,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}],
|
2023-12-08 13:03:08 +00:00
|
|
|
visualMap: {
|
|
|
|
type: 'continuous',
|
|
|
|
min: minValue,
|
|
|
|
max: maxValue,
|
|
|
|
dimension: 1,
|
|
|
|
seriesIndex: 1,
|
|
|
|
show: false,
|
|
|
|
inRange: {
|
|
|
|
color: ['#F4511E7f', '#FB8C007f', '#FFB3007f', '#FDD8357f', '#7CB3427f'].reverse() // Gradient color range
|
|
|
|
}
|
|
|
|
},
|
2023-07-22 15:43:52 +09:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onChartInit(ec) {
|
|
|
|
this.chartInstance = ec;
|
|
|
|
}
|
|
|
|
|
|
|
|
isMobile() {
|
|
|
|
return (window.innerWidth <= 767.98);
|
|
|
|
}
|
|
|
|
|
|
|
|
onSaveChart() {
|
|
|
|
// @ts-ignore
|
|
|
|
const prevBottom = this.chartOptions.grid.bottom;
|
|
|
|
const now = new Date();
|
|
|
|
// @ts-ignore
|
|
|
|
this.chartOptions.grid.bottom = 40;
|
|
|
|
this.chartOptions.backgroundColor = '#11131f';
|
|
|
|
this.chartInstance.setOption(this.chartOptions);
|
|
|
|
download(this.chartInstance.getDataURL({
|
|
|
|
pixelRatio: 2,
|
|
|
|
excludeComponents: ['dataZoom'],
|
|
|
|
}), `acceleration-fees-${this.timespan}-${Math.round(now.getTime() / 1000)}.svg`);
|
|
|
|
// @ts-ignore
|
|
|
|
this.chartOptions.grid.bottom = prevBottom;
|
|
|
|
this.chartOptions.backgroundColor = 'none';
|
|
|
|
this.chartInstance.setOption(this.chartOptions);
|
|
|
|
}
|
2023-12-08 13:03:08 +00:00
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
if (this.statsSubscription) {
|
|
|
|
this.statsSubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
2023-07-22 15:43:52 +09:00
|
|
|
}
|