Add a dedicated get token by address method.
This commit is contained in:
parent
701605be31
commit
d94f7e8e15
@ -1,9 +1,9 @@
|
|||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {CICRegistry} from 'cic-client';
|
import { CICRegistry } from 'cic-client';
|
||||||
import {TokenRegistry} from '@app/_eth';
|
import { TokenRegistry } from '@app/_eth';
|
||||||
import {HttpClient} from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import {RegistryService} from '@app/_services/registry.service';
|
import { RegistryService } from '@app/_services/registry.service';
|
||||||
import {Token} from '@app/_models';
|
import { Token } from '@app/_models';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
@ -29,22 +29,26 @@ export class TokenService {
|
|||||||
const count: number = await this.tokenRegistry.totalTokens();
|
const count: number = await this.tokenRegistry.totalTokens();
|
||||||
const tokens: Array<Token> = [];
|
const tokens: Array<Token> = [];
|
||||||
for (let i = 0; i < count; i++) {
|
for (let i = 0; i < count; i++) {
|
||||||
const token: any = {};
|
const token: Token = await this.getTokenByAddress(await this.tokenRegistry.entry(i));
|
||||||
token.address = await this.tokenRegistry.entry(i);
|
|
||||||
const tokenContract = await this.registry.addToken(token.address);
|
|
||||||
token.name = await tokenContract.methods.name().call();
|
|
||||||
token.symbol = await tokenContract.methods.symbol().call();
|
|
||||||
token.address = await this.tokenRegistry.entry(i);
|
|
||||||
token.supply = await tokenContract.methods.totalSupply().call();
|
|
||||||
token.decimals = await tokenContract.methods.decimals().call();
|
|
||||||
tokens.push(token);
|
tokens.push(token);
|
||||||
}
|
}
|
||||||
return tokens;
|
return tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getTokenByAddress(address: string): Promise<Token> {
|
||||||
|
const token: any = {};
|
||||||
|
const tokenContract = await this.registry.addToken(address);
|
||||||
|
token.address = address;
|
||||||
|
token.name = await tokenContract.methods.name().call();
|
||||||
|
token.symbol = await tokenContract.methods.symbol().call();
|
||||||
|
token.supply = await tokenContract.methods.totalSupply().call();
|
||||||
|
token.decimals = await tokenContract.methods.decimals().call();
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
async getTokenBySymbol(symbol: string): Promise<Token> {
|
async getTokenBySymbol(symbol: string): Promise<Token> {
|
||||||
const tokens: Array<Token> = await this.getTokens();
|
const tokens: Array<Token> = await this.getTokens();
|
||||||
return tokens.find(token => token.symbol === symbol);
|
return tokens.find((token) => token.symbol === symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTokenBalance(address: string): Promise<(address: string) => Promise<number>> {
|
async getTokenBalance(address: string): Promise<(address: string) => Promise<number>> {
|
||||||
|
Loading…
Reference in New Issue
Block a user