2020-07-29 10:16:09 +02:00
|
|
|
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
|
|
|
|
import { StateService } from 'src/app/services/state.service';
|
2020-07-29 10:20:23 +02:00
|
|
|
import { map, filter } from 'rxjs/operators';
|
2020-07-29 10:16:09 +02:00
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
|
|
|
|
interface FeeEstimations {
|
|
|
|
fastestFee: number;
|
|
|
|
halfHourFee: number;
|
|
|
|
hourFee: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-fees-box',
|
|
|
|
templateUrl: './fees-box.component.html',
|
|
|
|
styleUrls: ['./fees-box.component.scss'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
|
|
})
|
|
|
|
export class FeesBoxComponent implements OnInit {
|
|
|
|
feeEstimations$: Observable<FeeEstimations>;
|
2020-07-30 08:13:22 +02:00
|
|
|
isLoadingWebSocket$: Observable<boolean>;
|
2020-07-29 10:16:09 +02:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private stateService: StateService,
|
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2020-07-30 08:13:22 +02:00
|
|
|
this.isLoadingWebSocket$ = this.stateService.isLoadingWebSocket$;
|
2020-07-29 10:16:09 +02:00
|
|
|
this.feeEstimations$ = this.stateService.mempoolBlocks$
|
|
|
|
.pipe(
|
2020-07-29 10:20:23 +02:00
|
|
|
filter((blocks) => !!blocks.length),
|
2020-07-29 10:16:09 +02:00
|
|
|
map((pBlocks) => {
|
|
|
|
let firstMedianFee = Math.ceil(pBlocks[0].medianFee);
|
|
|
|
|
|
|
|
if (pBlocks.length === 1 && pBlocks[0].blockVSize <= 500000) {
|
|
|
|
firstMedianFee = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const secondMedianFee = pBlocks[1] ? Math.ceil(pBlocks[1].medianFee) : firstMedianFee;
|
|
|
|
const thirdMedianFee = pBlocks[2] ? Math.ceil(pBlocks[2].medianFee) : secondMedianFee;
|
|
|
|
|
|
|
|
return {
|
|
|
|
'fastestFee': firstMedianFee,
|
|
|
|
'halfHourFee': secondMedianFee,
|
|
|
|
'hourFee': thirdMedianFee,
|
|
|
|
};
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|