Fix token list.

This commit is contained in:
Spencer Ofwiti 2021-06-01 20:34:41 +03:00
parent 384071d3db
commit 8de8e6a30b
3 changed files with 15 additions and 4 deletions

View File

@ -26,9 +26,20 @@ export class TokenService {
}; };
} }
async getTokens(): Promise<Array<Promise<string>>> { async getTokens(): Promise<Array<any>> {
const count: number = await this.tokenRegistry.totalTokens(); const count: number = await this.tokenRegistry.totalTokens();
return Array.from({ length: count }, async (v, i) => await this.tokenRegistry.entry(i)); let tokens: Array<any> = [];
for (let i = 0; i < count; i++) {
const tokenContract = await this.registry.addToken(await this.tokenRegistry.entry(i));
let token: any = {};
token.name = await tokenContract.methods.name().call();
token.symbol = await tokenContract.methods.symbol().call();
token.address = await this.tokenRegistry.entry(i);
token.totalSupply = await tokenContract.methods.totalSupply().call();
token.decimals = await tokenContract.methods.decimals().call();
tokens.push(token);
}
return tokens;
} }
getTokenBySymbol(symbol: string): Observable<any> { getTokenBySymbol(symbol: string): Observable<any> {

View File

@ -48,7 +48,7 @@
<ng-container matColumnDef="supply"> <ng-container matColumnDef="supply">
<mat-header-cell *matHeaderCellDef mat-sort-header> Supply </mat-header-cell> <mat-header-cell *matHeaderCellDef mat-sort-header> Supply </mat-header-cell>
<mat-cell *matCellDef="let token"> {{token.supply | tokenRatio}} </mat-cell> <mat-cell *matCellDef="let token"> {{token.totalSupply | tokenRatio}} </mat-cell>
</ng-container> </ng-container>
<mat-header-row *matHeaderRowDef="columnsToDisplay"></mat-header-row> <mat-header-row *matHeaderRowDef="columnsToDisplay"></mat-header-row>

View File

@ -17,7 +17,7 @@ export class TokensComponent implements OnInit {
columnsToDisplay: Array<string> = ['name', 'symbol', 'address', 'supply']; columnsToDisplay: Array<string> = ['name', 'symbol', 'address', 'supply'];
@ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort; @ViewChild(MatSort) sort: MatSort;
tokens: Array<Promise<string>>; tokens: Array<any>;
constructor( constructor(
private tokenService: TokenService, private tokenService: TokenService,