From 5061dc0d32d29668eeace5ac809a1964c3f82b1f Mon Sep 17 00:00:00 2001 From: Blair Vanderlugt Date: Sun, 9 May 2021 10:07:49 -0700 Subject: [PATCH] still kinda broken --- src/app/_services/registry.service.ts | 1 + src/app/_services/user.service.ts | 48 ++++++++++++++------ src/app/pages/accounts/accounts.component.ts | 3 ++ 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/app/_services/registry.service.ts b/src/app/_services/registry.service.ts index 47570cf..8fc8018 100644 --- a/src/app/_services/registry.service.ts +++ b/src/app/_services/registry.service.ts @@ -15,6 +15,7 @@ export class RegistryService { constructor() { this.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress); + this.registry.load(); } getRegistry(): any { diff --git a/src/app/_services/user.service.ts b/src/app/_services/user.service.ts index 3685197..dd1b9e5 100644 --- a/src/app/_services/user.service.ts +++ b/src/app/_services/user.service.ts @@ -1,5 +1,5 @@ import {Injectable} from '@angular/core'; -import {BehaviorSubject, Observable, Subject} from 'rxjs'; +import {BehaviorSubject, Observable, Subject, throwError, of} from 'rxjs'; import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http'; import {environment} from '@src/environments/environment'; import {first} from 'rxjs/operators'; @@ -40,17 +40,30 @@ export class UserService { private registryService: RegistryService, private authService: AuthService ) { - this.authService = authService; - this.registryService = registryService; + //this.authService.init().then(() => { + // this.keystore = authService.mutableKeyStore; + // this.signer = new PGPSigner(this.keystore); + //}); + //this.registry = registryService.getRegistry(); + //this.registry.load(); } - async load(): Promise { - await this.authService.init(); - // TODO you don't have to do this reassignment - this.keystore = this.authService.mutableKeyStore; - this.signer = new PGPSigner(this.keystore); - this.registry = this.registryService.getRegistry(); - await this.registry.load(); + async load(): Promise { + try { + // TODO this method is called by ngOnInit so we need to + // emit an observalbe or conver ngonInit to promise + // TODO alig the load/init methods naming + await this.authService.init(); + // await this.registryService.load(); + // TODO key store is defined + this.keystore = this.authService.mutableKeyStore; + this.signer = new PGPSigner(this.keystore); + this.registry = this.registryService.getRegistry(); + return of(0); + } catch (error) { + console.log('ERROR: Failed to initiialize User Service', error) + return throwError(error); + } } resetPin(phone: string): Observable { @@ -153,10 +166,17 @@ export class UserService { async loadAccounts(limit: number = 100, offset: number = 0): Promise { this.resetAccountsList(); - const accountIndexAddress: string = await this.registry.getContractAddressByName('AccountRegistry'); - const accountIndexQuery = new AccountIndex(accountIndexAddress); - const accountAddresses: Array = await accountIndexQuery.last(await accountIndexQuery.totalAccounts()); - this.loggingService.sendInfoLevelMessage(accountAddresses); + let accountAddresses: Array; + try { + const accountIndexAddress: string = await this.registry.getContractAddressByName('AccountRegistry'); + const accountIndexQuery = new AccountIndex(accountIndexAddress); + const totalAccounts = await accountIndexQuery.totalAccounts() + const accountAddresses = await accountIndexQuery.last(totalAccounts); + this.loggingService.sendInfoLevelMessage(accountAddresses); + } catch (error){ + // TODO real logging: + console.log("ERROR: failed to load accounts \n", error) + } for (const accountAddress of accountAddresses.slice(offset, offset + limit)) { await this.getAccountByAddress(accountAddress, limit); } diff --git a/src/app/pages/accounts/accounts.component.ts b/src/app/pages/accounts/accounts.component.ts index bcb38a2..569182c 100644 --- a/src/app/pages/accounts/accounts.component.ts +++ b/src/app/pages/accounts/accounts.component.ts @@ -9,6 +9,8 @@ import {strip0x} from '@src/assets/js/ethtx/dist/hex'; import {first} from 'rxjs/operators'; import {environment} from '@src/environments/environment'; import {AccountDetails} from '@app/_models'; +import {Observable, of} from 'rxjs'; + @Component({ selector: 'app-accounts', @@ -38,6 +40,7 @@ export class AccountsComponent implements OnInit { } ngOnInit(): void { + of(this.userService.load()) this.userService.getAccountTypes().pipe(first()).subscribe(res => this.accountTypes = res); this.userService.accountsSubject.subscribe(accounts => { this.dataSource = new MatTableDataSource(accounts);