Add token service load event.
This commit is contained in:
parent
8ae6436460
commit
ac231dc03e
@ -4,7 +4,7 @@ async function personValidation(person: any): Promise<void> {
|
|||||||
const personValidationErrors: any = await validatePerson(person);
|
const personValidationErrors: any = await validatePerson(person);
|
||||||
|
|
||||||
if (personValidationErrors) {
|
if (personValidationErrors) {
|
||||||
personValidationErrors.map((error) => console.error(`${error.message}`));
|
personValidationErrors.map((error) => console.error(`${error.message}`, person, error));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -12,7 +12,7 @@ async function vcardValidation(vcard: any): Promise<void> {
|
|||||||
const vcardValidationErrors: any = await validateVcard(vcard);
|
const vcardValidationErrors: any = await validateVcard(vcard);
|
||||||
|
|
||||||
if (vcardValidationErrors) {
|
if (vcardValidationErrors) {
|
||||||
vcardValidationErrors.map((error) => console.error(`${error.message}`));
|
vcardValidationErrors.map((error) => console.error(`${error.message}`, vcard, error));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { EventEmitter, Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { environment } from '@src/environments/environment';
|
import { environment } from '@src/environments/environment';
|
||||||
import { BehaviorSubject, Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { CICRegistry } from 'cic-client';
|
import { CICRegistry } from 'cic-client';
|
||||||
import { TokenRegistry } from '@app/_eth';
|
import { TokenRegistry } from '@app/_eth';
|
||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
@ -12,15 +12,15 @@ import { RegistryService } from '@app/_services/registry.service';
|
|||||||
export class TokenService {
|
export class TokenService {
|
||||||
registry: CICRegistry;
|
registry: CICRegistry;
|
||||||
tokenRegistry: TokenRegistry;
|
tokenRegistry: TokenRegistry;
|
||||||
LoadEvent: EventEmitter<number> = new EventEmitter<number>();
|
onload: (status: boolean) => void;
|
||||||
|
|
||||||
constructor(private httpClient: HttpClient, private registryService: RegistryService) {
|
constructor(private httpClient: HttpClient, private registryService: RegistryService) {
|
||||||
this.registry = registryService.registry;
|
this.registry = this.registryService.registry;
|
||||||
this.registry.onload = async (address: string): Promise<void> => {
|
this.registry.onload = async (address: string): Promise<void> => {
|
||||||
this.tokenRegistry = new TokenRegistry(
|
this.tokenRegistry = new TokenRegistry(
|
||||||
await this.registry.getContractAddressByName('TokenRegistry')
|
await this.registry.getContractAddressByName('TokenRegistry')
|
||||||
);
|
);
|
||||||
this.LoadEvent.next(Date.now());
|
this.onload(this.tokenRegistry !== undefined);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ export class TokenService {
|
|||||||
return this.httpClient.get(`${environment.cicCacheUrl}/tokens/${symbol}`);
|
return this.httpClient.get(`${environment.cicCacheUrl}/tokens/${symbol}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTokenBalance(address: string): Promise<number> {
|
async getTokenBalance(address: string): Promise<(address: string) => Promise<number>> {
|
||||||
const sarafuToken = await this.registry.addToken(await this.tokenRegistry.entry(0));
|
const sarafuToken = await this.registry.addToken(await this.tokenRegistry.entry(0));
|
||||||
return await sarafuToken.methods.balanceOf(address).call();
|
return await sarafuToken.methods.balanceOf(address).call();
|
||||||
}
|
}
|
||||||
|
@ -205,9 +205,11 @@ export class UserService {
|
|||||||
const account: Syncable = Envelope.fromJSON(JSON.stringify(res)).unwrap();
|
const account: Syncable = Envelope.fromJSON(JSON.stringify(res)).unwrap();
|
||||||
const accountInfo = account.m.data;
|
const accountInfo = account.m.data;
|
||||||
await personValidation(accountInfo);
|
await personValidation(accountInfo);
|
||||||
accountInfo.balance = await this.tokenService.getTokenBalance(
|
this.tokenService.onload = async (status: boolean): Promise<void> => {
|
||||||
accountInfo.identities.evm[`bloxberg:${environment.bloxbergChainId}`][0]
|
accountInfo.balance = await this.tokenService.getTokenBalance(
|
||||||
);
|
accountInfo.identities.evm[`bloxberg:${environment.bloxbergChainId}`][0]
|
||||||
|
);
|
||||||
|
};
|
||||||
accountInfo.vcard = vCard.parse(atob(accountInfo.vcard));
|
accountInfo.vcard = vCard.parse(atob(accountInfo.vcard));
|
||||||
await vcardValidation(accountInfo.vcard);
|
await vcardValidation(accountInfo.vcard);
|
||||||
this.accounts.unshift(accountInfo);
|
this.accounts.unshift(accountInfo);
|
||||||
|
@ -5,8 +5,6 @@ import { LoggingService, TokenService } from '@app/_services';
|
|||||||
import { MatTableDataSource } from '@angular/material/table';
|
import { MatTableDataSource } from '@angular/material/table';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { exportCsv } from '@app/_helpers';
|
import { exportCsv } from '@app/_helpers';
|
||||||
import { TokenRegistry } from '../../_eth';
|
|
||||||
import { Token } from '../../_models';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-tokens',
|
selector: 'app-tokens',
|
||||||
@ -28,14 +26,13 @@ export class TokensComponent implements OnInit {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
async ngOnInit(): Promise<void> {
|
async ngOnInit(): Promise<void> {
|
||||||
this.tokenService.LoadEvent.subscribe(async () => {
|
this.tokenService.onload = async (status: boolean): Promise<void> => {
|
||||||
this.tokens = await this.tokenService.getTokens();
|
this.tokens = await this.tokenService.getTokens();
|
||||||
});
|
this.loggingService.sendInfoLevelMessage(this.tokens);
|
||||||
this.tokens = await this.tokenService.getTokens();
|
this.dataSource = new MatTableDataSource(this.tokens);
|
||||||
this.loggingService.sendInfoLevelMessage(this.tokens);
|
this.dataSource.paginator = this.paginator;
|
||||||
this.dataSource = new MatTableDataSource(this.tokens);
|
this.dataSource.sort = this.sort;
|
||||||
this.dataSource.paginator = this.paginator;
|
};
|
||||||
this.dataSource.sort = this.sort;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
doFilter(value: string): void {
|
doFilter(value: string): void {
|
||||||
|
Loading…
Reference in New Issue
Block a user