Clean up constructors.
This commit is contained in:
parent
5baffa5fef
commit
a4c0e26be9
@ -16,17 +16,20 @@ export class BlockSyncService {
|
||||
|
||||
constructor(
|
||||
private transactionService: TransactionService,
|
||||
private loggingService: LoggingService,
|
||||
private registryService: RegistryService
|
||||
private loggingService: LoggingService
|
||||
) {}
|
||||
|
||||
blockSync(address: string = null, offset: number = 0, limit: number = 100): void {
|
||||
async init(): Promise<void> {
|
||||
await this.transactionService.init();
|
||||
}
|
||||
|
||||
async blockSync(address: string = null, offset: number = 0, limit: number = 100): Promise<void> {
|
||||
this.transactionService.resetTransactionsList();
|
||||
const settings: Settings = new Settings(this.scan);
|
||||
const readyStateElements: { network: number } = { network: 2 };
|
||||
settings.w3.provider = environment.web3Provider;
|
||||
settings.w3.engine = this.registryService.web3;
|
||||
settings.registry = this.registryService.registry;
|
||||
settings.w3.engine = RegistryService.web3;
|
||||
settings.registry = await RegistryService.getRegistry();
|
||||
settings.txHelper = new TransactionHelper(settings.w3.engine, settings.registry);
|
||||
|
||||
settings.txHelper.ontransfer = async (transaction: any): Promise<void> => {
|
||||
|
@ -8,18 +8,24 @@ import { HttpGetter } from '@app/_helpers';
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class RegistryService {
|
||||
web3: Web3 = new Web3(environment.web3Provider);
|
||||
fileGetter: FileGetter = new HttpGetter();
|
||||
registry: CICRegistry = new CICRegistry(
|
||||
this.web3,
|
||||
environment.registryAddress,
|
||||
'Registry',
|
||||
this.fileGetter,
|
||||
['../../assets/js/block-sync/data']
|
||||
);
|
||||
static web3: Web3 = new Web3(environment.web3Provider);
|
||||
static fileGetter: FileGetter = new HttpGetter();
|
||||
private static registry: CICRegistry;
|
||||
|
||||
constructor() {
|
||||
this.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress);
|
||||
this.registry.load();
|
||||
constructor() {}
|
||||
|
||||
public static async getRegistry(): Promise<CICRegistry> {
|
||||
if (!RegistryService.registry) {
|
||||
RegistryService.registry = new CICRegistry(
|
||||
RegistryService.web3,
|
||||
environment.registryAddress,
|
||||
'Registry',
|
||||
RegistryService.fileGetter,
|
||||
['../../assets/js/block-sync/data']
|
||||
);
|
||||
RegistryService.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress);
|
||||
await RegistryService.registry.load();
|
||||
}
|
||||
return RegistryService.registry;
|
||||
}
|
||||
}
|
||||
|
@ -14,8 +14,10 @@ export class TokenService {
|
||||
tokenRegistry: TokenRegistry;
|
||||
onload: (status: boolean) => void;
|
||||
|
||||
constructor(private httpClient: HttpClient, private registryService: RegistryService) {
|
||||
this.registry = this.registryService.registry;
|
||||
constructor(private httpClient: HttpClient) {}
|
||||
|
||||
async init(): Promise<void> {
|
||||
this.registry = await RegistryService.getRegistry();
|
||||
this.registry.onload = async (address: string): Promise<void> => {
|
||||
this.tokenRegistry = new TokenRegistry(
|
||||
await this.registry.getContractAddressByName('TokenRegistry')
|
||||
|
@ -34,11 +34,15 @@ export class TransactionService {
|
||||
private httpClient: HttpClient,
|
||||
private authService: AuthService,
|
||||
private userService: UserService,
|
||||
private loggingService: LoggingService,
|
||||
private registryService: RegistryService
|
||||
private loggingService: LoggingService
|
||||
) {
|
||||
this.web3 = this.registryService.web3;
|
||||
this.registry = registryService.registry;
|
||||
this.web3 = RegistryService.web3;
|
||||
}
|
||||
|
||||
async init(): Promise<void> {
|
||||
await this.authService.init();
|
||||
await this.userService.init();
|
||||
this.registry = await RegistryService.getRegistry();
|
||||
}
|
||||
|
||||
getAllTransactions(offset: number, limit: number): Observable<any> {
|
||||
|
@ -39,14 +39,15 @@ export class UserService {
|
||||
private httpClient: HttpClient,
|
||||
private loggingService: LoggingService,
|
||||
private tokenService: TokenService,
|
||||
private registryService: RegistryService,
|
||||
private authService: AuthService
|
||||
) {
|
||||
this.authService.init().then(() => {
|
||||
this.keystore = authService.mutableKeyStore;
|
||||
this.signer = new PGPSigner(this.keystore);
|
||||
});
|
||||
this.registry = registryService.registry;
|
||||
) {}
|
||||
|
||||
async init(): Promise<void> {
|
||||
await this.authService.init();
|
||||
await this.tokenService.init();
|
||||
this.keystore = this.authService.mutableKeyStore;
|
||||
this.signer = new PGPSigner(this.keystore);
|
||||
this.registry = await RegistryService.getRegistry();
|
||||
}
|
||||
|
||||
resetPin(phone: string): Observable<any> {
|
||||
|
@ -27,28 +27,22 @@ export class AppComponent implements OnInit {
|
||||
private errorDialogService: ErrorDialogService,
|
||||
private swUpdate: SwUpdate
|
||||
) {
|
||||
(async () => {
|
||||
try {
|
||||
await this.authService.init();
|
||||
// this.authService.getPublicKeys()
|
||||
// .pipe(catchError(async (error) => {
|
||||
// this.loggingService.sendErrorLevelMessage('Unable to load trusted public keys.', this, {error});
|
||||
// this.errorDialogService.openDialog({message: 'Trusted keys endpoint can\'t be reached. Please try again later.'});
|
||||
// })).subscribe(this.authService.mutableKeyStore.importPublicKey);
|
||||
const publicKeys = await this.authService.getPublicKeys();
|
||||
await this.authService.mutableKeyStore.importPublicKey(publicKeys);
|
||||
} catch (error) {
|
||||
this.errorDialogService.openDialog({
|
||||
message: 'Trusted keys endpoint cannot be reached. Please try again later.',
|
||||
});
|
||||
// TODO do something to halt user progress...show a sad cicada page 🦗?
|
||||
}
|
||||
})();
|
||||
this.mediaQuery.addEventListener('change', this.onResize);
|
||||
this.onResize(this.mediaQuery);
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
async ngOnInit(): Promise<void> {
|
||||
await this.authService.init();
|
||||
await this.transactionService.init();
|
||||
try {
|
||||
const publicKeys = await this.authService.getPublicKeys();
|
||||
await this.authService.mutableKeyStore.importPublicKey(publicKeys);
|
||||
} catch (error) {
|
||||
this.errorDialogService.openDialog({
|
||||
message: 'Trusted keys endpoint cannot be reached. Please try again later.',
|
||||
});
|
||||
// TODO do something to halt user progress...show a sad cicada page 🦗?
|
||||
}
|
||||
if (!this.swUpdate.isEnabled) {
|
||||
this.swUpdate.available.subscribe(() => {
|
||||
if (confirm('New Version available. Load New Version?')) {
|
||||
|
@ -78,6 +78,14 @@ export class AccountDetailsComponent implements OnInit {
|
||||
private cdr: ChangeDetectorRef,
|
||||
private snackBar: MatSnackBar
|
||||
) {
|
||||
this.route.paramMap.subscribe((params: Params) => {
|
||||
this.accountAddress = add0x(params.get('id'));
|
||||
this.bloxbergLink =
|
||||
'https://blockexplorer.bloxberg.org/address/' + this.accountAddress + '/transactions';
|
||||
});
|
||||
}
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
this.accountInfoForm = this.formBuilder.group({
|
||||
name: ['', Validators.required],
|
||||
phoneNumber: ['', Validators.required],
|
||||
@ -90,15 +98,11 @@ export class AccountDetailsComponent implements OnInit {
|
||||
location: ['', Validators.required],
|
||||
locationType: ['', Validators.required],
|
||||
});
|
||||
this.route.paramMap.subscribe((params: Params) => {
|
||||
this.accountAddress = add0x(params.get('id'));
|
||||
this.bloxbergLink =
|
||||
'https://blockexplorer.bloxberg.org/address/' + this.accountAddress + '/transactions';
|
||||
this.blockSyncService.blockSync(this.accountAddress);
|
||||
});
|
||||
}
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
await this.blockSyncService.init();
|
||||
await this.tokenService.init();
|
||||
await this.transactionService.init();
|
||||
await this.userService.init();
|
||||
await this.blockSyncService.blockSync(this.accountAddress);
|
||||
(await this.userService.getAccountByAddress(this.accountAddress, 100)).subscribe(
|
||||
async (res) => {
|
||||
if (res !== undefined) {
|
||||
|
@ -30,7 +30,8 @@ export class AccountSearchComponent implements OnInit {
|
||||
private router: Router
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
async ngOnInit(): Promise<void> {
|
||||
await this.userService.init();
|
||||
this.nameSearchForm = this.formBuilder.group({
|
||||
name: ['', Validators.required],
|
||||
});
|
||||
|
@ -32,28 +32,26 @@ export class AccountsComponent implements OnInit {
|
||||
private userService: UserService,
|
||||
private loggingService: LoggingService,
|
||||
private router: Router
|
||||
) {
|
||||
(async () => {
|
||||
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 {
|
||||
async ngOnInit(): Promise<void> {
|
||||
await this.userService.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.dataSource = new MatTableDataSource<any>(accounts);
|
||||
this.dataSource.paginator = this.paginator;
|
||||
this.dataSource.sort = this.sort;
|
||||
this.accounts = accounts;
|
||||
});
|
||||
this.userService
|
||||
.getAccountTypes()
|
||||
.pipe(first())
|
||||
.subscribe((res) => (this.accountTypes = res));
|
||||
}
|
||||
|
||||
doFilter(value: string): void {
|
||||
|
@ -26,7 +26,8 @@ export class CreateAccountComponent implements OnInit {
|
||||
private userService: UserService
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
async ngOnInit(): Promise<void> {
|
||||
await this.userService.init();
|
||||
this.createForm = this.formBuilder.group({
|
||||
accountType: ['', Validators.required],
|
||||
idNumber: ['', Validators.required],
|
||||
|
@ -30,7 +30,10 @@ export class AdminComponent implements OnInit {
|
||||
@ViewChild(MatPaginator) paginator: MatPaginator;
|
||||
@ViewChild(MatSort) sort: MatSort;
|
||||
|
||||
constructor(private userService: UserService, private loggingService: LoggingService) {
|
||||
constructor(private userService: UserService, private loggingService: LoggingService) {}
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
await this.userService.init();
|
||||
this.userService.getActions();
|
||||
this.userService.actionsSubject.subscribe((actions) => {
|
||||
this.dataSource = new MatTableDataSource<any>(actions);
|
||||
@ -40,8 +43,6 @@ export class AdminComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit(): void {}
|
||||
|
||||
doFilter(value: string): void {
|
||||
this.dataSource.filter = value.trim().toLocaleLowerCase();
|
||||
}
|
||||
|
@ -24,7 +24,8 @@ export class SettingsComponent implements OnInit {
|
||||
|
||||
constructor(private authService: AuthService) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
async ngOnInit(): Promise<void> {
|
||||
await this.authService.init();
|
||||
const d = new Date();
|
||||
this.date = `${d.getDate()}/${d.getMonth()}/${d.getFullYear()}`;
|
||||
this.trustedUsers = this.authService.getTrustedUsers();
|
||||
|
@ -13,7 +13,10 @@ import { Token } from '../../../_models';
|
||||
export class TokenDetailsComponent implements OnInit {
|
||||
token: Token;
|
||||
|
||||
constructor(private route: ActivatedRoute, private tokenService: TokenService) {
|
||||
constructor(private route: ActivatedRoute, private tokenService: TokenService) {}
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
await this.tokenService.init();
|
||||
this.route.paramMap.subscribe((params: Params) => {
|
||||
this.tokenService
|
||||
.getTokenBySymbol(params.get('id'))
|
||||
@ -23,6 +26,4 @@ export class TokenDetailsComponent implements OnInit {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit(): void {}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ export class TokensComponent implements OnInit {
|
||||
) {}
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
await this.tokenService.init();
|
||||
this.tokenService.onload = async (status: boolean): Promise<void> => {
|
||||
this.tokens = await this.tokenService.getTokens();
|
||||
this.loggingService.sendInfoLevelMessage(this.tokens);
|
||||
|
@ -23,7 +23,8 @@ export class TransactionDetailsComponent implements OnInit {
|
||||
private snackBar: MatSnackBar
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
async ngOnInit(): Promise<void> {
|
||||
await this.transactionService.init();
|
||||
if (this.transaction?.type === 'conversion') {
|
||||
this.traderBloxbergLink =
|
||||
'https://blockexplorer.bloxberg.org/address/' + this.transaction?.trader + '/transactions';
|
||||
|
@ -36,17 +36,19 @@ export class TransactionsComponent implements OnInit, AfterViewInit {
|
||||
private blockSyncService: BlockSyncService,
|
||||
private transactionService: TransactionService,
|
||||
private userService: UserService
|
||||
) {
|
||||
this.blockSyncService.blockSync();
|
||||
}
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
async ngOnInit(): Promise<void> {
|
||||
this.transactionService.transactionsSubject.subscribe((transactions) => {
|
||||
this.transactionDataSource = new MatTableDataSource<any>(transactions);
|
||||
this.transactionDataSource.paginator = this.paginator;
|
||||
this.transactionDataSource.sort = this.sort;
|
||||
this.transactions = transactions;
|
||||
});
|
||||
await this.blockSyncService.init();
|
||||
await this.transactionService.init();
|
||||
await this.userService.init();
|
||||
await this.blockSyncService.blockSync();
|
||||
this.userService
|
||||
.getTransactionTypes()
|
||||
.pipe(first())
|
||||
|
Loading…
Reference in New Issue
Block a user