From 20fa803cee442c6a8c0f3cf948ab66e07233d5c3 Mon Sep 17 00:00:00 2001 From: Felipe Knorr Kuhn <100320+knorrium@users.noreply.github.com> Date: Tue, 31 Aug 2021 13:04:38 -0700 Subject: [PATCH] Add a potential fix for the memory leak on the Dashboard Fix the broken experience after unsubscribing for network changes Fix the broken experience after unsubscribing for network changes --- .../app/components/amount/amount.component.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/frontend/src/app/components/amount/amount.component.ts b/frontend/src/app/components/amount/amount.component.ts index 7958e8a0b..068acf1a7 100644 --- a/frontend/src/app/components/amount/amount.component.ts +++ b/frontend/src/app/components/amount/amount.component.ts @@ -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 { Observable } from 'rxjs'; +import { Observable, Subscription } from 'rxjs'; @Component({ selector: 'app-amount', @@ -8,11 +8,13 @@ import { Observable } from 'rxjs'; styleUrls: ['./amount.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class AmountComponent implements OnInit { +export class AmountComponent implements OnInit, OnDestroy { conversions$: Observable; viewFiat$: Observable; network = ''; + stateSubscription: Subscription; + @Input() satoshis: number; @Input() digitsInfo = '1.8-8'; @Input() noFiat = false; @@ -24,7 +26,13 @@ export class AmountComponent implements OnInit { ngOnInit() { this.viewFiat$ = this.stateService.viewFiat$.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(); + } } }