src/app/_services/token.service.ts
Properties |
Methods |
|
constructor(httpClient: HttpClient, registryService: RegistryService)
|
|||||||||
Defined in src/app/_services/token.service.ts:15
|
|||||||||
Parameters :
|
Async getTokenBalance | ||||||
getTokenBalance(address: string)
|
||||||
Defined in src/app/_services/token.service.ts:37
|
||||||
Parameters :
Returns :
Promise<number>
|
getTokenBySymbol | ||||||
getTokenBySymbol(symbol: string)
|
||||||
Defined in src/app/_services/token.service.ts:33
|
||||||
Parameters :
Returns :
Observable<any>
|
Async getTokens |
getTokens()
|
Defined in src/app/_services/token.service.ts:28
|
Returns :
Promise<Array<Promise<string>>>
|
LoadEvent |
Type : EventEmitter<number>
|
Default value : new EventEmitter<number>()
|
Defined in src/app/_services/token.service.ts:15
|
registry |
Type : CICRegistry
|
Defined in src/app/_services/token.service.ts:13
|
tokenRegistry |
Type : TokenRegistry
|
Defined in src/app/_services/token.service.ts:14
|
import { EventEmitter, Injectable } from '@angular/core';
import { environment } from '@src/environments/environment';
import { BehaviorSubject, 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';
@Injectable({
providedIn: 'root',
})
export class TokenService {
registry: CICRegistry;
tokenRegistry: TokenRegistry;
LoadEvent: EventEmitter<number> = new EventEmitter<number>();
constructor(private httpClient: HttpClient, private registryService: RegistryService) {
this.registry = registryService.getRegistry();
this.registry.load();
this.registry.onload = async (address: string): Promise<void> => {
this.tokenRegistry = new TokenRegistry(
await this.registry.getContractAddressByName('TokenRegistry')
);
this.LoadEvent.next(Date.now());
};
}
async getTokens(): Promise<Array<Promise<string>>> {
const count: number = await this.tokenRegistry.totalTokens();
return Array.from({ length: count }, async (v, i) => await this.tokenRegistry.entry(i));
}
getTokenBySymbol(symbol: string): Observable<any> {
return this.httpClient.get(`${environment.cicCacheUrl}/tokens/${symbol}`);
}
async getTokenBalance(address: string): Promise<number> {
const sarafuToken = await this.registry.addToken(await this.tokenRegistry.entry(0));
return await sarafuToken.methods.balanceOf(address).call();
}
}