diff --git a/src/app/_services/block-sync.service.ts b/src/app/_services/block-sync.service.ts index 785d452..987f0be 100644 --- a/src/app/_services/block-sync.service.ts +++ b/src/app/_services/block-sync.service.ts @@ -4,7 +4,6 @@ import { TransactionHelper } from '@cicnet/cic-client'; import { first } from 'rxjs/operators'; import { TransactionService } from '@app/_services/transaction.service'; import { environment } from '@src/environments/environment'; -import { LoggingService } from '@app/_services/logging.service'; import { RegistryService } from '@app/_services/registry.service'; import { Web3Service } from '@app/_services/web3.service'; @@ -17,13 +16,8 @@ export class BlockSyncService { constructor( private transactionService: TransactionService, - private loggingService: LoggingService ) {} - async init(): Promise { - await this.transactionService.init(); - } - async blockSync(address: string = null, offset: number = 0, limit: number = 100): Promise { this.transactionService.resetTransactionsList(); const settings: Settings = new Settings(this.scan); diff --git a/src/app/_services/transaction.service.ts b/src/app/_services/transaction.service.ts index 1977c3e..834c39c 100644 --- a/src/app/_services/transaction.service.ts +++ b/src/app/_services/transaction.service.ts @@ -42,8 +42,6 @@ export class TransactionService { } async init(): Promise { - await this.authService.init(); - await this.userService.init(); this.registry = await RegistryService.getRegistry(); } diff --git a/src/app/_services/user.service.ts b/src/app/_services/user.service.ts index 975dd72..6f7652a 100644 --- a/src/app/_services/user.service.ts +++ b/src/app/_services/user.service.ts @@ -7,11 +7,9 @@ import { ArgPair, Envelope, Phone, Syncable, User } from 'cic-client-meta'; import { AccountDetails } from '@app/_models'; import { LoggingService } from '@app/_services/logging.service'; import { TokenService } from '@app/_services/token.service'; -import { AccountIndex } from '@app/_eth'; import { MutableKeyStore, PGPSigner, Signer } from '@app/_pgp'; import { RegistryService } from '@app/_services/registry.service'; import { CICRegistry } from '@cicnet/cic-client'; -import { AuthService } from '@app/_services/auth.service'; import { personValidation, updateSyncable, vcardValidation } from '@app/_helpers'; import { add0x } from '@src/assets/js/ethtx/dist/hex'; import { KeystoreService } from '@app/_services/keystore.service'; @@ -44,12 +42,9 @@ export class UserService { private httpClient: HttpClient, private loggingService: LoggingService, private tokenService: TokenService, - private authService: AuthService ) {} async init(): Promise { - await this.authService.init(); - await this.tokenService.init(); this.keystore = await KeystoreService.getKeystore(); this.signer = new PGPSigner(this.keystore); this.registry = await RegistryService.getRegistry(); @@ -204,11 +199,6 @@ 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(limit); try { const accountRegistry = await RegistryService.getAccountRegistry(); const accountAddresses: Array = await accountRegistry.last(limit); diff --git a/src/app/app.component.ts b/src/app/app.component.ts index d9e4a2e..f305a22 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,11 +1,10 @@ import { ChangeDetectionStrategy, Component, HostListener, OnInit } from '@angular/core'; import { - AuthService, + AuthService, BlockSyncService, ErrorDialogService, - LoggingService, - TransactionService, + LoggingService, TokenService, + TransactionService, UserService, } from '@app/_services'; -import { catchError } from 'rxjs/operators'; import { SwUpdate } from '@angular/service-worker'; @Component({ @@ -22,9 +21,12 @@ export class AppComponent implements OnInit { constructor( private authService: AuthService, - private transactionService: TransactionService, - private loggingService: LoggingService, + private blockSyncService: BlockSyncService, private errorDialogService: ErrorDialogService, + private loggingService: LoggingService, + private tokenService: TokenService, + private transactionService: TransactionService, + private userService: UserService, private swUpdate: SwUpdate ) { this.mediaQuery.addEventListener('change', this.onResize); @@ -33,7 +35,10 @@ export class AppComponent implements OnInit { async ngOnInit(): Promise { await this.authService.init(); + await this.tokenService.init(); + await this.userService.init(); await this.transactionService.init(); + await this.blockSyncService.blockSync(); try { const publicKeys = await this.authService.getPublicKeys(); await this.authService.mutableKeyStore.importPublicKey(publicKeys); @@ -44,6 +49,12 @@ export class AppComponent implements OnInit { }); // TODO do something to halt user progress...show a sad cicada page 🦗? } + 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 }); + } if (!this.swUpdate.isEnabled) { this.swUpdate.available.subscribe(() => { if (confirm('New Version available. Load New Version?')) { diff --git a/src/app/auth/auth.component.ts b/src/app/auth/auth.component.ts index 5c507f3..2981c63 100644 --- a/src/app/auth/auth.component.ts +++ b/src/app/auth/auth.component.ts @@ -3,7 +3,6 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { CustomErrorStateMatcher } from '@app/_helpers'; import { AuthService } from '@app/_services'; import { ErrorDialogService } from '@app/_services/error-dialog.service'; -import { LoggingService } from '@app/_services/logging.service'; import { Router } from '@angular/router'; @Component({ @@ -25,7 +24,7 @@ export class AuthComponent implements OnInit { private errorDialogService: ErrorDialogService ) {} - async ngOnInit(): Promise { + ngOnInit(): void { this.keyForm = this.formBuilder.group({ key: ['', Validators.required], }); diff --git a/src/app/pages/accounts/account-details/account-details.component.ts b/src/app/pages/accounts/account-details/account-details.component.ts index 5290a9a..e1b680e 100644 --- a/src/app/pages/accounts/account-details/account-details.component.ts +++ b/src/app/pages/accounts/account-details/account-details.component.ts @@ -103,10 +103,6 @@ export class AccountDetailsComponent implements OnInit { location: ['', Validators.required], locationType: ['', Validators.required], }); - await this.blockSyncService.init(); - await this.tokenService.init(); - await this.transactionService.init(); - await this.userService.init(); await this.blockSyncService.blockSync(this.accountAddress); this.userService.resetAccountsList(); (await this.userService.getAccountByAddress(this.accountAddress, 100)).subscribe( @@ -114,7 +110,6 @@ export class AccountDetailsComponent implements OnInit { if (res !== undefined) { this.account = res; this.cdr.detectChanges(); - this.loggingService.sendInfoLevelMessage(this.account); this.locationService.areaNamesSubject.subscribe((response) => { this.area = this.locationService.getAreaNameByLocation( this.account.location.area_name, diff --git a/src/app/pages/accounts/account-search/account-search.component.ts b/src/app/pages/accounts/account-search/account-search.component.ts index f0ea97d..47daed9 100644 --- a/src/app/pages/accounts/account-search/account-search.component.ts +++ b/src/app/pages/accounts/account-search/account-search.component.ts @@ -40,9 +40,7 @@ export class AccountSearchComponent implements OnInit { }); } - async ngOnInit(): Promise { - await this.userService.init(); - } + ngOnInit(): void {} get nameSearchFormStub(): any { return this.nameSearchForm.controls; diff --git a/src/app/pages/accounts/accounts.component.ts b/src/app/pages/accounts/accounts.component.ts index d23735b..18368d3 100644 --- a/src/app/pages/accounts/accounts.component.ts +++ b/src/app/pages/accounts/accounts.component.ts @@ -2,7 +2,7 @@ import { ChangeDetectionStrategy, Component, OnInit, ViewChild } from '@angular/ import { MatTableDataSource } from '@angular/material/table'; import { MatPaginator } from '@angular/material/paginator'; import { MatSort } from '@angular/material/sort'; -import { LoggingService, TokenService, UserService } from '@app/_services'; +import { TokenService, UserService } from '@app/_services'; import { Router } from '@angular/router'; import { exportCsv } from '@app/_helpers'; import { strip0x } from '@src/assets/js/ethtx/dist/hex'; @@ -31,20 +31,11 @@ export class AccountsComponent implements OnInit { constructor( private userService: UserService, - private loggingService: LoggingService, private router: Router, private tokenService: TokenService ) {} - async ngOnInit(): Promise { - await this.userService.init(); - await this.tokenService.init(); - 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 }); - } + ngOnInit(): void { this.userService.accountsSubject.subscribe((accounts) => { this.dataSource = new MatTableDataSource(accounts); this.dataSource.paginator = this.paginator; diff --git a/src/app/pages/accounts/create-account/create-account.component.ts b/src/app/pages/accounts/create-account/create-account.component.ts index ab6dfbc..c29d714 100644 --- a/src/app/pages/accounts/create-account/create-account.component.ts +++ b/src/app/pages/accounts/create-account/create-account.component.ts @@ -25,8 +25,7 @@ export class CreateAccountComponent implements OnInit { private userService: UserService ) {} - async ngOnInit(): Promise { - await this.userService.init(); + ngOnInit(): void { this.createForm = this.formBuilder.group({ accountType: ['', Validators.required], idNumber: ['', Validators.required], diff --git a/src/app/pages/admin/admin.component.ts b/src/app/pages/admin/admin.component.ts index d33be3c..6dcfd5f 100644 --- a/src/app/pages/admin/admin.component.ts +++ b/src/app/pages/admin/admin.component.ts @@ -6,7 +6,7 @@ import { LoggingService, UserService } from '@app/_services'; import { animate, state, style, transition, trigger } from '@angular/animations'; import { first } from 'rxjs/operators'; import { exportCsv } from '@app/_helpers'; -import { Action } from '../../_models'; +import { Action } from '@app/_models'; @Component({ selector: 'app-admin', @@ -32,8 +32,7 @@ export class AdminComponent implements OnInit { constructor(private userService: UserService, private loggingService: LoggingService) {} - async ngOnInit(): Promise { - await this.userService.init(); + ngOnInit(): void { this.userService.getActions(); this.userService.actionsSubject.subscribe((actions) => { this.dataSource = new MatTableDataSource(actions); diff --git a/src/app/pages/settings/settings.component.ts b/src/app/pages/settings/settings.component.ts index 8e167b0..2ec1a80 100644 --- a/src/app/pages/settings/settings.component.ts +++ b/src/app/pages/settings/settings.component.ts @@ -24,8 +24,7 @@ export class SettingsComponent implements OnInit { constructor(private authService: AuthService) {} - async ngOnInit(): Promise { - await this.authService.init(); + ngOnInit(): void { this.authService.trustedUsersSubject.subscribe((users) => { this.dataSource = new MatTableDataSource(users); this.dataSource.paginator = this.paginator; diff --git a/src/app/pages/tokens/tokens.component.ts b/src/app/pages/tokens/tokens.component.ts index 9f96497..11cdb1a 100644 --- a/src/app/pages/tokens/tokens.component.ts +++ b/src/app/pages/tokens/tokens.component.ts @@ -1,9 +1,8 @@ import { ChangeDetectionStrategy, Component, OnInit, ViewChild } from '@angular/core'; import { MatPaginator } from '@angular/material/paginator'; import { MatSort } from '@angular/material/sort'; -import { LoggingService, TokenService } from '@app/_services'; +import { TokenService } from '@app/_services'; import { MatTableDataSource } from '@angular/material/table'; -import { Router } from '@angular/router'; import { exportCsv } from '@app/_helpers'; import { Token } from '@app/_models'; @@ -23,19 +22,15 @@ export class TokensComponent implements OnInit { constructor( private tokenService: TokenService, - private loggingService: LoggingService, - private router: Router ) {} - async ngOnInit(): Promise { - await this.tokenService.init(); + ngOnInit(): void { this.tokenService.load.subscribe(async (status: boolean) => { if (status) { await this.tokenService.getTokens(); } }); this.tokenService.tokensSubject.subscribe((tokens) => { - this.loggingService.sendInfoLevelMessage(tokens); this.dataSource = new MatTableDataSource(tokens); this.dataSource.paginator = this.paginator; this.dataSource.sort = this.sort; diff --git a/src/app/pages/transactions/transaction-details/transaction-details.component.ts b/src/app/pages/transactions/transaction-details/transaction-details.component.ts index 29322bb..ca324e1 100644 --- a/src/app/pages/transactions/transaction-details/transaction-details.component.ts +++ b/src/app/pages/transactions/transaction-details/transaction-details.component.ts @@ -36,9 +36,7 @@ export class TransactionDetailsComponent implements OnInit { private tokenService: TokenService ) {} - async ngOnInit(): Promise { - await this.transactionService.init(); - await this.tokenService.init(); + ngOnInit(): void { if (this.transaction?.type === 'conversion') { this.traderBloxbergLink = 'https://blockexplorer.bloxberg.org/address/' + this.transaction?.trader + '/transactions'; diff --git a/src/app/pages/transactions/transactions.component.ts b/src/app/pages/transactions/transactions.component.ts index dd25baf..d584a0e 100644 --- a/src/app/pages/transactions/transactions.component.ts +++ b/src/app/pages/transactions/transactions.component.ts @@ -5,7 +5,7 @@ import { OnInit, ViewChild, } from '@angular/core'; -import { BlockSyncService, TokenService, TransactionService, UserService } from '@app/_services'; +import { TokenService, TransactionService, UserService } from '@app/_services'; import { MatTableDataSource } from '@angular/material/table'; import { MatPaginator } from '@angular/material/paginator'; import { MatSort } from '@angular/material/sort'; @@ -34,24 +34,18 @@ export class TransactionsComponent implements OnInit, AfterViewInit { @ViewChild(MatSort) sort: MatSort; constructor( - private blockSyncService: BlockSyncService, private transactionService: TransactionService, private userService: UserService, private tokenService: TokenService ) {} - async ngOnInit(): Promise { + ngOnInit(): void { this.transactionService.transactionsSubject.subscribe((transactions) => { this.transactionDataSource = new MatTableDataSource(transactions); this.transactionDataSource.paginator = this.paginator; this.transactionDataSource.sort = this.sort; this.transactions = transactions; }); - await this.blockSyncService.init(); - await this.tokenService.init(); - await this.transactionService.init(); - await this.userService.init(); - await this.blockSyncService.blockSync(); this.userService .getTransactionTypes() .pipe(first())