2021-03-14 09:23:20 +01:00
|
|
|
import {ChangeDetectionStrategy, Component, HostListener} from '@angular/core';
|
2021-03-21 20:05:00 +01:00
|
|
|
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',
|
2021-03-14 09:23:20 +01:00
|
|
|
styleUrls: ['./app.component.scss'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
2020-10-30 16:16:05 +01:00
|
|
|
})
|
2021-03-04 10:35:20 +01:00
|
|
|
export class AppComponent {
|
2021-02-17 12:52:42 +01:00
|
|
|
title = 'CICADA';
|
2020-11-08 07:31:52 +01:00
|
|
|
readyStateTarget: number = 3;
|
|
|
|
readyState: number = 0;
|
2020-11-25 09:05:13 +01:00
|
|
|
mediaQuery = window.matchMedia('(max-width: 768px)');
|
2020-11-08 07:31:52 +01:00
|
|
|
|
2020-11-25 09:05:13 +01:00
|
|
|
constructor(
|
2021-02-17 12:52:42 +01:00
|
|
|
private authService: AuthService,
|
2020-11-25 09:05:13 +01:00
|
|
|
private transactionService: TransactionService,
|
2021-03-14 09:23:20 +01:00
|
|
|
private loggingService: LoggingService,
|
2021-03-21 20:05:00 +01:00
|
|
|
private errorDialogService: ErrorDialogService
|
2020-11-25 09:05:13 +01:00
|
|
|
) {
|
2021-03-18 10:10:55 +01:00
|
|
|
(async () => {
|
|
|
|
await this.authService.mutableKeyStore.loadKeyring();
|
2021-03-21 20:05:00 +01: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);
|
2021-03-18 10:10:55 +01:00
|
|
|
})();
|
2020-11-25 09:05:13 +01:00
|
|
|
this.mediaQuery.addListener(this.onResize);
|
|
|
|
this.onResize(this.mediaQuery);
|
2020-11-08 07:31:52 +01:00
|
|
|
}
|
|
|
|
|
2020-11-25 09:05:13 +01:00
|
|
|
// Load resize
|
|
|
|
onResize(e): void {
|
|
|
|
const sidebar = document.getElementById('sidebar');
|
|
|
|
const content = document.getElementById('content');
|
|
|
|
const sidebarCollapse = document.getElementById('sidebarCollapse');
|
2021-03-04 10:35:20 +01:00
|
|
|
if (sidebarCollapse?.classList.contains('active')) {
|
|
|
|
sidebarCollapse?.classList.remove('active');
|
|
|
|
}
|
2020-11-25 09:05:13 +01:00
|
|
|
if (e.matches) {
|
2021-03-04 10:35:20 +01:00
|
|
|
if (!sidebar?.classList.contains('active')) {
|
|
|
|
sidebar?.classList.add('active');
|
|
|
|
}
|
|
|
|
if (!content?.classList.contains('active')) {
|
|
|
|
content?.classList.add('active');
|
|
|
|
}
|
2020-11-25 09:05:13 +01:00
|
|
|
} else {
|
2021-03-04 10:35:20 +01:00
|
|
|
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'])
|
2021-03-18 10:10:55 +01:00
|
|
|
async cicTransfer(event: CustomEvent): Promise<void> {
|
2020-11-08 07:31:52 +01:00
|
|
|
const transaction = event.detail.tx;
|
2021-03-18 10:10:55 +01:00
|
|
|
await this.transactionService.setTransaction(transaction, 100);
|
2020-11-08 07:31:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@HostListener('window:cic_convert', ['$event'])
|
2021-03-18 10:10:55 +01:00
|
|
|
async cicConvert(event: CustomEvent): Promise<void> {
|
2020-11-08 07:31:52 +01:00
|
|
|
const conversion = event.detail.tx;
|
2021-03-18 10:10:55 +01:00
|
|
|
await this.transactionService.setConversion(conversion, 100);
|
2020-11-08 07:31:52 +01:00
|
|
|
}
|
2020-10-30 16:16:05 +01:00
|
|
|
}
|