more changes

This commit is contained in:
Blair Vanderlugt 2021-05-09 09:05:36 -07:00
parent e5fe424185
commit 6f26793359
4 changed files with 35 additions and 16 deletions

View File

@ -35,7 +35,7 @@ http {
location / { location / {
root /usr/share/nginx/html; root /usr/share/nginx/html;
index index.html index.htm; index index.html index.htm;
try_files $uri $uri/ /index.html =404; try_files $uri $uri/ /index.html;
} }
} }
} }

View File

@ -17,6 +17,10 @@ export class RegistryService {
this.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress); this.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress);
} }
async load(): Promise<any> {
this.registry.load();
}
getRegistry(): any { getRegistry(): any {
return this.registry; return this.registry;
} }

View File

@ -1,5 +1,5 @@
import {Injectable} from '@angular/core'; 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 {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
import {environment} from '@src/environments/environment'; import {environment} from '@src/environments/environment';
import {first} from 'rxjs/operators'; import {first} from 'rxjs/operators';
@ -40,17 +40,24 @@ export class UserService {
private registryService: RegistryService, private registryService: RegistryService,
private authService: AuthService private authService: AuthService
) { ) {
this.authService = authService;
this.registryService = registryService;
} }
async load(): Promise<void> { await load(): Observable<any> {
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.authService.init();
// TODO you don't have to do this reassignment await this.registryService.load();
// TODO key store is defined
this.keystore = this.authService.mutableKeyStore; this.keystore = this.authService.mutableKeyStore;
this.signer = new PGPSigner(this.keystore); this.signer = new PGPSigner(this.keystore);
this.registry = this.registryService.getRegistry(); this.registry = this.registryService.getRegistry();
await this.registry.load(); return of(0);
} catch (error) {
console.log('ERROR: Failed to initiialize User Service', error)
return throwError(error);
}
} }
resetPin(phone: string): Observable<any> { resetPin(phone: string): Observable<any> {
@ -153,10 +160,17 @@ export class UserService {
async loadAccounts(limit: number = 100, offset: number = 0): Promise<void> { async loadAccounts(limit: number = 100, offset: number = 0): Promise<void> {
this.resetAccountsList(); this.resetAccountsList();
let accountAddresses: Array<string>;
try {
const accountIndexAddress: string = await this.registry.getContractAddressByName('AccountRegistry'); const accountIndexAddress: string = await this.registry.getContractAddressByName('AccountRegistry');
const accountIndexQuery = new AccountIndex(accountIndexAddress); const accountIndexQuery = new AccountIndex(accountIndexAddress);
const accountAddresses: Array<string> = await accountIndexQuery.last(await accountIndexQuery.totalAccounts()); const totalAccounts = await accountIndexQuery.totalAccounts()
const accountAddresses = await accountIndexQuery.last(totalAccounts);
this.loggingService.sendInfoLevelMessage(accountAddresses); 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)) { for (const accountAddress of accountAddresses.slice(offset, offset + limit)) {
await this.getAccountByAddress(accountAddress, limit); await this.getAccountByAddress(accountAddress, limit);
} }

View File

@ -34,10 +34,11 @@ export class AccountsComponent implements OnInit {
private loggingService: LoggingService private loggingService: LoggingService
) )
{ {
this.userService = userService;
} }
ngOnInit(): void { ngOnInit(): void {
// TODO end of the line you gotta be an observalbe or a promise
this.userService.load();
this.userService.getAccountTypes().pipe(first()).subscribe(res => this.accountTypes = res); this.userService.getAccountTypes().pipe(first()).subscribe(res => this.accountTypes = res);
this.userService.accountsSubject.subscribe(accounts => { this.userService.accountsSubject.subscribe(accounts => {
this.dataSource = new MatTableDataSource<any>(accounts); this.dataSource = new MatTableDataSource<any>(accounts);