Refactor app component init function.

This commit is contained in:
Spencer Ofwiti 2021-08-09 11:45:23 +03:00
parent e541a155ff
commit 563bd20cfe
2 changed files with 28 additions and 26 deletions

View File

@ -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<void> {
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();
}
});
}
}
});
}
}

View File

@ -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 });