2022-03-09 21:21:44 +01:00
|
|
|
import { Component, Inject, LOCALE_ID, OnInit } from '@angular/core';
|
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { map } from 'rxjs/operators';
|
|
|
|
import { ApiService } from 'src/app/services/api.service';
|
|
|
|
import { formatNumber } from '@angular/common';
|
|
|
|
import { selectPowerOfTen } from 'src/app/bitcoin.utils';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-difficulty-adjustments-table',
|
|
|
|
templateUrl: './difficulty-adjustments-table.component.html',
|
|
|
|
styleUrls: ['./difficulty-adjustments-table.component.scss'],
|
|
|
|
styles: [`
|
|
|
|
.loadingGraphs {
|
|
|
|
position: absolute;
|
|
|
|
top: 50%;
|
|
|
|
left: calc(50% - 15px);
|
|
|
|
z-index: 100;
|
|
|
|
}
|
|
|
|
`],
|
|
|
|
})
|
|
|
|
export class DifficultyAdjustmentsTable implements OnInit {
|
|
|
|
hashrateObservable$: Observable<any>;
|
|
|
|
isLoading = true;
|
|
|
|
formatNumber = formatNumber;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
@Inject(LOCALE_ID) public locale: string,
|
|
|
|
private apiService: ApiService,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.hashrateObservable$ = this.apiService.getHistoricalHashrate$('1y')
|
|
|
|
.pipe(
|
2022-04-15 20:43:10 +09:00
|
|
|
map((response) => {
|
|
|
|
const data = response.body;
|
2022-03-09 21:21:44 +01:00
|
|
|
const tableData = [];
|
|
|
|
for (let i = data.difficulty.length - 1; i > 0; --i) {
|
|
|
|
const selectedPowerOfTen: any = selectPowerOfTen(data.difficulty[i].difficulty);
|
|
|
|
const change = (data.difficulty[i].difficulty / data.difficulty[i - 1].difficulty - 1) * 100;
|
|
|
|
|
|
|
|
tableData.push(Object.assign(data.difficulty[i], {
|
2022-03-13 11:37:56 +01:00
|
|
|
change: Math.round(change * 100) / 100,
|
2022-03-09 21:21:44 +01:00
|
|
|
difficultyShorten: formatNumber(
|
|
|
|
data.difficulty[i].difficulty / selectedPowerOfTen.divider,
|
|
|
|
this.locale, '1.2-2') + selectedPowerOfTen.unit
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
this.isLoading = false;
|
|
|
|
|
|
|
|
return {
|
2022-05-12 17:05:31 +02:00
|
|
|
difficulty: tableData.slice(0, 6),
|
2022-03-09 21:21:44 +01:00
|
|
|
};
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
isMobile() {
|
|
|
|
return (window.innerWidth <= 767.98);
|
|
|
|
}
|
|
|
|
}
|