cic-staff-client/src/app/pages/tokens/tokens.component.ts

68 lines
1.8 KiB
TypeScript
Raw Normal View History

import {
AfterViewInit,
ChangeDetectionStrategy,
Component,
OnInit,
ViewChild,
} from '@angular/core';
2021-05-10 18:15:25 +02:00
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import { TokenService } from '@app/_services';
2021-05-10 18:15:25 +02:00
import { MatTableDataSource } from '@angular/material/table';
import { exportCsv } from '@app/_helpers';
import { Token } from '@app/_models';
2020-11-25 09:00:20 +01:00
@Component({
selector: 'app-tokens',
templateUrl: './tokens.component.html',
styleUrls: ['./tokens.component.scss'],
2021-05-10 18:15:25 +02:00
changeDetection: ChangeDetectionStrategy.OnPush,
2020-11-25 09:00:20 +01:00
})
export class TokensComponent implements OnInit, AfterViewInit {
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;
tokens: Array<Token>;
token: Token;
loading: boolean = true;
2020-11-25 09:00:20 +01:00
constructor(private tokenService: TokenService) {}
2020-11-25 09:00:20 +01:00
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);
2021-05-18 12:24:41 +02:00
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
this.tokens = tokens;
if (tokens.length > 0) {
this.loading = false;
}
});
2020-11-25 09:00:20 +01:00
}
ngAfterViewInit(): void {
if (this.dataSource) {
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();
}
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
}