Commit 3691f0e7 authored by Olivia Madrid's avatar Olivia Madrid

dont detect changes on destroyed views

1 merge request!686WIP: Epic/wallet 80
Pipeline #116007640 passed with stages
in 90 minutes and 21 seconds
......@@ -7,8 +7,8 @@ import {
ViewChild,
ElementRef,
HostListener,
ViewRef,
} from '@angular/core';
import { Subscription } from 'rxjs';
import { Inject, PLATFORM_ID } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { horizontallyScrollElementIntoView } from '../../../helpers/scrollable-container-visibility';
......@@ -29,8 +29,6 @@ export class ShadowboxHeaderComponent implements AfterViewInit {
firstMetricEl;
activeMetricEl;
tabsSubscription: Subscription;
tabsArray;
childClientWidth: number;
......@@ -116,7 +114,9 @@ export class ShadowboxHeaderComponent implements AfterViewInit {
this.container.scrollLeft >= 0 &&
!this.isAtScrollEnd;
}
this.detectChanges();
if (!(this.cd as ViewRef).destroyed) {
this.detectChanges();
}
}
slide(direction) {
......
......@@ -6,18 +6,20 @@ import {
Input,
Output,
EventEmitter,
OnDestroy,
} from '@angular/core';
import { Client } from '../../../../services/api/client';
import { Session } from '../../../../services/session';
import { WalletDashboardService } from '../dashboard.service';
import { ActivatedRoute, ParamMap } from '@angular/router';
import * as moment from 'moment';
import { Subscription } from 'rxjs';
@Component({
selector: 'm-walletBalance--cash',
templateUrl: './balance-cash.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class WalletBalanceCashComponent implements OnInit {
export class WalletBalanceCashComponent implements OnInit, OnDestroy {
inProgress: boolean = true;
stripeAccount;
hasAccount: boolean = true;
......@@ -26,6 +28,7 @@ export class WalletBalanceCashComponent implements OnInit {
nextPayoutDate = '';
onSettingsTab: boolean = false;
currency = 'usd';
paramsSubscription: Subscription;
@Output() scrollToCashSettings: EventEmitter<any> = new EventEmitter();
constructor(
......@@ -37,14 +40,22 @@ export class WalletBalanceCashComponent implements OnInit {
) {}
ngOnInit() {
this.route.paramMap.subscribe((params: ParamMap) => {
this.onSettingsTab = params.get('view') === 'settings';
this.detectChanges();
});
this.paramsSubscription = this.route.paramMap.subscribe(
(params: ParamMap) => {
this.onSettingsTab = params.get('view') === 'settings';
this.detectChanges();
}
);
this.load();
}
ngOnDestroy() {
if (this.paramsSubscription) {
this.paramsSubscription.unsubscribe();
}
}
async load() {
// TODOOJM $stripe - this is not accurate for all stripe accounts
this.nextPayoutDate = moment()
......
......@@ -10,7 +10,6 @@ import {
} from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { Client } from '../../../../services/api/client';
import { Subscription } from 'rxjs';
import { Session } from '../../../../services/session';
import { WalletDashboardService } from '../dashboard.service';
import { FormToastService } from '../../../../common/services/form-toast.service';
......@@ -39,7 +38,6 @@ export class WalletBalanceTokensV2Component implements OnInit, OnDestroy {
.format('h:mma');
nextPayoutDate = 0;
estimatedTokenPayout;
payoutSubscription: Subscription;
constructor(
protected client: Client,
protected cd: ChangeDetectorRef,
......@@ -70,9 +68,6 @@ export class WalletBalanceTokensV2Component implements OnInit, OnDestroy {
if (this.updateTimer$) {
clearInterval(this.updateTimer$);
}
if (this.payoutSubscription) {
this.payoutSubscription.unsubscribe();
}
}
async getPayout() {
......
......@@ -8,6 +8,7 @@ import {
ViewChild,
ElementRef,
AfterViewInit,
OnDestroy,
} from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
......@@ -25,7 +26,7 @@ import { FeaturesService } from '../../../services/features.service';
templateUrl: './dashboard.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class WalletDashboardComponent implements OnInit {
export class WalletDashboardComponent implements OnInit, OnDestroy {
@ViewChild('tokensSettings', { static: false }) tokenSettingsEl: ElementRef;
@ViewChild('cashSettings', { static: false }) cashSettingsEl: ElementRef;
@ViewChild('dashboardViews', { static: false })
......@@ -79,31 +80,39 @@ export class WalletDashboardComponent implements OnInit {
this.wallet = this.walletService.getWallet();
this.route.paramMap.subscribe((params: ParamMap) => {
const currencyParam = params.get('currency');
const viewParam = params.get('view');
this.activeCurrencyId = currencyParam;
if (!this.views[this.activeCurrencyId]) {
this.activeCurrencyId = 'tokens';
this.router.navigate(['/wallet/tokens']);
}
if (
viewParam &&
this.views[this.activeCurrencyId].find(v => v.id === viewParam)
) {
this.activeViewId = viewParam;
} else {
this.activeViewId = this.views[this.activeCurrencyId][0].id;
this.updateView(this.activeViewId);
this.paramsSubscription = this.route.paramMap.subscribe(
(params: ParamMap) => {
const currencyParam = params.get('currency');
const viewParam = params.get('view');
this.activeCurrencyId = currencyParam;
if (!this.views[this.activeCurrencyId]) {
this.activeCurrencyId = 'tokens';
this.router.navigate(['/wallet/tokens']);
}
if (
viewParam &&
this.views[this.activeCurrencyId].find(v => v.id === viewParam)
) {
this.activeViewId = viewParam;
} else {
this.activeViewId = this.views[this.activeCurrencyId][0].id;
this.updateView(this.activeViewId);
}
this.detectChanges();
}
this.detectChanges();
});
);
this.setCurrencies();
this.detectChanges();
}
ngOnDestroy() {
if (this.paramsSubscription) {
this.paramsSubscription.unsubscribe();
}
}
setCurrencies() {
const headerCurrencies = ['tokens', 'cash', 'eth', 'btc'];
headerCurrencies.forEach(currency => {
......
......@@ -9,6 +9,7 @@ import {
EventEmitter,
Inject,
PLATFORM_ID,
ViewRef,
} from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { ConfigsService } from '../../../../common/services/configs.service';
......@@ -164,7 +165,9 @@ export class WalletSettingsTokensComponent implements OnInit, OnDestroy {
this.generatedAccount = null;
this.addressSetupComplete.emit();
this.inProgress = false;
this.detectChanges();
if (!(this.cd as ViewRef).destroyed) {
this.detectChanges();
}
}, 1000);
}
}
......@@ -232,7 +235,9 @@ export class WalletSettingsTokensComponent implements OnInit, OnDestroy {
this.detectExternal();
if (isPlatformBrowser(this.platformId)) {
this._externalTimer = setInterval(() => {
this.detectExternal();
if (!(this.cd as ViewRef).destroyed) {
this.detectExternal();
}
}, 1000);
}
}
......
......@@ -3,6 +3,7 @@ import {
ChangeDetectorRef,
Component,
OnInit,
OnDestroy,
} from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Client } from '../../../../services/api/client';
......@@ -21,7 +22,7 @@ import { Subscription } from 'rxjs';
templateUrl: './transactions-tokens.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class WalletTransactionsTokensComponent implements OnInit {
export class WalletTransactionsTokensComponent implements OnInit, OnDestroy {
init: boolean = false;
inProgress: boolean = true;
offset: string;
......@@ -98,6 +99,12 @@ export class WalletTransactionsTokensComponent implements OnInit {
this.getBalance();
}
ngOnDestroy() {
if (this.paramsSubscription) {
this.paramsSubscription.unsubscribe();
}
}
async getBalance() {
const tokenAccounts = await this.walletService.getTokenAccounts();
this.runningTotal = tokenAccounts.tokens.balance;
......
Please register or to comment