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)
|
||||||
Defined in src/app/pages/tokens/tokens.component.ts:28
|
||||||
Parameters :
|
doFilter | ||||||
doFilter(value: string)
|
||||||
Defined in src/app/pages/tokens/tokens.component.ts:56
|
||||||
Parameters :
Returns :
void
|
downloadCsv |
downloadCsv()
|
Defined in src/app/pages/tokens/tokens.component.ts:64
|
Returns :
void
|
ngAfterViewInit |
ngAfterViewInit()
|
Defined in src/app/pages/tokens/tokens.component.ts:49
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Defined in src/app/pages/tokens/tokens.component.ts:32
|
Returns :
void
|
viewToken | ||||
viewToken(token)
|
||||
Defined in src/app/pages/tokens/tokens.component.ts:60
|
||||
Parameters :
Returns :
void
|
columnsToDisplay |
Type : Array<string>
|
Default value : ['name', 'symbol', 'address', 'supply']
|
Defined in src/app/pages/tokens/tokens.component.ts:23
|
dataSource |
Type : MatTableDataSource<any>
|
Defined in src/app/pages/tokens/tokens.component.ts:22
|
loading |
Type : boolean
|
Default value : true
|
Defined in src/app/pages/tokens/tokens.component.ts:28
|
paginator |
Type : MatPaginator
|
Decorators :
@ViewChild(MatPaginator)
|
Defined in src/app/pages/tokens/tokens.component.ts:24
|
sort |
Type : MatSort
|
Decorators :
@ViewChild(MatSort)
|
Defined in src/app/pages/tokens/tokens.component.ts:25
|
token |
Type : Token
|
Defined in src/app/pages/tokens/tokens.component.ts:27
|
tokens |
Type : Array<Token>
|
Defined in src/app/pages/tokens/tokens.component.ts:26
|
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';
import { MatTableDataSource } from '@angular/material/table';
import { exportCsv } from '@app/_helpers';
import { Token } from '@app/_models';
@Component({
selector: 'app-tokens',
templateUrl: './tokens.component.html',
styleUrls: ['./tokens.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TokensComponent implements OnInit, AfterViewInit {
dataSource: MatTableDataSource<any>;
columnsToDisplay: Array<string> = ['name', 'symbol', 'address', 'supply'];
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
tokens: Array<Token>;
token: Token;
loading: boolean = true;
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;
this.dataSource.sort = this.sort;
this.tokens = tokens;
if (tokens.length > 0) {
this.loading = false;
}
});
}
ngAfterViewInit(): void {
if (this.dataSource) {
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
}
doFilter(value: string): void {
this.dataSource.filter = value.trim().toLocaleLowerCase();
}
viewToken(token): void {
this.token = token;
}
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">
<app-token-details [token]="token" (closeWindow)="token = $event"></app-token-details>
<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>
<div *ngIf="loading">
<h2 class="text-center"><strong>Loading Tokens!</strong></h2>
<mat-progress-bar [mode]="'query'"></mat-progress-bar>
</div>
<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