import {ChangeDetectionStrategy, Component, HostListener, OnInit} from '@angular/core'; import {AuthService, LoggingService, TokenService, TransactionService} from '@app/_services'; import {SwUpdate} from '@angular/service-worker'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush }) export class AppComponent implements OnInit { title = 'CICADA'; readyStateTarget: number = 3; readyState: number = 0; mediaQuery = window.matchMedia('(max-width: 768px)'); constructor( private authService: AuthService, private tokenService: TokenService, private transactionService: TransactionService, private loggingService: LoggingService, private swUpdate: SwUpdate ) { (async () => { await this.authService.mutableKeyStore.loadKeyring(); await this.authService.getPublicKeys(); this.loggingService.sendInfoLevelMessage(await this.tokenService.getTokens()); })(); this.mediaQuery.addListener(this.onResize); this.onResize(this.mediaQuery); } ngOnInit(): void { if (!this.swUpdate.isEnabled) { this.swUpdate.available.subscribe(() => { if (confirm('New Version available. Load New Version?')) { window.location.reload(); } }); } } // Load resize onResize(e): void { const sidebar = document.getElementById('sidebar'); const content = document.getElementById('content'); const sidebarCollapse = 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'); } } } @HostListener('window:cic_transfer', ['$event']) async cicTransfer(event: CustomEvent): Promise { const transaction = event.detail.tx; await this.transactionService.setTransaction(transaction, 100); } @HostListener('window:cic_convert', ['$event']) async cicConvert(event: CustomEvent): Promise { const conversion = event.detail.tx; await this.transactionService.setConversion(conversion, 100); } }