|
|
|
|
@@ -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,24 @@ export class UserService {
|
|
|
|
|
private registryService: RegistryService,
|
|
|
|
|
private authService: AuthService
|
|
|
|
|
) {
|
|
|
|
|
this.authService = authService;
|
|
|
|
|
this.registryService = registryService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async load(): Promise<void> {
|
|
|
|
|
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();
|
|
|
|
|
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.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<any> {
|
|
|
|
|
@@ -153,10 +160,17 @@ export class UserService {
|
|
|
|
|
|
|
|
|
|
async loadAccounts(limit: number = 100, offset: number = 0): Promise<void> {
|
|
|
|
|
this.resetAccountsList();
|
|
|
|
|
const accountIndexAddress: string = await this.registry.getContractAddressByName('AccountRegistry');
|
|
|
|
|
const accountIndexQuery = new AccountIndex(accountIndexAddress);
|
|
|
|
|
const accountAddresses: Array<string> = await accountIndexQuery.last(await accountIndexQuery.totalAccounts());
|
|
|
|
|
this.loggingService.sendInfoLevelMessage(accountAddresses);
|
|
|
|
|
let accountAddresses: Array<string>;
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|