Refactor getTokenBySymbol method.

This commit is contained in:
Spencer Ofwiti 2021-06-02 13:09:06 +03:00
parent 06326aa0bf
commit 701605be31
1 changed files with 11 additions and 11 deletions

View File

@ -1,10 +1,9 @@
import { Injectable } from '@angular/core';
import { environment } from '@src/environments/environment';
import { Observable } from 'rxjs';
import { CICRegistry } from 'cic-client';
import { TokenRegistry } from '@app/_eth';
import { HttpClient } from '@angular/common/http';
import { RegistryService } from '@app/_services/registry.service';
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',
@ -26,9 +25,9 @@ export class TokenService {
};
}
async getTokens(): Promise<Array<any>> {
async getTokens(): Promise<Array<Token>> {
const count: number = await this.tokenRegistry.totalTokens();
const tokens: Array<any> = [];
const tokens: Array<Token> = [];
for (let i = 0; i < count; i++) {
const token: any = {};
token.address = await this.tokenRegistry.entry(i);
@ -43,8 +42,9 @@ export class TokenService {
return tokens;
}
getTokenBySymbol(symbol: string): Observable<any> {
return this.httpClient.get(`${environment.cicCacheUrl}/tokens/${symbol}`);
async getTokenBySymbol(symbol: string): Promise<Token> {
const tokens: Array<Token> = await this.getTokens();
return tokens.find(token => token.symbol === symbol);
}
async getTokenBalance(address: string): Promise<(address: string) => Promise<number>> {