From 701605be312a63d0f9724fc79c5719e7fee77bd0 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 2 Jun 2021 13:09:06 +0300 Subject: [PATCH] Refactor getTokenBySymbol method. --- src/app/_services/token.service.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/app/_services/token.service.ts b/src/app/_services/token.service.ts index 382507b..f4ee1fb 100644 --- a/src/app/_services/token.service.ts +++ b/src/app/_services/token.service.ts @@ -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> { + async getTokens(): Promise> { const count: number = await this.tokenRegistry.totalTokens(); - const tokens: Array = []; + const tokens: Array = []; 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 { - return this.httpClient.get(`${environment.cicCacheUrl}/tokens/${symbol}`); + async getTokenBySymbol(symbol: string): Promise { + const tokens: Array = await this.getTokens(); + return tokens.find(token => token.symbol === symbol); } async getTokenBalance(address: string): Promise<(address: string) => Promise> {