src/app/pages/tokens/tokens.component.ts
changeDetection | ChangeDetectionStrategy.OnPush |
selector | app-tokens |
styleUrls | ./tokens.component.scss |
templateUrl | ./tokens.component.html |
Properties |
Methods |
|
constructor(tokenService: TokenService, loggingService: LoggingService, router: Router)
|
||||||||||||
Defined in src/app/pages/tokens/tokens.component.ts:22
|
||||||||||||
Parameters :
|
doFilter | ||||||
doFilter(value: string)
|
||||||
Defined in src/app/pages/tokens/tokens.component.ts:41
|
||||||
Parameters :
Returns :
void
|
downloadCsv |
downloadCsv()
|
Defined in src/app/pages/tokens/tokens.component.ts:49
|
Returns :
void
|
Async ngOnInit |
ngOnInit()
|
Defined in src/app/pages/tokens/tokens.component.ts:30
|
Returns :
Promise<void>
|
Async viewToken | ||||
viewToken(token)
|
||||
Defined in src/app/pages/tokens/tokens.component.ts:45
|
||||
Parameters :
Returns :
Promise<void>
|
columnsToDisplay |
Type : Array<string>
|
Default value : ['name', 'symbol', 'address', 'supply']
|
Defined in src/app/pages/tokens/tokens.component.ts:19
|
dataSource |
Type : MatTableDataSource<any>
|
Defined in src/app/pages/tokens/tokens.component.ts:18
|
paginator |
Type : MatPaginator
|
Decorators :
@ViewChild(MatPaginator)
|
Defined in src/app/pages/tokens/tokens.component.ts:20
|
sort |
Type : MatSort
|
Decorators :
@ViewChild(MatSort)
|
Defined in src/app/pages/tokens/tokens.component.ts:21
|
tokens |
Type : Array<Promise<string>>
|
Defined in src/app/pages/tokens/tokens.component.ts:22
|
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';
import {TokenRegistry} from '../../_eth';
import {Token} from '../../_models';
@Component({
selector: 'app-tokens',
templateUrl: './tokens.component.html',
styleUrls: ['./tokens.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class TokensComponent implements OnInit {
dataSource: MatTableDataSource<any>;
columnsToDisplay: Array<string> = ['name', 'symbol', 'address', 'supply'];
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
tokens: Array<Promise<string>>;
constructor(
private tokenService: TokenService,
private loggingService: LoggingService,
private router: Router
) { }
async ngOnInit(): Promise<void> {
this.tokenService.LoadEvent.subscribe(async () => {
this.tokens = await this.tokenService.getTokens();
});
this.tokens = await this.tokenService.getTokens();
this.loggingService.sendInfoLevelMessage(this.tokens);
this.dataSource = new MatTableDataSource(this.tokens);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
doFilter(value: string): void {
this.dataSource.filter = value.trim().toLocaleLowerCase();
}
async viewToken(token): Promise<void> {
await this.router.navigateByUrl(`/tokens/${token.symbol}`);
}
downloadCsv(): void {
exportCsv(this.tokens, 'tokens');
}
}
<!-- Begin page -->
<div class="wrapper">
<app-sidebar></app-sidebar>
<!-- ============================================================== -->
<!-- Start Page Content here -->
<!-- ============================================================== -->
<div id="content">
<app-topbar></app-topbar>
<!-- Start Content-->
<div class="container-fluid" appMenuSelection>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a routerLink="/home">Home</a></li>
<li class="breadcrumb-item active" aria-current="page">Tokens</li>
</ol>
</nav>
<div class="card">
<mat-card-title class="card-header">
<div class="row">
Tokens
<button mat-raised-button color="primary" type="button" class="btn btn-outline-primary ml-auto mr-2" (click)="downloadCsv()"> EXPORT </button>
</div>
</mat-card-title>
<div class="card-body">
<mat-form-field appearance="outline">
<mat-label> Filter </mat-label>
<input matInput type="text" (keyup)="doFilter($event.target.value)" placeholder="Filter">
<mat-icon matSuffix>search</mat-icon>
</mat-form-field>
<mat-table class="mat-elevation-z10 table-responsive" [dataSource]="dataSource" matSort matSortDirection="asc" matSortDisableClear>
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef mat-sort-header> Name </mat-header-cell>
<mat-cell *matCellDef="let token"> {{token.name}} </mat-cell>
</ng-container>
<ng-container matColumnDef="symbol">
<mat-header-cell *matHeaderCellDef mat-sort-header> Symbol </mat-header-cell>
<mat-cell *matCellDef="let token"> {{token.symbol}} </mat-cell>
</ng-container>
<ng-container matColumnDef="address">
<mat-header-cell *matHeaderCellDef mat-sort-header> Address </mat-header-cell>
<mat-cell *matCellDef="let token"> {{token.address}} </mat-cell>
</ng-container>
<ng-container matColumnDef="supply">
<mat-header-cell *matHeaderCellDef mat-sort-header> Supply </mat-header-cell>
<mat-cell *matCellDef="let token"> {{token.supply | tokenRatio}} </mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="columnsToDisplay"></mat-header-row>
<mat-row *matRowDef="let token; columns: columnsToDisplay" (click)="viewToken(token)" matRipple></mat-row>
</mat-table>
<mat-paginator [pageSize]="5" [pageSizeOptions]="[5, 10, 25, 100]" showFirstLastButtons></mat-paginator>
</div>
</div>
</div>
<app-footer appMenuSelection></app-footer>
</div>
<!-- ============================================================== -->
<!-- End Page content -->
<!-- ============================================================== -->
</div>
./tokens.component.scss