Refactor data load process.
- Move data loading to app component. - Move services init calls to app component.
This commit is contained in:
parent
a070cbe710
commit
e1bb7355e3
@ -4,7 +4,6 @@ import { TransactionHelper } from '@cicnet/cic-client';
|
|||||||
import { first } from 'rxjs/operators';
|
import { first } from 'rxjs/operators';
|
||||||
import { TransactionService } from '@app/_services/transaction.service';
|
import { TransactionService } from '@app/_services/transaction.service';
|
||||||
import { environment } from '@src/environments/environment';
|
import { environment } from '@src/environments/environment';
|
||||||
import { LoggingService } from '@app/_services/logging.service';
|
|
||||||
import { RegistryService } from '@app/_services/registry.service';
|
import { RegistryService } from '@app/_services/registry.service';
|
||||||
import { Web3Service } from '@app/_services/web3.service';
|
import { Web3Service } from '@app/_services/web3.service';
|
||||||
|
|
||||||
@ -17,13 +16,8 @@ export class BlockSyncService {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private transactionService: TransactionService,
|
private transactionService: TransactionService,
|
||||||
private loggingService: LoggingService
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async init(): Promise<void> {
|
|
||||||
await this.transactionService.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
async blockSync(address: string = null, offset: number = 0, limit: number = 100): Promise<void> {
|
async blockSync(address: string = null, offset: number = 0, limit: number = 100): Promise<void> {
|
||||||
this.transactionService.resetTransactionsList();
|
this.transactionService.resetTransactionsList();
|
||||||
const settings: Settings = new Settings(this.scan);
|
const settings: Settings = new Settings(this.scan);
|
||||||
|
@ -42,8 +42,6 @@ export class TransactionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async init(): Promise<void> {
|
async init(): Promise<void> {
|
||||||
await this.authService.init();
|
|
||||||
await this.userService.init();
|
|
||||||
this.registry = await RegistryService.getRegistry();
|
this.registry = await RegistryService.getRegistry();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,11 +7,9 @@ import { ArgPair, Envelope, Phone, Syncable, User } from 'cic-client-meta';
|
|||||||
import { AccountDetails } from '@app/_models';
|
import { AccountDetails } from '@app/_models';
|
||||||
import { LoggingService } from '@app/_services/logging.service';
|
import { LoggingService } from '@app/_services/logging.service';
|
||||||
import { TokenService } from '@app/_services/token.service';
|
import { TokenService } from '@app/_services/token.service';
|
||||||
import { AccountIndex } from '@app/_eth';
|
|
||||||
import { MutableKeyStore, PGPSigner, Signer } from '@app/_pgp';
|
import { MutableKeyStore, PGPSigner, Signer } from '@app/_pgp';
|
||||||
import { RegistryService } from '@app/_services/registry.service';
|
import { RegistryService } from '@app/_services/registry.service';
|
||||||
import { CICRegistry } from '@cicnet/cic-client';
|
import { CICRegistry } from '@cicnet/cic-client';
|
||||||
import { AuthService } from '@app/_services/auth.service';
|
|
||||||
import { personValidation, updateSyncable, vcardValidation } from '@app/_helpers';
|
import { personValidation, updateSyncable, vcardValidation } from '@app/_helpers';
|
||||||
import { add0x } from '@src/assets/js/ethtx/dist/hex';
|
import { add0x } from '@src/assets/js/ethtx/dist/hex';
|
||||||
import { KeystoreService } from '@app/_services/keystore.service';
|
import { KeystoreService } from '@app/_services/keystore.service';
|
||||||
@ -44,12 +42,9 @@ export class UserService {
|
|||||||
private httpClient: HttpClient,
|
private httpClient: HttpClient,
|
||||||
private loggingService: LoggingService,
|
private loggingService: LoggingService,
|
||||||
private tokenService: TokenService,
|
private tokenService: TokenService,
|
||||||
private authService: AuthService
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async init(): Promise<void> {
|
async init(): Promise<void> {
|
||||||
await this.authService.init();
|
|
||||||
await this.tokenService.init();
|
|
||||||
this.keystore = await KeystoreService.getKeystore();
|
this.keystore = await KeystoreService.getKeystore();
|
||||||
this.signer = new PGPSigner(this.keystore);
|
this.signer = new PGPSigner(this.keystore);
|
||||||
this.registry = await RegistryService.getRegistry();
|
this.registry = await RegistryService.getRegistry();
|
||||||
@ -204,11 +199,6 @@ 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'
|
|
||||||
// );
|
|
||||||
// const accountIndexQuery = new AccountIndex(accountIndexAddress);
|
|
||||||
// const accountAddresses: Array<string> = await accountIndexQuery.last(limit);
|
|
||||||
try {
|
try {
|
||||||
const accountRegistry = await RegistryService.getAccountRegistry();
|
const accountRegistry = await RegistryService.getAccountRegistry();
|
||||||
const accountAddresses: Array<string> = await accountRegistry.last(limit);
|
const accountAddresses: Array<string> = await accountRegistry.last(limit);
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
import { ChangeDetectionStrategy, Component, HostListener, OnInit } from '@angular/core';
|
import { ChangeDetectionStrategy, Component, HostListener, OnInit } from '@angular/core';
|
||||||
import {
|
import {
|
||||||
AuthService,
|
AuthService, BlockSyncService,
|
||||||
ErrorDialogService,
|
ErrorDialogService,
|
||||||
LoggingService,
|
LoggingService, TokenService,
|
||||||
TransactionService,
|
TransactionService, UserService,
|
||||||
} from '@app/_services';
|
} from '@app/_services';
|
||||||
import { catchError } from 'rxjs/operators';
|
|
||||||
import { SwUpdate } from '@angular/service-worker';
|
import { SwUpdate } from '@angular/service-worker';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -22,9 +21,12 @@ export class AppComponent implements OnInit {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
private transactionService: TransactionService,
|
private blockSyncService: BlockSyncService,
|
||||||
private loggingService: LoggingService,
|
|
||||||
private errorDialogService: ErrorDialogService,
|
private errorDialogService: ErrorDialogService,
|
||||||
|
private loggingService: LoggingService,
|
||||||
|
private tokenService: TokenService,
|
||||||
|
private transactionService: TransactionService,
|
||||||
|
private userService: UserService,
|
||||||
private swUpdate: SwUpdate
|
private swUpdate: SwUpdate
|
||||||
) {
|
) {
|
||||||
this.mediaQuery.addEventListener('change', this.onResize);
|
this.mediaQuery.addEventListener('change', this.onResize);
|
||||||
@ -33,7 +35,10 @@ export class AppComponent implements OnInit {
|
|||||||
|
|
||||||
async ngOnInit(): Promise<void> {
|
async ngOnInit(): Promise<void> {
|
||||||
await this.authService.init();
|
await this.authService.init();
|
||||||
|
await this.tokenService.init();
|
||||||
|
await this.userService.init();
|
||||||
await this.transactionService.init();
|
await this.transactionService.init();
|
||||||
|
await this.blockSyncService.blockSync();
|
||||||
try {
|
try {
|
||||||
const publicKeys = await this.authService.getPublicKeys();
|
const publicKeys = await this.authService.getPublicKeys();
|
||||||
await this.authService.mutableKeyStore.importPublicKey(publicKeys);
|
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 🦗?
|
// 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) {
|
if (!this.swUpdate.isEnabled) {
|
||||||
this.swUpdate.available.subscribe(() => {
|
this.swUpdate.available.subscribe(() => {
|
||||||
if (confirm('New Version available. Load New Version?')) {
|
if (confirm('New Version available. Load New Version?')) {
|
||||||
|
@ -3,7 +3,6 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
|||||||
import { CustomErrorStateMatcher } from '@app/_helpers';
|
import { CustomErrorStateMatcher } from '@app/_helpers';
|
||||||
import { AuthService } from '@app/_services';
|
import { AuthService } from '@app/_services';
|
||||||
import { ErrorDialogService } from '@app/_services/error-dialog.service';
|
import { ErrorDialogService } from '@app/_services/error-dialog.service';
|
||||||
import { LoggingService } from '@app/_services/logging.service';
|
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -25,7 +24,7 @@ export class AuthComponent implements OnInit {
|
|||||||
private errorDialogService: ErrorDialogService
|
private errorDialogService: ErrorDialogService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async ngOnInit(): Promise<void> {
|
ngOnInit(): void {
|
||||||
this.keyForm = this.formBuilder.group({
|
this.keyForm = this.formBuilder.group({
|
||||||
key: ['', Validators.required],
|
key: ['', Validators.required],
|
||||||
});
|
});
|
||||||
|
@ -103,10 +103,6 @@ export class AccountDetailsComponent implements OnInit {
|
|||||||
location: ['', Validators.required],
|
location: ['', Validators.required],
|
||||||
locationType: ['', 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);
|
await this.blockSyncService.blockSync(this.accountAddress);
|
||||||
this.userService.resetAccountsList();
|
this.userService.resetAccountsList();
|
||||||
(await this.userService.getAccountByAddress(this.accountAddress, 100)).subscribe(
|
(await this.userService.getAccountByAddress(this.accountAddress, 100)).subscribe(
|
||||||
@ -114,7 +110,6 @@ export class AccountDetailsComponent implements OnInit {
|
|||||||
if (res !== undefined) {
|
if (res !== undefined) {
|
||||||
this.account = res;
|
this.account = res;
|
||||||
this.cdr.detectChanges();
|
this.cdr.detectChanges();
|
||||||
this.loggingService.sendInfoLevelMessage(this.account);
|
|
||||||
this.locationService.areaNamesSubject.subscribe((response) => {
|
this.locationService.areaNamesSubject.subscribe((response) => {
|
||||||
this.area = this.locationService.getAreaNameByLocation(
|
this.area = this.locationService.getAreaNameByLocation(
|
||||||
this.account.location.area_name,
|
this.account.location.area_name,
|
||||||
|
@ -40,9 +40,7 @@ export class AccountSearchComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async ngOnInit(): Promise<void> {
|
ngOnInit(): void {}
|
||||||
await this.userService.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
get nameSearchFormStub(): any {
|
get nameSearchFormStub(): any {
|
||||||
return this.nameSearchForm.controls;
|
return this.nameSearchForm.controls;
|
||||||
|
@ -2,7 +2,7 @@ import { ChangeDetectionStrategy, Component, OnInit, ViewChild } from '@angular/
|
|||||||
import { MatTableDataSource } from '@angular/material/table';
|
import { MatTableDataSource } from '@angular/material/table';
|
||||||
import { MatPaginator } from '@angular/material/paginator';
|
import { MatPaginator } from '@angular/material/paginator';
|
||||||
import { MatSort } from '@angular/material/sort';
|
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 { Router } from '@angular/router';
|
||||||
import { exportCsv } from '@app/_helpers';
|
import { exportCsv } from '@app/_helpers';
|
||||||
import { strip0x } from '@src/assets/js/ethtx/dist/hex';
|
import { strip0x } from '@src/assets/js/ethtx/dist/hex';
|
||||||
@ -31,20 +31,11 @@ export class AccountsComponent implements OnInit {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private userService: UserService,
|
private userService: UserService,
|
||||||
private loggingService: LoggingService,
|
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private tokenService: TokenService
|
private tokenService: TokenService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async ngOnInit(): Promise<void> {
|
ngOnInit(): void {
|
||||||
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 });
|
|
||||||
}
|
|
||||||
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;
|
||||||
|
@ -25,8 +25,7 @@ export class CreateAccountComponent implements OnInit {
|
|||||||
private userService: UserService
|
private userService: UserService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async ngOnInit(): Promise<void> {
|
ngOnInit(): void {
|
||||||
await this.userService.init();
|
|
||||||
this.createForm = this.formBuilder.group({
|
this.createForm = this.formBuilder.group({
|
||||||
accountType: ['', Validators.required],
|
accountType: ['', Validators.required],
|
||||||
idNumber: ['', Validators.required],
|
idNumber: ['', Validators.required],
|
||||||
|
@ -6,7 +6,7 @@ import { LoggingService, UserService } from '@app/_services';
|
|||||||
import { animate, state, style, transition, trigger } from '@angular/animations';
|
import { animate, state, style, transition, trigger } from '@angular/animations';
|
||||||
import { first } from 'rxjs/operators';
|
import { first } from 'rxjs/operators';
|
||||||
import { exportCsv } from '@app/_helpers';
|
import { exportCsv } from '@app/_helpers';
|
||||||
import { Action } from '../../_models';
|
import { Action } from '@app/_models';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-admin',
|
selector: 'app-admin',
|
||||||
@ -32,8 +32,7 @@ export class AdminComponent implements OnInit {
|
|||||||
|
|
||||||
constructor(private userService: UserService, private loggingService: LoggingService) {}
|
constructor(private userService: UserService, private loggingService: LoggingService) {}
|
||||||
|
|
||||||
async ngOnInit(): Promise<void> {
|
ngOnInit(): void {
|
||||||
await this.userService.init();
|
|
||||||
this.userService.getActions();
|
this.userService.getActions();
|
||||||
this.userService.actionsSubject.subscribe((actions) => {
|
this.userService.actionsSubject.subscribe((actions) => {
|
||||||
this.dataSource = new MatTableDataSource<any>(actions);
|
this.dataSource = new MatTableDataSource<any>(actions);
|
||||||
|
@ -24,8 +24,7 @@ export class SettingsComponent implements OnInit {
|
|||||||
|
|
||||||
constructor(private authService: AuthService) {}
|
constructor(private authService: AuthService) {}
|
||||||
|
|
||||||
async ngOnInit(): Promise<void> {
|
ngOnInit(): void {
|
||||||
await this.authService.init();
|
|
||||||
this.authService.trustedUsersSubject.subscribe((users) => {
|
this.authService.trustedUsersSubject.subscribe((users) => {
|
||||||
this.dataSource = new MatTableDataSource<any>(users);
|
this.dataSource = new MatTableDataSource<any>(users);
|
||||||
this.dataSource.paginator = this.paginator;
|
this.dataSource.paginator = this.paginator;
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import { ChangeDetectionStrategy, Component, OnInit, ViewChild } from '@angular/core';
|
import { ChangeDetectionStrategy, Component, OnInit, ViewChild } from '@angular/core';
|
||||||
import { MatPaginator } from '@angular/material/paginator';
|
import { MatPaginator } from '@angular/material/paginator';
|
||||||
import { MatSort } from '@angular/material/sort';
|
import { MatSort } from '@angular/material/sort';
|
||||||
import { LoggingService, TokenService } from '@app/_services';
|
import { TokenService } from '@app/_services';
|
||||||
import { MatTableDataSource } from '@angular/material/table';
|
import { MatTableDataSource } from '@angular/material/table';
|
||||||
import { Router } from '@angular/router';
|
|
||||||
import { exportCsv } from '@app/_helpers';
|
import { exportCsv } from '@app/_helpers';
|
||||||
import { Token } from '@app/_models';
|
import { Token } from '@app/_models';
|
||||||
|
|
||||||
@ -23,19 +22,15 @@ export class TokensComponent implements OnInit {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private tokenService: TokenService,
|
private tokenService: TokenService,
|
||||||
private loggingService: LoggingService,
|
|
||||||
private router: Router
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async ngOnInit(): Promise<void> {
|
ngOnInit(): void {
|
||||||
await this.tokenService.init();
|
|
||||||
this.tokenService.load.subscribe(async (status: boolean) => {
|
this.tokenService.load.subscribe(async (status: boolean) => {
|
||||||
if (status) {
|
if (status) {
|
||||||
await this.tokenService.getTokens();
|
await this.tokenService.getTokens();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.tokenService.tokensSubject.subscribe((tokens) => {
|
this.tokenService.tokensSubject.subscribe((tokens) => {
|
||||||
this.loggingService.sendInfoLevelMessage(tokens);
|
|
||||||
this.dataSource = new MatTableDataSource(tokens);
|
this.dataSource = new MatTableDataSource(tokens);
|
||||||
this.dataSource.paginator = this.paginator;
|
this.dataSource.paginator = this.paginator;
|
||||||
this.dataSource.sort = this.sort;
|
this.dataSource.sort = this.sort;
|
||||||
|
@ -36,9 +36,7 @@ export class TransactionDetailsComponent implements OnInit {
|
|||||||
private tokenService: TokenService
|
private tokenService: TokenService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async ngOnInit(): Promise<void> {
|
ngOnInit(): void {
|
||||||
await this.transactionService.init();
|
|
||||||
await this.tokenService.init();
|
|
||||||
if (this.transaction?.type === 'conversion') {
|
if (this.transaction?.type === 'conversion') {
|
||||||
this.traderBloxbergLink =
|
this.traderBloxbergLink =
|
||||||
'https://blockexplorer.bloxberg.org/address/' + this.transaction?.trader + '/transactions';
|
'https://blockexplorer.bloxberg.org/address/' + this.transaction?.trader + '/transactions';
|
||||||
|
@ -5,7 +5,7 @@ import {
|
|||||||
OnInit,
|
OnInit,
|
||||||
ViewChild,
|
ViewChild,
|
||||||
} from '@angular/core';
|
} 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 { MatTableDataSource } from '@angular/material/table';
|
||||||
import { MatPaginator } from '@angular/material/paginator';
|
import { MatPaginator } from '@angular/material/paginator';
|
||||||
import { MatSort } from '@angular/material/sort';
|
import { MatSort } from '@angular/material/sort';
|
||||||
@ -34,24 +34,18 @@ export class TransactionsComponent implements OnInit, AfterViewInit {
|
|||||||
@ViewChild(MatSort) sort: MatSort;
|
@ViewChild(MatSort) sort: MatSort;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private blockSyncService: BlockSyncService,
|
|
||||||
private transactionService: TransactionService,
|
private transactionService: TransactionService,
|
||||||
private userService: UserService,
|
private userService: UserService,
|
||||||
private tokenService: TokenService
|
private tokenService: TokenService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async ngOnInit(): Promise<void> {
|
ngOnInit(): void {
|
||||||
this.transactionService.transactionsSubject.subscribe((transactions) => {
|
this.transactionService.transactionsSubject.subscribe((transactions) => {
|
||||||
this.transactionDataSource = new MatTableDataSource<any>(transactions);
|
this.transactionDataSource = new MatTableDataSource<any>(transactions);
|
||||||
this.transactionDataSource.paginator = this.paginator;
|
this.transactionDataSource.paginator = this.paginator;
|
||||||
this.transactionDataSource.sort = this.sort;
|
this.transactionDataSource.sort = this.sort;
|
||||||
this.transactions = transactions;
|
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
|
this.userService
|
||||||
.getTransactionTypes()
|
.getTransactionTypes()
|
||||||
.pipe(first())
|
.pipe(first())
|
||||||
|
Loading…
Reference in New Issue
Block a user