2020-11-08 07:31:52 +01:00
|
|
|
import {Component, HostListener, OnInit} from '@angular/core';
|
2021-02-17 13:49:04 +01:00
|
|
|
import {BlockSyncService, TransactionService} from '@app/_services';
|
2021-02-14 17:02:35 +01:00
|
|
|
import {AuthService} from '@app/_services';
|
2021-02-24 16:09:50 +01:00
|
|
|
import {AccountIndex} from '@app/_helpers';
|
|
|
|
import {environment} from '@src/environments/environment';
|
2020-10-30 16:16:05 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-root',
|
|
|
|
templateUrl: './app.component.html',
|
|
|
|
styleUrls: ['./app.component.scss']
|
|
|
|
})
|
2020-11-08 07:31:52 +01:00
|
|
|
export class AppComponent implements OnInit {
|
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)');
|
2021-02-24 16:09:50 +01:00
|
|
|
accountIndexQuery = new AccountIndex(environment.contractAddress);
|
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,
|
|
|
|
private blockSyncService: BlockSyncService
|
|
|
|
) {
|
2021-02-17 12:13:08 +01:00
|
|
|
this.authService.mutableKeyStore.loadKeyring().then(r => this.authService.getPublicKeys().then());
|
2021-02-12 07:32:08 +01:00
|
|
|
this.blockSyncService.blockSync();
|
2020-11-25 09:05:13 +01:00
|
|
|
}
|
2020-11-08 07:31:52 +01:00
|
|
|
|
|
|
|
ngOnInit(): void {
|
2020-11-25 09:05:13 +01:00
|
|
|
this.mediaQuery.addListener(this.onResize);
|
|
|
|
this.onResize(this.mediaQuery);
|
2021-02-24 16:09:50 +01:00
|
|
|
this.queryAccountsIndex(20).then();
|
|
|
|
}
|
|
|
|
|
|
|
|
async queryAccountsIndex(numberOfAccounts: number): Promise<void> {
|
|
|
|
console.log(`Last ${numberOfAccounts} accounts are: `, await this.accountIndexQuery.last(numberOfAccounts));
|
|
|
|
console.log('Total number of accounts: ', await this.accountIndexQuery.totalAccounts());
|
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-02-09 09:32:37 +01:00
|
|
|
sidebarCollapse?.classList.remove('active');
|
2020-11-25 09:05:13 +01:00
|
|
|
if (e.matches) {
|
2021-02-09 09:32:37 +01:00
|
|
|
sidebar?.classList.add('active');
|
|
|
|
content?.classList.add('active');
|
2020-11-25 09:05:13 +01:00
|
|
|
} else {
|
2021-02-09 09:32:37 +01:00
|
|
|
sidebar?.classList.remove('active');
|
|
|
|
content?.classList.remove('active');
|
2020-11-08 07:31:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@HostListener('window:cic_transfer', ['$event'])
|
|
|
|
cicTransfer(event: CustomEvent): void {
|
|
|
|
const transaction = event.detail.tx;
|
2020-11-25 09:05:13 +01:00
|
|
|
this.transactionService.setTransaction(transaction, 100);
|
2020-11-08 07:31:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@HostListener('window:cic_convert', ['$event'])
|
|
|
|
cicConvert(event: CustomEvent): void {
|
|
|
|
const conversion = event.detail.tx;
|
2020-12-05 07:30:30 +01:00
|
|
|
this.transactionService.setConversion(conversion, 100);
|
2020-11-08 07:31:52 +01:00
|
|
|
}
|
2020-10-30 16:16:05 +01:00
|
|
|
}
|