From 717c8616aee779144da444540ef9dd06e1e134e3 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 30 Jun 2021 19:48:44 +0300 Subject: [PATCH] Refactor loading of tokens to occur in app component. --- src/app/app.component.ts | 5 +++++ src/app/pages/tokens/tokens.component.ts | 20 +++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 03aa30e..7ed099d 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -56,6 +56,11 @@ export class AppComponent implements OnInit { } catch (error) { this.loggingService.sendErrorLevelMessage('Failed to load accounts', this, { error }); } + this.tokenService.load.subscribe(async (status: boolean) => { + if (status) { + await this.tokenService.getTokens(); + } + }); if (!this.swUpdate.isEnabled) { this.swUpdate.available.subscribe(() => { if (confirm('New Version available. Load New Version?')) { diff --git a/src/app/pages/tokens/tokens.component.ts b/src/app/pages/tokens/tokens.component.ts index 38cce28..cc717d5 100644 --- a/src/app/pages/tokens/tokens.component.ts +++ b/src/app/pages/tokens/tokens.component.ts @@ -1,4 +1,10 @@ -import { ChangeDetectionStrategy, Component, OnInit, ViewChild } from '@angular/core'; +import { + AfterViewInit, + ChangeDetectionStrategy, + Component, + OnInit, + ViewChild, +} from '@angular/core'; import { MatPaginator } from '@angular/material/paginator'; import { MatSort } from '@angular/material/sort'; import { TokenService } from '@app/_services'; @@ -12,7 +18,7 @@ import { Token } from '@app/_models'; styleUrls: ['./tokens.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class TokensComponent implements OnInit { +export class TokensComponent implements OnInit, AfterViewInit { dataSource: MatTableDataSource; columnsToDisplay: Array = ['name', 'symbol', 'address', 'supply']; @ViewChild(MatPaginator) paginator: MatPaginator; @@ -23,11 +29,6 @@ export class TokensComponent implements OnInit { constructor(private tokenService: TokenService) {} ngOnInit(): void { - this.tokenService.load.subscribe(async (status: boolean) => { - if (status) { - await this.tokenService.getTokens(); - } - }); this.tokenService.tokensSubject.subscribe((tokens) => { this.dataSource = new MatTableDataSource(tokens); this.dataSource.paginator = this.paginator; @@ -36,6 +37,11 @@ export class TokensComponent implements OnInit { }); } + ngAfterViewInit(): void { + this.dataSource.paginator = this.paginator; + this.dataSource.sort = this.sort; + } + doFilter(value: string): void { this.dataSource.filter = value.trim().toLocaleLowerCase(); }