import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core'; import { StateService } from 'src/app/services/state.service'; import { map, filter } from 'rxjs/operators'; import { merge, 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; isLoadingWebSocket$: Observable; constructor( private stateService: StateService, ) { } ngOnInit(): void { const defaultFee = this.stateService.network === 'liquid' ? 0.1 : 1; this.isLoadingWebSocket$ = this.stateService.isLoadingWebSocket$; this.feeEstimations$ = this.stateService.mempoolBlocks$ .pipe( map((pBlocks) => { if (!pBlocks.length) { return { 'fastestFee': defaultFee, 'halfHourFee': defaultFee, 'hourFee': defaultFee, }; } let firstMedianFee = Math.ceil(pBlocks[0].medianFee); if (pBlocks.length === 1 && pBlocks[0].blockVSize <= 500000) { firstMedianFee = defaultFee; } const secondMedianFee = pBlocks[1] ? Math.ceil(pBlocks[1].medianFee) : defaultFee; const thirdMedianFee = pBlocks[2] ? Math.ceil(pBlocks[2].medianFee) : defaultFee; return { 'fastestFee': firstMedianFee, 'halfHourFee': secondMedianFee, 'hourFee': thirdMedianFee, }; }) ); } }