2021-05-10 18:15:25 +02:00
|
|
|
import { ChangeDetectionStrategy, Component, OnInit, ViewChild } from '@angular/core';
|
|
|
|
import { MatPaginator } from '@angular/material/paginator';
|
|
|
|
import { MatSort } from '@angular/material/sort';
|
|
|
|
import { LoggingService, TokenService } from '@app/_services';
|
|
|
|
import { MatTableDataSource } from '@angular/material/table';
|
|
|
|
import { Router } from '@angular/router';
|
|
|
|
import { exportCsv } from '@app/_helpers';
|
2021-06-02 09:04:42 +02:00
|
|
|
import { Token } from '@app/_models';
|
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'],
|
2021-05-10 18:15:25 +02:00
|
|
|
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>;
|
2021-04-30 14:50:16 +02:00
|
|
|
columnsToDisplay: Array<string> = ['name', 'symbol', 'address', 'supply'];
|
2020-11-25 09:00:20 +01:00
|
|
|
@ViewChild(MatPaginator) paginator: MatPaginator;
|
|
|
|
@ViewChild(MatSort) sort: MatSort;
|
2021-06-02 09:04:42 +02:00
|
|
|
tokens: Array<Token>;
|
|
|
|
token: Token;
|
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-05-10 18:15:25 +02:00
|
|
|
) {}
|
2020-11-25 09:00:20 +01:00
|
|
|
|
2021-03-18 10:10:55 +01:00
|
|
|
async ngOnInit(): Promise<void> {
|
2021-05-19 18:57:10 +02:00
|
|
|
await this.tokenService.init();
|
2021-05-18 12:24:41 +02:00
|
|
|
this.tokenService.onload = async (status: boolean): Promise<void> => {
|
2021-06-04 10:01:20 +02:00
|
|
|
await this.tokenService.getTokens();
|
|
|
|
};
|
|
|
|
this.tokenService.tokensSubject.subscribe((tokens) => {
|
|
|
|
this.loggingService.sendInfoLevelMessage(tokens);
|
|
|
|
this.dataSource = new MatTableDataSource(tokens);
|
2021-05-18 12:24:41 +02:00
|
|
|
this.dataSource.paginator = this.paginator;
|
|
|
|
this.dataSource.sort = this.sort;
|
2021-06-04 10:01:20 +02:00
|
|
|
this.tokens = tokens;
|
|
|
|
});
|
2020-11-25 09:00:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
doFilter(value: string): void {
|
|
|
|
this.dataSource.filter = value.trim().toLocaleLowerCase();
|
|
|
|
}
|
|
|
|
|
2021-06-02 09:04:42 +02:00
|
|
|
viewToken(token): void {
|
|
|
|
this.token = token;
|
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
|
|
|
}
|