Add typing to components.

This commit is contained in:
Spencer Ofwiti 2021-04-30 15:50:16 +03:00
parent 9921488a04
commit 53d6d6b7a4
20 changed files with 107 additions and 111 deletions

View File

@ -2,40 +2,7 @@ import {HTTP_INTERCEPTORS, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest,
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {Observable, of, throwError} from 'rxjs'; import {Observable, of, throwError} from 'rxjs';
import {delay, dematerialize, materialize, mergeMap} from 'rxjs/operators'; import {delay, dematerialize, materialize, mergeMap} from 'rxjs/operators';
import {Action, AreaName, AreaType, Category, Token} from '@app/_models';
interface Action {
id: number;
user: string;
role: string;
action: string;
approval: boolean;
}
interface Token {
name: string;
symbol: string;
address: string;
supply: string;
decimals: string;
reserves: {};
reserveRatio?: string;
owner?: string;
}
interface Category {
name: string;
products: Array<string>;
}
interface AreaName {
name: string;
locations: Array<string>;
}
interface AreaType {
name: string;
area: Array<string>;
}
const actions: Array<Action> = [ const actions: Array<Action> = [
{ id: 1, user: 'Tom', role: 'enroller', action: 'Disburse RSV 100', approval: false }, { id: 1, user: 'Tom', role: 'enroller', action: 'Disburse RSV 100', approval: false },

View File

@ -3,3 +3,4 @@ export * from '@app/_models/settings';
export * from '@app/_models/account'; export * from '@app/_models/account';
export * from '@app/_models/staff'; export * from '@app/_models/staff';
export * from '@app/_models/token'; export * from '@app/_models/token';
export * from '@app/_models/mappings';

View File

@ -0,0 +1,29 @@
interface Action {
id: number;
user: string;
role: string;
action: string;
approval: boolean;
}
interface Category {
name: string;
products: Array<string>;
}
interface AreaName {
name: string;
locations: Array<string>;
}
interface AreaType {
name: string;
area: Array<string>;
}
export {
Action,
Category,
AreaName,
AreaType
};

View File

@ -30,6 +30,7 @@ class Transaction {
token: TxToken; token: TxToken;
tx: Tx; tx: Tx;
value: number; value: number;
type?: string;
} }
class Conversion { class Conversion {

View File

@ -12,7 +12,7 @@ export class AppComponent {
title = 'CICADA'; title = 'CICADA';
readyStateTarget: number = 3; readyStateTarget: number = 3;
readyState: number = 0; readyState: number = 0;
mediaQuery = window.matchMedia('(max-width: 768px)'); mediaQuery: MediaQueryList = window.matchMedia('(max-width: 768px)');
constructor( constructor(
private authService: AuthService, private authService: AuthService,
@ -41,9 +41,9 @@ export class AppComponent {
// Load resize // Load resize
onResize(e): void { onResize(e): void {
const sidebar = document.getElementById('sidebar'); const sidebar: HTMLElement = document.getElementById('sidebar');
const content = document.getElementById('content'); const content: HTMLElement = document.getElementById('content');
const sidebarCollapse = document.getElementById('sidebarCollapse'); const sidebarCollapse: HTMLElement = document.getElementById('sidebarCollapse');
if (sidebarCollapse?.classList.contains('active')) { if (sidebarCollapse?.classList.contains('active')) {
sidebarCollapse?.classList.remove('active'); sidebarCollapse?.classList.remove('active');
} }
@ -66,13 +66,13 @@ export class AppComponent {
@HostListener('window:cic_transfer', ['$event']) @HostListener('window:cic_transfer', ['$event'])
async cicTransfer(event: CustomEvent): Promise<void> { async cicTransfer(event: CustomEvent): Promise<void> {
const transaction = event.detail.tx; const transaction: any = event.detail.tx;
await this.transactionService.setTransaction(transaction, 100); await this.transactionService.setTransaction(transaction, 100);
} }
@HostListener('window:cic_convert', ['$event']) @HostListener('window:cic_convert', ['$event'])
async cicConvert(event: CustomEvent): Promise<void> { async cicConvert(event: CustomEvent): Promise<void> {
const conversion = event.detail.tx; const conversion: any = event.detail.tx;
await this.transactionService.setConversion(conversion, 100); await this.transactionService.setConversion(conversion, 100);
} }
} }

View File

@ -20,8 +20,8 @@ export class PasswordToggleDirective {
} }
togglePasswordVisibility(): void { togglePasswordVisibility(): void {
const password = document.getElementById(this.id); const password: HTMLElement = document.getElementById(this.id);
const icon = document.getElementById(this.iconId); const icon: HTMLElement = document.getElementById(this.iconId);
// @ts-ignore // @ts-ignore
if (password.type === 'password') { if (password.type === 'password') {
// @ts-ignore // @ts-ignore

View File

@ -14,7 +14,7 @@ export class AuthComponent implements OnInit {
keyForm: FormGroup; keyForm: FormGroup;
submitted: boolean = false; submitted: boolean = false;
loading: boolean = false; loading: boolean = false;
matcher = new CustomErrorStateMatcher(); matcher: CustomErrorStateMatcher = new CustomErrorStateMatcher();
constructor( constructor(
private authService: AuthService, private authService: AuthService,
@ -58,14 +58,14 @@ export class AuthComponent implements OnInit {
switchWindows(): void { switchWindows(): void {
this.authService.sessionToken = undefined; this.authService.sessionToken = undefined;
const divOne = document.getElementById('one'); const divOne: HTMLElement = document.getElementById('one');
const divTwo = document.getElementById('two'); const divTwo: HTMLElement = document.getElementById('two');
this.toggleDisplay(divOne); this.toggleDisplay(divOne);
this.toggleDisplay(divTwo); this.toggleDisplay(divTwo);
} }
toggleDisplay(element: any): void { toggleDisplay(element: any): void {
const style = window.getComputedStyle(element).display; const style: string = window.getComputedStyle(element).display;
if (style === 'block') { if (style === 'block') {
element.style.display = 'none'; element.style.display = 'none';
} else { } else {

View File

@ -50,12 +50,4 @@ describe('AccountDetailsComponent', () => {
it('should create', () => { it('should create', () => {
expect(component).toBeTruthy(); expect(component).toBeTruthy();
}); });
it('#addTransfer() should toggle #isDisbursing', () => {
expect(component.isDisbursing).toBe(false, 'off at first');
component.addTransfer();
expect(component.isDisbursing).toBe(true, 'on after click');
component.addTransfer();
expect(component.isDisbursing).toBe(false, 'off after second click');
});
}); });

View File

@ -10,6 +10,7 @@ import {copyToClipboard, CustomErrorStateMatcher, exportCsv} from '@app/_helpers
import {MatSnackBar} from '@angular/material/snack-bar'; import {MatSnackBar} from '@angular/material/snack-bar';
import {add0x, strip0x} from '@src/assets/js/ethtx/dist/hex'; import {add0x, strip0x} from '@src/assets/js/ethtx/dist/hex';
import {environment} from '@src/environments/environment'; import {environment} from '@src/environments/environment';
import {AccountDetails, AreaName, AreaType, Category, Transaction} from '@app/_models';
@Component({ @Component({
selector: 'app-account-details', selector: 'app-account-details',
@ -19,35 +20,35 @@ import {environment} from '@src/environments/environment';
}) })
export class AccountDetailsComponent implements OnInit { export class AccountDetailsComponent implements OnInit {
transactionsDataSource: MatTableDataSource<any>; transactionsDataSource: MatTableDataSource<any>;
transactionsDisplayedColumns = ['sender', 'recipient', 'value', 'created', 'type']; transactionsDisplayedColumns: Array<string> = ['sender', 'recipient', 'value', 'created', 'type'];
transactionsDefaultPageSize = 10; transactionsDefaultPageSize: number = 10;
transactionsPageSizeOptions = [10, 20, 50, 100]; transactionsPageSizeOptions: Array<number> = [10, 20, 50, 100];
@ViewChild('TransactionTablePaginator', {static: true}) transactionTablePaginator: MatPaginator; @ViewChild('TransactionTablePaginator', {static: true}) transactionTablePaginator: MatPaginator;
@ViewChild('TransactionTableSort', {static: true}) transactionTableSort: MatSort; @ViewChild('TransactionTableSort', {static: true}) transactionTableSort: MatSort;
userDataSource: MatTableDataSource<any>; userDataSource: MatTableDataSource<any>;
userDisplayedColumns = ['name', 'phone', 'created', 'balance', 'location']; userDisplayedColumns: Array<string> = ['name', 'phone', 'created', 'balance', 'location'];
usersDefaultPageSize = 10; usersDefaultPageSize: number = 10;
usersPageSizeOptions = [10, 20, 50, 100]; usersPageSizeOptions: Array<number> = [10, 20, 50, 100];
@ViewChild('UserTablePaginator', {static: true}) userTablePaginator: MatPaginator; @ViewChild('UserTablePaginator', {static: true}) userTablePaginator: MatPaginator;
@ViewChild('UserTableSort', {static: true}) userTableSort: MatSort; @ViewChild('UserTableSort', {static: true}) userTableSort: MatSort;
accountInfoForm: FormGroup; accountInfoForm: FormGroup;
account: any; account: AccountDetails;
accountAddress: string; accountAddress: string;
accountStatus: any; accountStatus: any;
accounts: any[] = []; accounts: Array<AccountDetails> = [];
accountsType = 'all'; accountsType: string = 'all';
categories: any[]; categories: Array<Category>;
areaNames: any[]; areaNames: Array<AreaName>;
areaTypes: any[]; areaTypes: Array<AreaType>;
transaction: any; transaction: any;
transactions: any[]; transactions: Array<Transaction>;
transactionsType = 'all'; transactionsType: string = 'all';
accountTypes: any[]; accountTypes: Array<string>;
transactionsTypes: any[]; transactionsTypes: Array<string>;
genders: any[]; genders: Array<string>;
matcher = new CustomErrorStateMatcher(); matcher: CustomErrorStateMatcher = new CustomErrorStateMatcher();
submitted: boolean = false; submitted: boolean = false;
bloxbergLink: string; bloxbergLink: string;
@ -84,7 +85,8 @@ export class AccountDetailsComponent implements OnInit {
this.account = res; this.account = res;
this.cdr.detectChanges(); this.cdr.detectChanges();
this.loggingService.sendInfoLevelMessage(this.account); this.loggingService.sendInfoLevelMessage(this.account);
// this.userService.getAccountStatus(this.account.vcard?.tel[0].value).pipe(first()).subscribe(response => this.accountStatus = response); // this.userService.getAccountStatus(this.account.vcard?.tel[0].value).pipe(first())
// .subscribe(response => this.accountStatus = response);
this.accountInfoForm.patchValue({ this.accountInfoForm.patchValue({
name: this.account.vcard?.fn[0].value, name: this.account.vcard?.fn[0].value,
phoneNumber: this.account.vcard?.tel[0].value, phoneNumber: this.account.vcard?.tel[0].value,
@ -188,7 +190,7 @@ export class AccountDetailsComponent implements OnInit {
resetPin(): void { resetPin(): void {
if (!confirm('Reset user\'s pin?')) { return; } if (!confirm('Reset user\'s pin?')) { return; }
this.userService.resetPin(this.account.phone).pipe(first()).subscribe(res => { this.userService.resetPin(this.account.vcard.tel[0].value).pipe(first()).subscribe(res => {
this.loggingService.sendInfoLevelMessage(`Response: ${res}`); this.loggingService.sendInfoLevelMessage(`Response: ${res}`);
}); });
} }

View File

@ -22,7 +22,7 @@ export class AccountSearchComponent implements OnInit {
addressSearchForm: FormGroup; addressSearchForm: FormGroup;
addressSearchSubmitted: boolean = false; addressSearchSubmitted: boolean = false;
addressSearchLoading: boolean = false; addressSearchLoading: boolean = false;
matcher = new CustomErrorStateMatcher(); matcher: CustomErrorStateMatcher = new CustomErrorStateMatcher();
constructor( constructor(
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
@ -59,7 +59,6 @@ export class AccountSearchComponent implements OnInit {
if (this.phoneSearchForm.invalid) { return; } if (this.phoneSearchForm.invalid) { return; }
this.phoneSearchLoading = true; this.phoneSearchLoading = true;
(await this.userService.getAccountByPhone(this.phoneSearchFormStub.phoneNumber.value, 100)).subscribe(async res => { (await this.userService.getAccountByPhone(this.phoneSearchFormStub.phoneNumber.value, 100)).subscribe(async res => {
console.log(res);
if (res !== undefined) { if (res !== undefined) {
await this.router.navigateByUrl(`/accounts/${strip0x(res.identities.evm[`bloxberg:${environment.bloxbergChainId}`][0])}`); await this.router.navigateByUrl(`/accounts/${strip0x(res.identities.evm[`bloxberg:${environment.bloxbergChainId}`][0])}`);
} else { } else {

View File

@ -8,6 +8,7 @@ import {exportCsv} from '@app/_helpers';
import {strip0x} from '@src/assets/js/ethtx/dist/hex'; import {strip0x} from '@src/assets/js/ethtx/dist/hex';
import {first} from 'rxjs/operators'; import {first} from 'rxjs/operators';
import {environment} from '@src/environments/environment'; import {environment} from '@src/environments/environment';
import {AccountDetails} from '@app/_models';
@Component({ @Component({
selector: 'app-accounts', selector: 'app-accounts',
@ -17,12 +18,12 @@ import {environment} from '@src/environments/environment';
}) })
export class AccountsComponent implements OnInit { export class AccountsComponent implements OnInit {
dataSource: MatTableDataSource<any>; dataSource: MatTableDataSource<any>;
accounts: any[] = []; accounts: Array<AccountDetails> = [];
displayedColumns = ['name', 'phone', 'created', 'balance', 'location']; displayedColumns: Array<string> = ['name', 'phone', 'created', 'balance', 'location'];
defaultPageSize = 10; defaultPageSize: number = 10;
pageSizeOptions = [10, 20, 50, 100]; pageSizeOptions: Array<number> = [10, 20, 50, 100];
accountsType = 'all'; accountsType: string = 'all';
accountTypes: any[]; accountTypes: Array<string>;
@ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort; @ViewChild(MatSort) sort: MatSort;
@ -35,7 +36,7 @@ export class AccountsComponent implements OnInit {
{ {
(async () => { (async () => {
try { try {
// TODO it feels like this shuold be in the onInit handler // TODO it feels like this should be in the onInit handler
await this.userService.loadAccounts(100); await this.userService.loadAccounts(100);
} catch (error) { } catch (error) {
this.loggingService.sendErrorLevelMessage('Failed to load accounts', this, {error}); this.loggingService.sendErrorLevelMessage('Failed to load accounts', this, {error});

View File

@ -3,6 +3,7 @@ import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {LocationService, UserService} from '@app/_services'; import {LocationService, UserService} from '@app/_services';
import {CustomErrorStateMatcher} from '@app/_helpers'; import {CustomErrorStateMatcher} from '@app/_helpers';
import {first} from 'rxjs/operators'; import {first} from 'rxjs/operators';
import {AreaName, Category} from '@app/_models';
@Component({ @Component({
selector: 'app-create-account', selector: 'app-create-account',
@ -12,12 +13,12 @@ import {first} from 'rxjs/operators';
}) })
export class CreateAccountComponent implements OnInit { export class CreateAccountComponent implements OnInit {
createForm: FormGroup; createForm: FormGroup;
matcher = new CustomErrorStateMatcher(); matcher: CustomErrorStateMatcher = new CustomErrorStateMatcher();
submitted: boolean = false; submitted: boolean = false;
categories: any[]; categories: Array<Category>;
areaNames: any[]; areaNames: Array<AreaName>;
accountTypes: any[]; accountTypes: Array<string>;
genders: any[]; genders: Array<string>;
constructor( constructor(
private formBuilder: FormBuilder, private formBuilder: FormBuilder,

View File

@ -6,6 +6,7 @@ import {LoggingService, UserService} from '@app/_services';
import {animate, state, style, transition, trigger} from '@angular/animations'; import {animate, state, style, transition, trigger} from '@angular/animations';
import {first} from 'rxjs/operators'; import {first} from 'rxjs/operators';
import {exportCsv} from '@app/_helpers'; import {exportCsv} from '@app/_helpers';
import {Action} from '../../_models';
@Component({ @Component({
selector: 'app-admin', selector: 'app-admin',
@ -22,9 +23,9 @@ import {exportCsv} from '@app/_helpers';
}) })
export class AdminComponent implements OnInit { export class AdminComponent implements OnInit {
dataSource: MatTableDataSource<any>; dataSource: MatTableDataSource<any>;
displayedColumns = ['expand', 'user', 'role', 'action', 'status', 'approve']; displayedColumns: Array<string> = ['expand', 'user', 'role', 'action', 'status', 'approve'];
action: any; action: Action;
actions: any; actions: Array<Action>;
@ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort; @ViewChild(MatSort) sort: MatSort;
@ -39,7 +40,6 @@ export class AdminComponent implements OnInit {
this.dataSource.paginator = this.paginator; this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort; this.dataSource.sort = this.sort;
this.actions = actions; this.actions = actions;
console.log(this.actions);
}); });
} }

View File

@ -11,7 +11,7 @@ import {CustomErrorStateMatcher} from '@app/_helpers';
export class OrganizationComponent implements OnInit { export class OrganizationComponent implements OnInit {
organizationForm: FormGroup; organizationForm: FormGroup;
submitted: boolean = false; submitted: boolean = false;
matcher = new CustomErrorStateMatcher(); matcher: CustomErrorStateMatcher = new CustomErrorStateMatcher();
constructor( constructor(
private formBuilder: FormBuilder private formBuilder: FormBuilder

View File

@ -15,8 +15,8 @@ import {exportCsv} from '@app/_helpers';
export class SettingsComponent implements OnInit { export class SettingsComponent implements OnInit {
date: string; date: string;
dataSource: MatTableDataSource<any>; dataSource: MatTableDataSource<any>;
displayedColumns = ['name', 'email', 'userId']; displayedColumns: Array<string> = ['name', 'email', 'userId'];
trustedUsers: Staff[]; trustedUsers: Array<Staff>;
@ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort; @ViewChild(MatSort) sort: MatSort;

View File

@ -2,6 +2,7 @@ import {ChangeDetectionStrategy, Component, OnInit} from '@angular/core';
import {ActivatedRoute, Params} from '@angular/router'; import {ActivatedRoute, Params} from '@angular/router';
import {TokenService} from '@app/_services'; import {TokenService} from '@app/_services';
import {first} from 'rxjs/operators'; import {first} from 'rxjs/operators';
import {Token} from '../../../_models';
@Component({ @Component({
selector: 'app-token-details', selector: 'app-token-details',
@ -10,7 +11,7 @@ import {first} from 'rxjs/operators';
changeDetection: ChangeDetectionStrategy.OnPush changeDetection: ChangeDetectionStrategy.OnPush
}) })
export class TokenDetailsComponent implements OnInit { export class TokenDetailsComponent implements OnInit {
token: any; token: Token;
constructor( constructor(
private route: ActivatedRoute, private route: ActivatedRoute,

View File

@ -6,6 +6,7 @@ import {MatTableDataSource} from '@angular/material/table';
import {Router} from '@angular/router'; import {Router} from '@angular/router';
import {exportCsv} from '@app/_helpers'; import {exportCsv} from '@app/_helpers';
import {TokenRegistry} from '../../_eth'; import {TokenRegistry} from '../../_eth';
import {Token} from '../../_models';
@Component({ @Component({
selector: 'app-tokens', selector: 'app-tokens',
@ -15,10 +16,10 @@ import {TokenRegistry} from '../../_eth';
}) })
export class TokensComponent implements OnInit { export class TokensComponent implements OnInit {
dataSource: MatTableDataSource<any>; dataSource: MatTableDataSource<any>;
columnsToDisplay = ['name', 'symbol', 'address', 'supply']; columnsToDisplay: Array<string> = ['name', 'symbol', 'address', 'supply'];
@ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort; @ViewChild(MatSort) sort: MatSort;
tokens: any; tokens: Array<Promise<string>>;
constructor( constructor(
private tokenService: TokenService, private tokenService: TokenService,

View File

@ -5,6 +5,7 @@ import {MatPaginator} from '@angular/material/paginator';
import {MatSort} from '@angular/material/sort'; import {MatSort} from '@angular/material/sort';
import {exportCsv} from '@app/_helpers'; import {exportCsv} from '@app/_helpers';
import {first} from 'rxjs/operators'; import {first} from 'rxjs/operators';
import {Transaction} from '@app/_models';
@Component({ @Component({
selector: 'app-transactions', selector: 'app-transactions',
@ -14,13 +15,13 @@ import {first} from 'rxjs/operators';
}) })
export class TransactionsComponent implements OnInit, AfterViewInit { export class TransactionsComponent implements OnInit, AfterViewInit {
transactionDataSource: MatTableDataSource<any>; transactionDataSource: MatTableDataSource<any>;
transactionDisplayedColumns = ['sender', 'recipient', 'value', 'created', 'type']; transactionDisplayedColumns: Array<string> = ['sender', 'recipient', 'value', 'created', 'type'];
defaultPageSize = 10; defaultPageSize: number = 10;
pageSizeOptions = [10, 20, 50, 100]; pageSizeOptions: Array<number> = [10, 20, 50, 100];
transactions: any[]; transactions: Array<Transaction>;
transaction: any; transaction: Transaction;
transactionsType = 'all'; transactionsType: string = 'all';
transactionsTypes: any[]; transactionsTypes: Array<string>;
@ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort; @ViewChild(MatSort) sort: MatSort;

View File

@ -18,15 +18,15 @@ export class MenuSelectionDirective {
} }
onMenuSelect(): void { onMenuSelect(): void {
const sidebar = document.getElementById('sidebar'); const sidebar: HTMLElement = document.getElementById('sidebar');
if (!sidebar?.classList.contains('active')) { if (!sidebar?.classList.contains('active')) {
sidebar?.classList.add('active'); sidebar?.classList.add('active');
} }
const content = document.getElementById('content'); const content: HTMLElement = document.getElementById('content');
if (!content?.classList.contains('active')) { if (!content?.classList.contains('active')) {
content?.classList.add('active'); content?.classList.add('active');
} }
const sidebarCollapse = document.getElementById('sidebarCollapse'); const sidebarCollapse: HTMLElement = document.getElementById('sidebarCollapse');
if (sidebarCollapse?.classList.contains('active')) { if (sidebarCollapse?.classList.contains('active')) {
sidebarCollapse?.classList.remove('active'); sidebarCollapse?.classList.remove('active');
} }

View File

@ -16,11 +16,11 @@ export class MenuToggleDirective {
// Menu Trigger // Menu Trigger
onMenuToggle(): void { onMenuToggle(): void {
const sidebar = document.getElementById('sidebar'); const sidebar: HTMLElement = document.getElementById('sidebar');
sidebar?.classList.toggle('active'); sidebar?.classList.toggle('active');
const content = document.getElementById('content'); const content: HTMLElement = document.getElementById('content');
content?.classList.toggle('active'); content?.classList.toggle('active');
const sidebarCollapse = document.getElementById('sidebarCollapse'); const sidebarCollapse: HTMLElement = document.getElementById('sidebarCollapse');
sidebarCollapse?.classList.toggle('active'); sidebarCollapse?.classList.toggle('active');
} }
} }