diff --git a/src/app/_services/token.service.ts b/src/app/_services/token.service.ts index f4ee1fb..f5b69f1 100644 --- a/src/app/_services/token.service.ts +++ b/src/app/_services/token.service.ts @@ -1,9 +1,9 @@ -import {Injectable} from '@angular/core'; -import {CICRegistry} from 'cic-client'; -import {TokenRegistry} from '@app/_eth'; -import {HttpClient} from '@angular/common/http'; -import {RegistryService} from '@app/_services/registry.service'; -import {Token} from '@app/_models'; +import { Injectable } from '@angular/core'; +import { CICRegistry } from 'cic-client'; +import { TokenRegistry } from '@app/_eth'; +import { HttpClient } from '@angular/common/http'; +import { RegistryService } from '@app/_services/registry.service'; +import { Token } from '@app/_models'; @Injectable({ providedIn: 'root', @@ -29,22 +29,26 @@ export class TokenService { const count: number = await this.tokenRegistry.totalTokens(); const tokens: Array = []; 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 { + 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 { const tokens: Array = 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> {