mempool/frontend/src/app/components/fees-box/fees-box.component.ts

52 lines
2.4 KiB
TypeScript
Raw Normal View History

import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
2022-09-21 17:23:45 +02:00
import { StateService } from '../../services/state.service';
2022-05-31 22:31:01 +02:00
import { Observable } from 'rxjs';
2022-09-21 17:23:45 +02:00
import { Recommendedfees } from '../../interfaces/websocket.interface';
import { feeLevels, mempoolFeeColors } from '../../app.constants';
2022-05-31 22:31:01 +02:00
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 {
2020-07-30 13:13:22 +07:00
isLoadingWebSocket$: Observable<boolean>;
recommendedFees$: Observable<Recommendedfees>;
gradient = 'linear-gradient(to right, #2e324e, #2e324e)';
2022-06-02 17:44:44 +02:00
noPriority = '#2e324e';
constructor(
private stateService: StateService
) { }
ngOnInit(): void {
2020-07-30 13:13:22 +07:00
this.isLoadingWebSocket$ = this.stateService.isLoadingWebSocket$;
2022-05-31 22:31:01 +02:00
this.recommendedFees$ = this.stateService.recommendedFees$
.pipe(
tap((fees) => {
2023-05-08 13:06:56 -06:00
let feeLevelIndex = feeLevels.slice().reverse().findIndex((feeLvl) => fees.economyFee >= feeLvl);
2022-05-31 22:31:01 +02:00
feeLevelIndex = feeLevelIndex >= 0 ? feeLevels.length - feeLevelIndex : feeLevelIndex;
const startColor = '#' + (mempoolFeeColors[feeLevelIndex - 1] || mempoolFeeColors[mempoolFeeColors.length - 1]);
2022-05-31 22:31:01 +02:00
2023-05-08 13:06:56 -06:00
feeLevelIndex = feeLevels.slice().reverse().findIndex((feeLvl) => fees.hourFee >= feeLvl);
feeLevelIndex = feeLevelIndex >= 0 ? feeLevels.length - feeLevelIndex : feeLevelIndex;
const lowColor = '#' + (mempoolFeeColors[feeLevelIndex - 1] || mempoolFeeColors[mempoolFeeColors.length - 1]);
feeLevelIndex = feeLevels.slice().reverse().findIndex((feeLvl) => fees.halfHourFee >= feeLvl);
feeLevelIndex = feeLevelIndex >= 0 ? feeLevels.length - feeLevelIndex : feeLevelIndex;
const medColor = '#' + (mempoolFeeColors[feeLevelIndex - 1] || mempoolFeeColors[mempoolFeeColors.length - 1]);
2022-05-31 22:31:01 +02:00
feeLevelIndex = feeLevels.slice().reverse().findIndex((feeLvl) => fees.fastestFee >= feeLvl);
feeLevelIndex = feeLevelIndex >= 0 ? feeLevels.length - feeLevelIndex : feeLevelIndex;
2023-05-08 13:06:56 -06:00
const highColor = '#' + (mempoolFeeColors[feeLevelIndex - 1] || mempoolFeeColors[mempoolFeeColors.length - 1]);
2023-05-08 13:06:56 -06:00
this.gradient = `linear-gradient(to right, ${lowColor} 0%, ${medColor} 50%, ${highColor} 100%)`;
2022-06-02 17:44:44 +02:00
this.noPriority = startColor;
2022-05-31 22:31:01 +02:00
}
)
);
}
}