Refactor loading of tokens to occur in app component.
This commit is contained in:
		
							parent
							
								
									2515ce1d96
								
							
						
					
					
						commit
						717c8616ae
					
				@ -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?')) {
 | 
			
		||||
 | 
			
		||||
@ -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<any>;
 | 
			
		||||
  columnsToDisplay: Array<string> = ['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();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user