diff --git a/src/app/_helpers/schema-validation.ts b/src/app/_helpers/schema-validation.ts index f8779a5..371ff44 100644 --- a/src/app/_helpers/schema-validation.ts +++ b/src/app/_helpers/schema-validation.ts @@ -4,7 +4,7 @@ async function personValidation(person: any): Promise { const personValidationErrors: any = await validatePerson(person); 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 { const vcardValidationErrors: any = await validateVcard(vcard); if (vcardValidationErrors) { - vcardValidationErrors.map((error) => console.error(`${error.message}`)); + vcardValidationErrors.map((error) => console.error(`${error.message}`, vcard, error)); } } diff --git a/src/app/_services/token.service.ts b/src/app/_services/token.service.ts index 748361f..b644b4d 100644 --- a/src/app/_services/token.service.ts +++ b/src/app/_services/token.service.ts @@ -1,6 +1,6 @@ -import { EventEmitter, Injectable } from '@angular/core'; +import { Injectable } from '@angular/core'; import { environment } from '@src/environments/environment'; -import { BehaviorSubject, Observable } from 'rxjs'; +import { Observable } from 'rxjs'; import { CICRegistry } from 'cic-client'; import { TokenRegistry } from '@app/_eth'; import { HttpClient } from '@angular/common/http'; @@ -12,15 +12,15 @@ import { RegistryService } from '@app/_services/registry.service'; export class TokenService { registry: CICRegistry; tokenRegistry: TokenRegistry; - LoadEvent: EventEmitter = new EventEmitter(); + onload: (status: boolean) => void; constructor(private httpClient: HttpClient, private registryService: RegistryService) { - this.registry = registryService.registry; + this.registry = this.registryService.registry; this.registry.onload = async (address: string): Promise => { this.tokenRegistry = new 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}`); } - async getTokenBalance(address: string): Promise { + async getTokenBalance(address: string): Promise<(address: string) => Promise> { const sarafuToken = await this.registry.addToken(await this.tokenRegistry.entry(0)); return await sarafuToken.methods.balanceOf(address).call(); } diff --git a/src/app/_services/user.service.ts b/src/app/_services/user.service.ts index 80ef2d2..cb418d4 100644 --- a/src/app/_services/user.service.ts +++ b/src/app/_services/user.service.ts @@ -205,9 +205,11 @@ export class UserService { const account: Syncable = Envelope.fromJSON(JSON.stringify(res)).unwrap(); const accountInfo = account.m.data; await personValidation(accountInfo); - accountInfo.balance = await this.tokenService.getTokenBalance( - accountInfo.identities.evm[`bloxberg:${environment.bloxbergChainId}`][0] - ); + this.tokenService.onload = async (status: boolean): Promise => { + accountInfo.balance = await this.tokenService.getTokenBalance( + accountInfo.identities.evm[`bloxberg:${environment.bloxbergChainId}`][0] + ); + }; accountInfo.vcard = vCard.parse(atob(accountInfo.vcard)); await vcardValidation(accountInfo.vcard); this.accounts.unshift(accountInfo); diff --git a/src/app/pages/tokens/tokens.component.ts b/src/app/pages/tokens/tokens.component.ts index 767694a..b4b4012 100644 --- a/src/app/pages/tokens/tokens.component.ts +++ b/src/app/pages/tokens/tokens.component.ts @@ -5,8 +5,6 @@ import { LoggingService, TokenService } from '@app/_services'; import { MatTableDataSource } from '@angular/material/table'; import { Router } from '@angular/router'; import { exportCsv } from '@app/_helpers'; -import { TokenRegistry } from '../../_eth'; -import { Token } from '../../_models'; @Component({ selector: 'app-tokens', @@ -28,14 +26,13 @@ export class TokensComponent implements OnInit { ) {} async ngOnInit(): Promise { - this.tokenService.LoadEvent.subscribe(async () => { + this.tokenService.onload = async (status: boolean): Promise => { this.tokens = await this.tokenService.getTokens(); - }); - this.tokens = await this.tokenService.getTokens(); - this.loggingService.sendInfoLevelMessage(this.tokens); - this.dataSource = new MatTableDataSource(this.tokens); - this.dataSource.paginator = this.paginator; - this.dataSource.sort = this.sort; + this.loggingService.sendInfoLevelMessage(this.tokens); + this.dataSource = new MatTableDataSource(this.tokens); + this.dataSource.paginator = this.paginator; + this.dataSource.sort = this.sort; + }; } doFilter(value: string): void {