cic-staff-client/src/app/app.component.ts

79 lines
2.9 KiB
TypeScript
Raw Normal View History

import {ChangeDetectionStrategy, Component, HostListener} from '@angular/core';
import {AuthService, ErrorDialogService, LoggingService, TransactionService} from '@app/_services';
import {catchError} from 'rxjs/operators';
2020-10-30 16:16:05 +01:00
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
2020-10-30 16:16:05 +01:00
})
export class AppComponent {
title = 'CICADA';
2020-11-08 07:31:52 +01:00
readyStateTarget: number = 3;
readyState: number = 0;
2021-04-30 14:50:16 +02:00
mediaQuery: MediaQueryList = window.matchMedia('(max-width: 768px)');
2020-11-08 07:31:52 +01:00
constructor(
private authService: AuthService,
private transactionService: TransactionService,
private loggingService: LoggingService,
private errorDialogService: ErrorDialogService
) {
(async () => {
2021-04-29 07:29:54 +02:00
try {
await this.authService.init();
2021-04-29 07:29:54 +02:00
// 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();
2021-04-29 07:29:54 +02:00
await this.authService.mutableKeyStore.importPublicKey(publicKeys);
} catch (error) {
2021-04-29 07:29:54 +02:00
this.errorDialogService.openDialog({message: 'Trusted keys endpoint can\'t be reached. Please try again later.'});
// TODO do something to halt user progress...show a sad cicada page 🦗?
}
})();
this.mediaQuery.addListener(this.onResize);
this.onResize(this.mediaQuery);
2020-11-08 07:31:52 +01:00
}
// Load resize
onResize(e): void {
2021-04-30 14:50:16 +02:00
const sidebar: HTMLElement = document.getElementById('sidebar');
const content: HTMLElement = document.getElementById('content');
const sidebarCollapse: HTMLElement = document.getElementById('sidebarCollapse');
if (sidebarCollapse?.classList.contains('active')) {
sidebarCollapse?.classList.remove('active');
}
if (e.matches) {
if (!sidebar?.classList.contains('active')) {
sidebar?.classList.add('active');
}
if (!content?.classList.contains('active')) {
content?.classList.add('active');
}
} else {
if (sidebar?.classList.contains('active')) {
sidebar?.classList.remove('active');
}
if (content?.classList.contains('active')) {
content?.classList.remove('active');
}
2020-11-08 07:31:52 +01:00
}
}
@HostListener('window:cic_transfer', ['$event'])
async cicTransfer(event: CustomEvent): Promise<void> {
2021-04-30 14:50:16 +02:00
const transaction: any = event.detail.tx;
await this.transactionService.setTransaction(transaction, 100);
2020-11-08 07:31:52 +01:00
}
@HostListener('window:cic_convert', ['$event'])
async cicConvert(event: CustomEvent): Promise<void> {
2021-04-30 14:50:16 +02:00
const conversion: any = event.detail.tx;
await this.transactionService.setConversion(conversion, 100);
2020-11-08 07:31:52 +01:00
}
2020-10-30 16:16:05 +01:00
}