Add a dedicated get token by address method.
This commit is contained in:
parent
701605be31
commit
d94f7e8e15
@ -29,22 +29,26 @@ export class TokenService {
|
||||
const count: number = await this.tokenRegistry.totalTokens();
|
||||
const tokens: Array<Token> = [];
|
||||
for (let i = 0; i < count; i++) {
|
||||
const token: any = {};
|
||||
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();
|
||||
const token: Token = await this.getTokenByAddress(await this.tokenRegistry.entry(i));
|
||||
tokens.push(token);
|
||||
}
|
||||
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> {
|
||||
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>> {
|
||||
|
Loading…
Reference in New Issue
Block a user