2022-01-17 13:33:07 +09:00
|
|
|
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
|
|
|
|
import { combineLatest, Observable, timer } from 'rxjs';
|
|
|
|
import { map, switchMap } from 'rxjs/operators';
|
|
|
|
import { StateService } from '../..//services/state.service';
|
|
|
|
|
|
|
|
interface EpochProgress {
|
|
|
|
base: string;
|
|
|
|
change: number;
|
2022-03-12 14:55:42 +01:00
|
|
|
progress: number;
|
2022-01-17 13:33:07 +09:00
|
|
|
remainingBlocks: number;
|
|
|
|
newDifficultyHeight: number;
|
|
|
|
colorAdjustments: string;
|
|
|
|
colorPreviousAdjustments: string;
|
|
|
|
remainingTime: number;
|
|
|
|
previousRetarget: number;
|
2022-01-17 15:34:34 +09:00
|
|
|
blocksUntilHalving: number;
|
|
|
|
timeUntilHalving: number;
|
2022-01-17 13:33:07 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-difficulty',
|
|
|
|
templateUrl: './difficulty.component.html',
|
|
|
|
styleUrls: ['./difficulty.component.scss'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
|
|
})
|
|
|
|
export class DifficultyComponent implements OnInit {
|
|
|
|
isLoadingWebSocket$: Observable<boolean>;
|
|
|
|
difficultyEpoch$: Observable<EpochProgress>;
|
|
|
|
|
2022-02-28 17:31:10 +09:00
|
|
|
@Input() showProgress = true;
|
|
|
|
@Input() showHalving = false;
|
|
|
|
@Input() showTitle = true;
|
2022-01-17 15:34:34 +09:00
|
|
|
|
2022-01-17 13:33:07 +09:00
|
|
|
constructor(
|
|
|
|
public stateService: StateService,
|
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.isLoadingWebSocket$ = this.stateService.isLoadingWebSocket$;
|
2022-03-12 14:55:42 +01:00
|
|
|
this.difficultyEpoch$ = combineLatest([
|
|
|
|
this.stateService.blocks$.pipe(map(([block]) => block)),
|
|
|
|
this.stateService.difficultyAdjustment$,
|
|
|
|
])
|
|
|
|
.pipe(
|
|
|
|
map(([block, da]) => {
|
|
|
|
let colorAdjustments = '#ffffff66';
|
|
|
|
if (da.difficultyChange > 0) {
|
|
|
|
colorAdjustments = '#3bcc49';
|
|
|
|
}
|
|
|
|
if (da.difficultyChange < 0) {
|
|
|
|
colorAdjustments = '#dc3545';
|
|
|
|
}
|
2022-01-17 13:33:07 +09:00
|
|
|
|
2022-03-12 14:55:42 +01:00
|
|
|
let colorPreviousAdjustments = '#dc3545';
|
|
|
|
if (da.previousRetarget) {
|
|
|
|
if (da.previousRetarget >= 0) {
|
|
|
|
colorPreviousAdjustments = '#3bcc49';
|
2022-01-17 13:33:07 +09:00
|
|
|
}
|
2022-03-12 14:55:42 +01:00
|
|
|
if (da.previousRetarget === 0) {
|
2022-01-17 13:33:07 +09:00
|
|
|
colorPreviousAdjustments = '#ffffff66';
|
|
|
|
}
|
2022-03-12 14:55:42 +01:00
|
|
|
} else {
|
|
|
|
colorPreviousAdjustments = '#ffffff66';
|
|
|
|
}
|
2022-01-17 13:33:07 +09:00
|
|
|
|
2022-03-12 14:55:42 +01:00
|
|
|
const blocksUntilHalving = 210000 - (block.height % 210000);
|
2022-03-21 12:16:41 +09:00
|
|
|
const timeUntilHalving = new Date().getTime() + (blocksUntilHalving * 600000);
|
2022-01-17 15:34:34 +09:00
|
|
|
|
2022-03-12 14:55:42 +01:00
|
|
|
const data = {
|
|
|
|
base: `${da.progressPercent.toFixed(2)}%`,
|
|
|
|
change: da.difficultyChange,
|
|
|
|
progress: da.progressPercent,
|
|
|
|
remainingBlocks: da.remainingBlocks,
|
|
|
|
colorAdjustments,
|
|
|
|
colorPreviousAdjustments,
|
|
|
|
newDifficultyHeight: da.nextRetargetHeight,
|
|
|
|
remainingTime: da.remainingTime,
|
|
|
|
previousRetarget: da.previousRetarget,
|
|
|
|
blocksUntilHalving,
|
|
|
|
timeUntilHalving,
|
|
|
|
};
|
|
|
|
return data;
|
|
|
|
})
|
|
|
|
);
|
2022-01-17 13:33:07 +09:00
|
|
|
}
|
|
|
|
}
|