2022-03-08 12:50:47 +01:00
|
|
|
import { ChangeDetectionStrategy, Component, Inject, Input, LOCALE_ID, OnInit } from '@angular/core';
|
2022-02-09 19:41:05 +09:00
|
|
|
import { ActivatedRoute } from '@angular/router';
|
2022-03-08 12:50:47 +01:00
|
|
|
import { EChartsOption, graphic } from 'echarts';
|
2022-03-22 17:19:34 +09:00
|
|
|
import { BehaviorSubject, Observable, timer } from 'rxjs';
|
2022-03-16 19:17:33 +01:00
|
|
|
import { map, switchMap, tap } from 'rxjs/operators';
|
2022-02-09 19:41:05 +09:00
|
|
|
import { BlockExtended, PoolStat } from 'src/app/interfaces/node-api.interface';
|
|
|
|
import { ApiService } from 'src/app/services/api.service';
|
|
|
|
import { StateService } from 'src/app/services/state.service';
|
2022-03-08 12:50:47 +01:00
|
|
|
import { selectPowerOfTen } from 'src/app/bitcoin.utils';
|
|
|
|
import { formatNumber } from '@angular/common';
|
2022-02-08 18:56:51 +09:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-pool',
|
|
|
|
templateUrl: './pool.component.html',
|
2022-02-15 18:36:58 +09:00
|
|
|
styleUrls: ['./pool.component.scss'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
2022-02-08 18:56:51 +09:00
|
|
|
})
|
|
|
|
export class PoolComponent implements OnInit {
|
2022-03-08 12:50:47 +01:00
|
|
|
@Input() right: number | string = 45;
|
|
|
|
@Input() left: number | string = 75;
|
|
|
|
|
2022-03-09 16:30:45 +01:00
|
|
|
formatNumber = formatNumber;
|
2022-02-09 19:41:05 +09:00
|
|
|
poolStats$: Observable<PoolStat>;
|
2022-02-10 19:16:00 +09:00
|
|
|
blocks$: Observable<BlockExtended[]>;
|
2022-03-08 12:50:47 +01:00
|
|
|
isLoading = true;
|
|
|
|
|
|
|
|
chartOptions: EChartsOption = {};
|
|
|
|
chartInitOptions = {
|
|
|
|
renderer: 'svg',
|
|
|
|
width: 'auto',
|
|
|
|
height: 'auto',
|
|
|
|
};
|
2022-02-09 19:41:05 +09:00
|
|
|
|
2022-02-10 19:16:00 +09:00
|
|
|
blocks: BlockExtended[] = [];
|
|
|
|
poolId: number = undefined;
|
2022-02-09 19:41:05 +09:00
|
|
|
|
2022-03-22 17:19:34 +09:00
|
|
|
loadMoreSubject: BehaviorSubject<number> = new BehaviorSubject(this.poolId);
|
|
|
|
|
2022-02-08 18:56:51 +09:00
|
|
|
constructor(
|
2022-03-08 12:50:47 +01:00
|
|
|
@Inject(LOCALE_ID) public locale: string,
|
2022-02-09 19:41:05 +09:00
|
|
|
private apiService: ApiService,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
public stateService: StateService,
|
2022-02-10 19:16:00 +09:00
|
|
|
) {
|
|
|
|
}
|
2022-02-08 18:56:51 +09:00
|
|
|
|
|
|
|
ngOnInit(): void {
|
2022-03-08 13:54:04 +01:00
|
|
|
this.poolStats$ = this.route.params.pipe(map((params) => params.poolId))
|
2022-02-09 19:41:05 +09:00
|
|
|
.pipe(
|
2022-03-08 13:54:04 +01:00
|
|
|
switchMap((poolId: any) => {
|
2022-03-08 18:58:19 +01:00
|
|
|
this.isLoading = true;
|
2022-03-08 13:54:04 +01:00
|
|
|
this.poolId = poolId;
|
2022-03-22 17:19:34 +09:00
|
|
|
this.loadMoreSubject.next(this.poolId);
|
2022-03-08 13:54:04 +01:00
|
|
|
return this.apiService.getPoolHashrate$(this.poolId)
|
2022-03-08 12:50:47 +01:00
|
|
|
.pipe(
|
|
|
|
switchMap((data) => {
|
2022-03-08 20:29:09 +01:00
|
|
|
this.isLoading = false;
|
2022-03-08 12:50:47 +01:00
|
|
|
this.prepareChartOptions(data.hashrates.map(val => [val.timestamp * 1000, val.avgHashrate]));
|
2022-03-08 13:54:04 +01:00
|
|
|
return poolId;
|
2022-03-08 12:50:47 +01:00
|
|
|
}),
|
2022-03-16 19:17:33 +01:00
|
|
|
);
|
2022-03-08 12:50:47 +01:00
|
|
|
}),
|
2022-03-08 13:54:04 +01:00
|
|
|
switchMap(() => {
|
|
|
|
return this.apiService.getPoolStats$(this.poolId);
|
2022-02-09 19:41:05 +09:00
|
|
|
}),
|
2022-02-11 18:29:38 +09:00
|
|
|
map((poolStats) => {
|
2022-02-11 19:10:29 +09:00
|
|
|
let regexes = '"';
|
2022-02-15 18:45:53 +09:00
|
|
|
for (const regex of poolStats.pool.regexes) {
|
2022-02-11 19:10:29 +09:00
|
|
|
regexes += regex + '", "';
|
|
|
|
}
|
|
|
|
poolStats.pool.regexes = regexes.slice(0, -3);
|
2022-02-15 18:45:53 +09:00
|
|
|
poolStats.pool.addresses = poolStats.pool.addresses;
|
2022-02-11 19:10:29 +09:00
|
|
|
|
2022-02-11 18:29:38 +09:00
|
|
|
return Object.assign({
|
|
|
|
logo: `./resources/mining-pools/` + poolStats.pool.name.toLowerCase().replace(' ', '').replace('.', '') + '.svg'
|
|
|
|
}, poolStats);
|
|
|
|
})
|
2022-02-09 19:41:05 +09:00
|
|
|
);
|
|
|
|
|
2022-03-16 19:17:33 +01:00
|
|
|
this.blocks$ = this.loadMoreSubject
|
2022-02-10 19:16:00 +09:00
|
|
|
.pipe(
|
2022-03-16 19:17:33 +01:00
|
|
|
switchMap((flag) => {
|
2022-03-22 17:19:34 +09:00
|
|
|
if (this.poolId === undefined) {
|
|
|
|
return [];
|
|
|
|
}
|
2022-03-16 19:17:33 +01:00
|
|
|
return this.apiService.getPoolBlocks$(this.poolId, this.blocks[this.blocks.length - 1]?.height);
|
2022-02-10 19:16:00 +09:00
|
|
|
}),
|
|
|
|
tap((newBlocks) => {
|
|
|
|
this.blocks = this.blocks.concat(newBlocks);
|
|
|
|
}),
|
|
|
|
map(() => this.blocks)
|
2022-03-16 19:17:33 +01:00
|
|
|
);
|
2022-02-10 19:16:00 +09:00
|
|
|
}
|
2022-02-09 19:41:05 +09:00
|
|
|
|
2022-03-08 12:50:47 +01:00
|
|
|
prepareChartOptions(data) {
|
|
|
|
this.chartOptions = {
|
|
|
|
animation: false,
|
|
|
|
color: [
|
|
|
|
new graphic.LinearGradient(0, 0, 0, 0.65, [
|
|
|
|
{ offset: 0, color: '#F4511E' },
|
|
|
|
{ offset: 0.25, color: '#FB8C00' },
|
|
|
|
{ offset: 0.5, color: '#FFB300' },
|
|
|
|
{ offset: 0.75, color: '#FDD835' },
|
|
|
|
{ offset: 1, color: '#7CB342' }
|
|
|
|
]),
|
|
|
|
'#D81B60',
|
|
|
|
],
|
|
|
|
grid: {
|
|
|
|
right: this.right,
|
|
|
|
left: this.left,
|
|
|
|
bottom: 60,
|
|
|
|
},
|
|
|
|
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',
|
2022-03-16 19:17:33 +01:00
|
|
|
formatter: function(ticks: any[]) {
|
2022-03-08 12:50:47 +01:00
|
|
|
let hashratePowerOfTen: any = selectPowerOfTen(1);
|
2022-03-16 19:17:33 +01:00
|
|
|
let hashrate = ticks[0].data[1];
|
2022-03-08 12:50:47 +01:00
|
|
|
|
|
|
|
if (this.isMobile()) {
|
2022-03-16 19:17:33 +01:00
|
|
|
hashratePowerOfTen = selectPowerOfTen(ticks[0].data[1]);
|
|
|
|
hashrate = Math.round(ticks[0].data[1] / hashratePowerOfTen.divider);
|
2022-03-08 12:50:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return `
|
2022-03-16 19:17:33 +01:00
|
|
|
<b style="color: white; margin-left: 18px">${ticks[0].axisValueLabel}</b><br>
|
|
|
|
<span>${ticks[0].marker} ${ticks[0].seriesName}: ${formatNumber(hashrate, this.locale, '1.0-0')} ${hashratePowerOfTen.unit}H/s</span><br>
|
2022-03-08 12:50:47 +01:00
|
|
|
`;
|
|
|
|
}.bind(this)
|
|
|
|
},
|
|
|
|
xAxis: {
|
|
|
|
type: 'time',
|
|
|
|
splitNumber: (this.isMobile()) ? 5 : 10,
|
|
|
|
},
|
|
|
|
yAxis: [
|
|
|
|
{
|
2022-03-16 17:00:06 +01:00
|
|
|
min: (value) => {
|
2022-03-08 12:50:47 +01:00
|
|
|
return value.min * 0.9;
|
|
|
|
},
|
|
|
|
type: 'value',
|
|
|
|
axisLabel: {
|
|
|
|
color: 'rgb(110, 112, 121)',
|
|
|
|
formatter: (val) => {
|
|
|
|
const selectedPowerOfTen: any = selectPowerOfTen(val);
|
|
|
|
const newVal = Math.round(val / selectedPowerOfTen.divider);
|
|
|
|
return `${newVal} ${selectedPowerOfTen.unit}H/s`
|
|
|
|
}
|
|
|
|
},
|
|
|
|
splitLine: {
|
|
|
|
show: false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
],
|
|
|
|
series: [
|
|
|
|
{
|
|
|
|
name: 'Hashrate',
|
|
|
|
showSymbol: false,
|
|
|
|
symbol: 'none',
|
|
|
|
data: data,
|
|
|
|
type: 'line',
|
|
|
|
lineStyle: {
|
|
|
|
width: 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
isMobile() {
|
|
|
|
return (window.innerWidth <= 767.98);
|
|
|
|
}
|
|
|
|
|
2022-02-10 19:16:00 +09:00
|
|
|
loadMore() {
|
2022-03-22 17:19:34 +09:00
|
|
|
this.loadMoreSubject.next(this.poolId);
|
2022-02-09 19:41:05 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
trackByBlock(index: number, block: BlockExtended) {
|
|
|
|
return block.height;
|
2022-02-08 18:56:51 +09:00
|
|
|
}
|
|
|
|
}
|