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