From 563bd20cfeb33c51ced67807173472b3c33bf684 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Mon, 9 Aug 2021 11:45:23 +0300 Subject: [PATCH] Refactor app component init function. --- src/app/app.component.ts | 53 +++++++++++--------- src/app/pages/accounts/accounts.component.ts | 1 - 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 878e09d..41e639a 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -61,31 +61,7 @@ export class AppComponent implements OnInit { } }); } - await this.router.events - .pipe(filter((e) => e instanceof NavigationEnd)) - .forEach(async (routeInfo) => { - if (routeInfo instanceof NavigationEnd) { - this.url = routeInfo.url; - if (!this.url.match(this.accountDetailsRegex) || !this.url.includes('tx')) { - await this.blockSyncService.blockSync(); - } - if (!this.url.includes('accounts')) { - try { - // TODO it feels like this should be in the onInit handler - await this.userService.loadAccounts(100); - } catch (error) { - this.loggingService.sendErrorLevelMessage('Failed to load accounts', this, { error }); - } - } - if (!this.url.includes('tokens')) { - this.tokenService.load.subscribe(async (status: boolean) => { - if (status) { - await this.tokenService.getTokens(); - } - }); - } - } - }); + await this.routeManagement(); } // Load resize @@ -124,4 +100,31 @@ export class AppComponent implements OnInit { const conversion: any = event.detail.tx; await this.transactionService.setConversion(conversion, 100); } + + async routeManagement(): Promise { + await this.router.events + .pipe(filter((e) => e instanceof NavigationEnd)) + .forEach(async (routeInfo) => { + if (routeInfo instanceof NavigationEnd) { + this.url = routeInfo.url; + if (!this.url.match(this.accountDetailsRegex) || !this.url.includes('tx')) { + await this.blockSyncService.blockSync(); + } + if (!this.url.includes('accounts')) { + try { + await this.userService.loadAccounts(100); + } catch (error) { + this.loggingService.sendErrorLevelMessage('Failed to load accounts', this, { error }); + } + } + if (!this.url.includes('tokens')) { + this.tokenService.load.subscribe(async (status: boolean) => { + if (status) { + await this.tokenService.getTokens(); + } + }); + } + } + }); + } } diff --git a/src/app/pages/accounts/accounts.component.ts b/src/app/pages/accounts/accounts.component.ts index 2e4c864..77828d4 100644 --- a/src/app/pages/accounts/accounts.component.ts +++ b/src/app/pages/accounts/accounts.component.ts @@ -54,7 +54,6 @@ export class AccountsComponent implements OnInit, AfterViewInit { } }); try { - // TODO it feels like this should be in the onInit handler await this.userService.loadAccounts(100); } catch (error) { this.loggingService.sendErrorLevelMessage('Failed to load accounts', this, { error });