2021-03-14 09:23:20 +01:00
|
|
|
import {ChangeDetectionStrategy, Component, OnInit, ViewChild} from '@angular/core';
|
2020-11-25 09:00:20 +01:00
|
|
|
import {MatPaginator} from '@angular/material/paginator';
|
|
|
|
import {MatSort} from '@angular/material/sort';
|
2021-03-18 10:10:55 +01:00
|
|
|
import {LoggingService, TokenService} from '@app/_services';
|
2020-11-25 09:00:20 +01:00
|
|
|
import {MatTableDataSource} from '@angular/material/table';
|
|
|
|
import {Router} from '@angular/router';
|
2021-03-24 14:26:51 +01:00
|
|
|
import {exportCsv} from '@app/_helpers';
|
2021-04-29 19:10:39 +02:00
|
|
|
import {TokenRegistry} from '../../_eth';
|
2020-11-25 09:00:20 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-tokens',
|
|
|
|
templateUrl: './tokens.component.html',
|
2021-03-14 09:23:20 +01:00
|
|
|
styleUrls: ['./tokens.component.scss'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
2020-11-25 09:00:20 +01:00
|
|
|
})
|
2020-12-05 07:30:30 +01:00
|
|
|
export class TokensComponent implements OnInit {
|
2020-11-25 09:00:20 +01:00
|
|
|
dataSource: MatTableDataSource<any>;
|
2020-12-05 07:30:30 +01:00
|
|
|
columnsToDisplay = ['name', 'symbol', 'address', 'supply'];
|
2020-11-25 09:00:20 +01:00
|
|
|
@ViewChild(MatPaginator) paginator: MatPaginator;
|
|
|
|
@ViewChild(MatSort) sort: MatSort;
|
2021-03-18 10:10:55 +01:00
|
|
|
tokens: any;
|
2020-11-25 09:00:20 +01:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private tokenService: TokenService,
|
2021-03-18 10:10:55 +01:00
|
|
|
private loggingService: LoggingService,
|
2020-11-25 09:00:20 +01:00
|
|
|
private router: Router
|
2021-03-18 10:10:55 +01:00
|
|
|
) { }
|
2020-11-25 09:00:20 +01:00
|
|
|
|
2021-03-18 10:10:55 +01:00
|
|
|
async ngOnInit(): Promise<void> {
|
2021-04-29 19:10:39 +02:00
|
|
|
this.tokenService.LoadEvent.subscribe(async () => {
|
|
|
|
this.tokens = await this.tokenService.getTokens();
|
|
|
|
});
|
2021-03-18 10:10:55 +01:00
|
|
|
this.tokens = await this.tokenService.getTokens();
|
|
|
|
this.loggingService.sendInfoLevelMessage(this.tokens);
|
2021-04-29 19:10:39 +02:00
|
|
|
this.dataSource = new MatTableDataSource(this.tokens);
|
|
|
|
this.dataSource.paginator = this.paginator;
|
|
|
|
this.dataSource.sort = this.sort;
|
2020-11-25 09:00:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
doFilter(value: string): void {
|
|
|
|
this.dataSource.filter = value.trim().toLocaleLowerCase();
|
|
|
|
}
|
|
|
|
|
2021-03-18 10:10:55 +01:00
|
|
|
async viewToken(token): Promise<void> {
|
|
|
|
await this.router.navigateByUrl(`/tokens/${token.symbol}`);
|
2020-11-25 09:00:20 +01:00
|
|
|
}
|
2021-03-24 14:26:51 +01:00
|
|
|
|
|
|
|
downloadCsv(): void {
|
|
|
|
exportCsv(this.tokens, 'tokens');
|
|
|
|
}
|
2020-11-25 09:00:20 +01:00
|
|
|
}
|