Compare commits

...

4 Commits

Author SHA1 Message Date
Spencer Ofwiti
c83cc5240e Merge remote-tracking branch 'origin/bvander/accounts-search-review' into bvander/accounts-search-review
# Conflicts:
#	src/app/_services/user.service.ts
#	src/app/pages/accounts/accounts.component.ts
2021-05-09 20:08:39 +03:00
5061dc0d32 still kinda broken 2021-05-09 10:07:49 -07:00
6f26793359 more changes 2021-05-09 09:05:36 -07:00
e5fe424185 refactor based on review 2021-05-08 12:12:33 -07:00
5 changed files with 54 additions and 27 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

@ -18,6 +18,10 @@ export class RegistryService {
this.registry.load(); this.registry.load();
} }
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';
@ -38,16 +38,34 @@ export class UserService {
private loggingService: LoggingService, private loggingService: LoggingService,
private tokenService: TokenService, private tokenService: TokenService,
private registryService: RegistryService, private registryService: RegistryService,
private authService: AuthService, private authService: AuthService
) { ) {
this.authService.init().then(() => { //this.authService.init().then(() => {
this.keystore = authService.mutableKeyStore; // this.keystore = authService.mutableKeyStore;
this.signer = new PGPSigner(this.keystore); // this.signer = new PGPSigner(this.keystore);
}); //});
this.registry = registryService.getRegistry(); //this.registry = registryService.getRegistry();
this.registry.load(); //this.registry.load();
} }
async load(): Promise<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> { resetPin(phone: string): Observable<any> {
const params: HttpParams = new HttpParams().set('phoneNumber', phone); const params: HttpParams = new HttpParams().set('phoneNumber', phone);
return this.httpClient.get(`${environment.cicUssdUrl}/pin`, {params}); return this.httpClient.get(`${environment.cicUssdUrl}/pin`, {params});
@ -148,10 +166,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();
const accountIndexAddress: string = await this.registry.getContractAddressByName('AccountRegistry'); let accountAddresses: Array<string>;
const accountIndexQuery = new AccountIndex(accountIndexAddress); try {
const accountAddresses: Array<string> = await accountIndexQuery.last(await accountIndexQuery.totalAccounts()); const accountIndexAddress: string = await this.registry.getContractAddressByName('AccountRegistry');
this.loggingService.sendInfoLevelMessage(accountAddresses); 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)) { for (const accountAddress of accountAddresses.slice(offset, offset + limit)) {
await this.getAccountByAddress(accountAddress, limit); await this.getAccountByAddress(accountAddress, limit);
} }
@ -216,3 +241,5 @@ export class UserService {
return this.httpClient.get(`${environment.cicMetaUrl}/genders`); return this.httpClient.get(`${environment.cicMetaUrl}/genders`);
} }
} }

View File

@ -9,6 +9,8 @@ import {strip0x} from '@src/assets/js/ethtx/dist/hex';
import {first} from 'rxjs/operators'; import {first} from 'rxjs/operators';
import {environment} from '@src/environments/environment'; import {environment} from '@src/environments/environment';
import {AccountDetails} from '@app/_models'; import {AccountDetails} from '@app/_models';
import {Observable, of} from 'rxjs';
@Component({ @Component({
selector: 'app-accounts', selector: 'app-accounts',
@ -30,22 +32,16 @@ export class AccountsComponent implements OnInit {
constructor( constructor(
private userService: UserService, private userService: UserService,
private loggingService: LoggingService, private router: Router,
private router: Router private loggingService: LoggingService
) )
{ {
(async () => { this.userService = userService;
try {
// TODO it feels like this should be in the onInit handler
await this.userService.loadAccounts(100);
} catch (error) {
this.loggingService.sendErrorLevelMessage('Failed to load accounts', this, {error});
}
})();
this.userService.getAccountTypes().pipe(first()).subscribe(res => this.accountTypes = res);
} }
ngOnInit(): void { ngOnInit(): void {
of(this.userService.load())
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);
this.dataSource.paginator = this.paginator; this.dataSource.paginator = this.paginator;

View File

@ -7,10 +7,10 @@ export const environment = {
serverLogLevel: NgxLoggerLevel.OFF, serverLogLevel: NgxLoggerLevel.OFF,
loggingUrl: 'http://localhost:8000', loggingUrl: 'http://localhost:8000',
cicMetaUrl: 'https://meta.dev.grassrootseconomics.net', cicMetaUrl: 'https://meta.dev.grassrootseconomics.net',
publicKeysUrl: 'http://localhost:8000/keys.asc', publicKeysUrl: 'https://dev.grassrootseconomics.net/.well-known/publickeys/',
cicCacheUrl: 'https://cache.dev.grassrootseconomics.net', cicCacheUrl: 'https://cache.dev.grassrootseconomics.net',
web3Provider: 'ws://localhost:63546', web3Provider: 'wss://bloxberg-ws.dev.grassrootseconomics.net',
cicUssdUrl: 'https://ussd.dev.grassrootseconomics.net', cicUssdUrl: 'https://ussd.dev.grassrootseconomics.net',
registryAddress: '0x6Ca3cB14aA6F761712E1C18646AfBA4d5Ae249E8', registryAddress: '0xea6225212005e86a4490018ded4bf37f3e772161',
trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C' trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C'
}; };