mirror of
https://github.com/mempool/mempool.git
synced 2025-03-01 01:00:00 +01:00
Fix the broken experience after unsubscribing for network changes Fix the broken experience after unsubscribing for network changes
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { Component, OnInit, OnDestroy, Input, ChangeDetectionStrategy } from '@angular/core';
|
|
import { StateService } from '../../services/state.service';
|
|
import { Observable, Subscription } from 'rxjs';
|
|
|
|
@Component({
|
|
selector: 'app-amount',
|
|
templateUrl: './amount.component.html',
|
|
styleUrls: ['./amount.component.scss'],
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
})
|
|
export class AmountComponent implements OnInit, OnDestroy {
|
|
conversions$: Observable<any>;
|
|
viewFiat$: Observable<boolean>;
|
|
network = '';
|
|
|
|
stateSubscription: Subscription;
|
|
|
|
@Input() satoshis: number;
|
|
@Input() digitsInfo = '1.8-8';
|
|
@Input() noFiat = false;
|
|
|
|
constructor(
|
|
private stateService: StateService,
|
|
) { }
|
|
|
|
ngOnInit() {
|
|
this.viewFiat$ = this.stateService.viewFiat$.asObservable();
|
|
this.conversions$ = this.stateService.conversions$.asObservable();
|
|
this.stateSubscription = this.stateService.networkChanged$.subscribe((network) => this.network = network);
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
if (this.stateSubscription) {
|
|
this.stateSubscription.unsubscribe();
|
|
}
|
|
}
|
|
|
|
}
|