Merge pull request #755 from knorrium/fix_dashboard_memory_leak

Add a potential fix for the memory leak on the Dashboard
This commit is contained in:
wiz 2021-09-02 19:12:42 +09:00 committed by GitHub
commit ad6503c7b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,6 @@
import { Component, OnInit, Input, ChangeDetectionStrategy } from '@angular/core'; import { Component, OnInit, OnDestroy, Input, ChangeDetectionStrategy } from '@angular/core';
import { StateService } from '../../services/state.service'; import { StateService } from '../../services/state.service';
import { Observable } from 'rxjs'; import { Observable, Subscription } from 'rxjs';
@Component({ @Component({
selector: 'app-amount', selector: 'app-amount',
@ -8,11 +8,13 @@ import { Observable } from 'rxjs';
styleUrls: ['./amount.component.scss'], styleUrls: ['./amount.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
}) })
export class AmountComponent implements OnInit { export class AmountComponent implements OnInit, OnDestroy {
conversions$: Observable<any>; conversions$: Observable<any>;
viewFiat$: Observable<boolean>; viewFiat$: Observable<boolean>;
network = ''; network = '';
stateSubscription: Subscription;
@Input() satoshis: number; @Input() satoshis: number;
@Input() digitsInfo = '1.8-8'; @Input() digitsInfo = '1.8-8';
@Input() noFiat = false; @Input() noFiat = false;
@ -24,7 +26,13 @@ export class AmountComponent implements OnInit {
ngOnInit() { ngOnInit() {
this.viewFiat$ = this.stateService.viewFiat$.asObservable(); this.viewFiat$ = this.stateService.viewFiat$.asObservable();
this.conversions$ = this.stateService.conversions$.asObservable(); this.conversions$ = this.stateService.conversions$.asObservable();
this.stateService.networkChanged$.subscribe((network) => this.network = network); this.stateSubscription = this.stateService.networkChanged$.subscribe((network) => this.network = network);
}
ngOnDestroy() {
if (this.stateSubscription) {
this.stateSubscription.unsubscribe();
}
} }
} }