import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core'; import { StateService } from 'src/app/services/state.service'; import { Observable } from 'rxjs'; import { Recommendedfees } from 'src/app/interfaces/websocket.interface'; import { feeLevels, mempoolFeeColors } from 'src/app/app.constants'; import { tap } from 'rxjs/operators'; @Component({ selector: 'app-fees-box', templateUrl: './fees-box.component.html', styleUrls: ['./fees-box.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush, }) export class FeesBoxComponent implements OnInit { isLoadingWebSocket$: Observable; recommendedFees$: Observable; gradient = 'linear-gradient(to right, #2e324e, #2e324e)'; constructor( private stateService: StateService ) { } ngOnInit(): void { this.isLoadingWebSocket$ = this.stateService.isLoadingWebSocket$; this.recommendedFees$ = this.stateService.recommendedFees$ .pipe( tap((fees) => { let feeLevelIndex = feeLevels.slice().reverse().findIndex((feeLvl) => fees.minimumFee >= feeLvl); feeLevelIndex = feeLevelIndex >= 0 ? feeLevels.length - feeLevelIndex : feeLevelIndex; const startColor = '#' + (mempoolFeeColors[feeLevelIndex - 1] || mempoolFeeColors[mempoolFeeColors.length - 1]); feeLevelIndex = feeLevels.slice().reverse().findIndex((feeLvl) => fees.fastestFee >= feeLvl); feeLevelIndex = feeLevelIndex >= 0 ? feeLevels.length - feeLevelIndex : feeLevelIndex; const endColor = '#' + (mempoolFeeColors[feeLevelIndex - 1] || mempoolFeeColors[mempoolFeeColors.length - 1]); this.gradient = `linear-gradient(to right, ${startColor}, ${endColor})`; } ) ); } }