2023-01-16 11:05:30 -06:00
|
|
|
import { Component, OnInit, OnDestroy, Input, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
|
2020-02-16 22:15:07 +07:00
|
|
|
import { StateService } from '../../services/state.service';
|
2021-08-31 13:04:38 -07:00
|
|
|
import { Observable, Subscription } from 'rxjs';
|
2023-02-28 10:59:39 +09:00
|
|
|
import { Price } from '../../services/price.service';
|
2020-02-16 22:15:07 +07:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-amount',
|
|
|
|
templateUrl: './amount.component.html',
|
|
|
|
styleUrls: ['./amount.component.scss'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
|
|
})
|
2021-08-31 13:04:38 -07:00
|
|
|
export class AmountComponent implements OnInit, OnDestroy {
|
2020-02-16 22:15:07 +07:00
|
|
|
conversions$: Observable<any>;
|
2023-01-16 11:05:30 -06:00
|
|
|
currency: string;
|
2024-04-24 15:52:36 +02:00
|
|
|
viewAmountMode$: Observable<'btc' | 'sats' | 'fiat'>;
|
2020-05-09 20:37:50 +07:00
|
|
|
network = '';
|
2020-02-16 22:15:07 +07:00
|
|
|
|
2021-08-31 13:04:38 -07:00
|
|
|
stateSubscription: Subscription;
|
2023-01-16 11:05:30 -06:00
|
|
|
currencySubscription: Subscription;
|
2021-08-31 13:04:38 -07:00
|
|
|
|
2020-02-16 22:15:07 +07:00
|
|
|
@Input() satoshis: number;
|
2020-05-09 20:37:50 +07:00
|
|
|
@Input() digitsInfo = '1.8-8';
|
2020-05-10 21:34:25 +07:00
|
|
|
@Input() noFiat = false;
|
2022-03-06 13:50:01 +01:00
|
|
|
@Input() addPlus = false;
|
2023-02-21 12:36:43 +09:00
|
|
|
@Input() blockConversion: Price;
|
2024-01-21 13:33:20 +01:00
|
|
|
@Input() forceBtc: boolean = false;
|
2024-06-26 10:48:17 +09:00
|
|
|
@Input() ignoreViewMode: boolean = false;
|
2024-03-17 16:25:36 +09:00
|
|
|
@Input() forceBlockConversion: boolean = false; // true = displays fiat price as 0 if blockConversion is undefined instead of falling back to conversions
|
2020-02-16 22:15:07 +07:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private stateService: StateService,
|
2023-01-16 11:05:30 -06:00
|
|
|
private cd: ChangeDetectorRef,
|
|
|
|
) {
|
|
|
|
this.currencySubscription = this.stateService.fiatCurrency$.subscribe((fiat) => {
|
|
|
|
this.currency = fiat;
|
|
|
|
this.cd.markForCheck();
|
|
|
|
});
|
|
|
|
}
|
2020-02-16 22:15:07 +07:00
|
|
|
|
|
|
|
ngOnInit() {
|
2024-04-24 15:52:36 +02:00
|
|
|
this.viewAmountMode$ = this.stateService.viewAmountMode$.asObservable();
|
2020-02-16 22:15:07 +07:00
|
|
|
this.conversions$ = this.stateService.conversions$.asObservable();
|
2021-08-31 13:04:38 -07:00
|
|
|
this.stateSubscription = this.stateService.networkChanged$.subscribe((network) => this.network = network);
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
if (this.stateSubscription) {
|
|
|
|
this.stateSubscription.unsubscribe();
|
|
|
|
}
|
2023-01-16 11:05:30 -06:00
|
|
|
this.currencySubscription.unsubscribe();
|
2020-02-16 22:15:07 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|