2020-07-29 15:16:09 +07:00
|
|
|
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
|
|
|
|
import { StateService } from 'src/app/services/state.service';
|
2022-05-31 22:31:01 +02:00
|
|
|
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';
|
2020-07-29 15:16:09 +07:00
|
|
|
|
|
|
|
@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>;
|
2022-05-27 12:52:40 +02:00
|
|
|
recommendedFees$: Observable<Recommendedfees>;
|
2020-10-05 11:42:54 +07:00
|
|
|
defaultFee: number;
|
2022-05-31 22:31:01 +02:00
|
|
|
startColor = '#557d00';
|
|
|
|
endColor = '#557d00';
|
2020-07-29 15:16:09 +07:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private stateService: StateService,
|
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2021-12-27 22:54:45 +04:00
|
|
|
this.defaultFee = this.stateService.network === 'liquid' || this.stateService.network === 'liquidtestnet' ? 0.1 : 1;
|
2020-09-27 18:12:36 +07:00
|
|
|
|
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) => {
|
|
|
|
// fees.fastestFee = 400;
|
|
|
|
// fees.halfHourFee = 75;
|
|
|
|
// fees.hourFee = 50;
|
|
|
|
// fees.economyFee = 40;
|
|
|
|
// fees.minimumFee = 5;
|
|
|
|
|
|
|
|
let feeLevelIndex = feeLevels.slice().reverse().findIndex((feeLvl) => fees.minimumFee >= feeLvl);
|
|
|
|
feeLevelIndex = feeLevelIndex >= 0 ? feeLevels.length - feeLevelIndex : feeLevelIndex;
|
|
|
|
this.startColor = '#' + (mempoolFeeColors[feeLevelIndex - 1] || mempoolFeeColors[mempoolFeeColors.length - 1]);
|
|
|
|
|
|
|
|
feeLevelIndex = feeLevels.slice().reverse().findIndex((feeLvl) => fees.fastestFee >= feeLvl);
|
|
|
|
feeLevelIndex = feeLevelIndex >= 0 ? feeLevels.length - feeLevelIndex : feeLevelIndex;
|
|
|
|
this.endColor = '#' + (mempoolFeeColors[feeLevelIndex - 1] || mempoolFeeColors[mempoolFeeColors.length - 1]);
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2020-07-29 15:16:09 +07:00
|
|
|
}
|
|
|
|
}
|