diff --git a/src/app/_models/staff.ts b/src/app/_models/staff.ts index fbc504a..1dfdb07 100644 --- a/src/app/_models/staff.ts +++ b/src/app/_models/staff.ts @@ -1,2 +1,7 @@ export interface Staff { + comment: string; + email: string; + name: string; + tag: number; + userid: string; } diff --git a/src/app/_services/auth.service.ts b/src/app/_services/auth.service.ts index d0e19fa..1d8a1b4 100644 --- a/src/app/_services/auth.service.ts +++ b/src/app/_services/auth.service.ts @@ -76,11 +76,11 @@ export class AuthService { const xhr = new XMLHttpRequest(); xhr.responseType = 'arraybuffer'; xhr.open('GET', environment.cicAuthUrl + window.location.search.substring(1)); - xhr.onload = (e) => { + xhr.onload = async (e) => { if (xhr.status === 401) { const authHeader = xhr.getResponseHeader('WWW-Authenticate'); const o = hobaParseChallengeHeader(authHeader); - this.loginResponse(o).then(); + await this.loginResponse(o); } }; xhr.send(); @@ -138,6 +138,12 @@ export class AuthService { window.location.reload(true); } + getTrustedUsers(): any { + let trustedUsers = []; + this.mutableKeyStore.getPublicKeys().forEach(key => trustedUsers.push(key.users[0].userId)); + return trustedUsers; + } + async getPublicKeys(): Promise { this.httpWrapperService.get(`${environment.publicKeysUrl}`).pipe(first()).subscribe(async res => { await this.mutableKeyStore.importPublicKey(res.body); diff --git a/src/app/app.component.ts b/src/app/app.component.ts index cbf9dc1..e1421c6 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,6 +1,5 @@ import {ChangeDetectionStrategy, Component, HostListener} from '@angular/core'; import {AuthService, LoggingService, TokenService, TransactionService} from '@app/_services'; -import {NGXLogger} from 'ngx-logger'; @Component({ selector: 'app-root', @@ -18,11 +17,13 @@ export class AppComponent { private authService: AuthService, private tokenService: TokenService, private transactionService: TransactionService, - private logger: NGXLogger, private loggingService: LoggingService, ) { - this.authService.mutableKeyStore.loadKeyring().then(r => this.authService.getPublicKeys().then()); - this.tokenService.getTokens().then(async r => loggingService.sendInfoLevelMessage(await r)); + (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); } @@ -53,14 +54,14 @@ export class AppComponent { } @HostListener('window:cic_transfer', ['$event']) - cicTransfer(event: CustomEvent): void { + async cicTransfer(event: CustomEvent): Promise { const transaction = event.detail.tx; - this.transactionService.setTransaction(transaction, 100).then(); + await this.transactionService.setTransaction(transaction, 100); } @HostListener('window:cic_convert', ['$event']) - cicConvert(event: CustomEvent): void { + async cicConvert(event: CustomEvent): Promise { const conversion = event.detail.tx; - this.transactionService.setConversion(conversion, 100).then(); + await this.transactionService.setConversion(conversion, 100); } } diff --git a/src/app/auth/auth.component.ts b/src/app/auth/auth.component.ts index 6d6c2b7..cc06dd3 100644 --- a/src/app/auth/auth.component.ts +++ b/src/app/auth/auth.component.ts @@ -22,35 +22,33 @@ export class AuthComponent implements OnInit { private router: Router ) { } - ngOnInit(): void { + async ngOnInit(): Promise { this.keyForm = this.formBuilder.group({ key: ['', Validators.required], }); - if (this.authService.privateKey !== undefined ) { - this.authService.setKey(this.authService.privateKey).then(r => { - if (this.authService.sessionToken !== undefined) { - this.authService.setState( - 'Click button to perform login ' + this.authService.sessionLoginCount + ' with token ' + this.authService.sessionToken); - } - }); + if (this.authService.privateKey !== undefined) { + const setKey = await this.authService.setKey(this.authService.privateKey); + if (setKey && this.authService.sessionToken !== undefined) { + this.authService.setState( + 'Click button to perform login ' + this.authService.sessionLoginCount + ' with token ' + this.authService.sessionToken); + } } } get keyFormStub(): any { return this.keyForm.controls; } - onSubmit(): void { + async onSubmit(): Promise { this.submitted = true; if (this.keyForm.invalid) { return; } this.loading = true; - this.authService.setKey(this.keyFormStub.key.value).then(); + await this.authService.setKey(this.keyFormStub.key.value); this.loading = false; } login(): void { const loginStatus = this.authService.login(); - console.log(loginStatus); if (loginStatus) { this.router.navigate(['/home']); } diff --git a/src/app/pages/accounts/account-details/account-details.component.ts b/src/app/pages/accounts/account-details/account-details.component.ts index 32b5624..2d4d8df 100644 --- a/src/app/pages/accounts/account-details/account-details.component.ts +++ b/src/app/pages/accounts/account-details/account-details.component.ts @@ -1,6 +1,5 @@ import {ChangeDetectionStrategy, Component, OnInit, ViewChild} from '@angular/core'; import {MatTableDataSource} from '@angular/material/table'; -import {SelectionModel} from '@angular/cdk/collections'; import {MatPaginator} from '@angular/material/paginator'; import {MatSort} from '@angular/material/sort'; import {BlockSyncService, LocationService, LoggingService, TokenService, TransactionService, UserService} from '@app/_services'; @@ -81,11 +80,11 @@ export class AccountDetailsComponent implements OnInit { this.route.paramMap.subscribe(async (params: Params) => { this.accountAddress = params.get('id'); this.bloxbergLink = 'https://blockexplorer.bloxberg.org/address/' + this.accountAddress + '/transactions'; - this.userService.getAccountDetailsFromMeta(await User.toKey(this.accountAddress)).pipe(first()).subscribe(res => { + this.userService.getAccountDetailsFromMeta(await User.toKey(this.accountAddress)).pipe(first()).subscribe(async res => { this.metaAccount = Envelope.fromJSON(JSON.stringify(res.body)).unwrap(); this.account = this.metaAccount.m.data; this.loggingService.sendInfoLevelMessage(this.account); - this.tokenService.getTokenBalance(this.accountAddress).then(r => this.accountBalance = r); + this.accountBalance = await this.tokenService.getTokenBalance(this.accountAddress); this.account.vcard = vCard.parse(atob(this.account.vcard)); this.accountInfoForm.patchValue({ name: this.account.vcard?.fn[0].value, @@ -159,10 +158,10 @@ export class AccountDetailsComponent implements OnInit { get accountInfoFormStub(): any { return this.accountInfoForm.controls; } - saveInfo(): void { + async saveInfo(): Promise { this.submitted = true; if (this.accountInfoForm.invalid) { return; } - this.userService.changeAccountInfo( + const accountKey = await this.userService.changeAccountInfo( this.account.address, this.accountInfoFormStub.name.value, this.accountInfoFormStub.phoneNumber.value, @@ -175,7 +174,8 @@ export class AccountDetailsComponent implements OnInit { this.accountInfoFormStub.location.value, this.accountInfoFormStub.locationType.value, this.metaAccount - ).then(res => this.loggingService.sendInfoLevelMessage(`Response: ${res}`)); + ); + this.loggingService.sendInfoLevelMessage(`Response: ${accountKey}`); this.submitted = false; } diff --git a/src/app/pages/accounts/accounts.component.ts b/src/app/pages/accounts/accounts.component.ts index ca6d466..5069b86 100644 --- a/src/app/pages/accounts/accounts.component.ts +++ b/src/app/pages/accounts/accounts.component.ts @@ -2,7 +2,7 @@ import {ChangeDetectionStrategy, Component, OnInit, ViewChild} from '@angular/co import {MatTableDataSource} from '@angular/material/table'; import {MatPaginator} from '@angular/material/paginator'; import {MatSort} from '@angular/material/sort'; -import {UserService} from '@app/_services'; +import {LoggingService, UserService} from '@app/_services'; import {Router} from '@angular/router'; @Component({ @@ -24,9 +24,16 @@ export class AccountsComponent implements OnInit { constructor( private userService: UserService, + private loggingService: LoggingService, private router: Router ) { - this.userService.loadAccounts(100).then(); + (async () => { + try { + await this.userService.loadAccounts(100); + } catch (error) { + this.loggingService.sendErrorLevelMessage('Failed to load accounts', this, {error}); + } + })(); } ngOnInit(): void { @@ -42,8 +49,8 @@ export class AccountsComponent implements OnInit { this.dataSource.filter = value.trim().toLocaleLowerCase(); } - viewAccount(account): void { - this.router.navigateByUrl(`/accounts/${account.identities.evm['bloxberg:8996']}`).then(); + async viewAccount(account): Promise { + await this.router.navigateByUrl(`/accounts/${account.identities.evm['bloxberg:8996']}`); } filterAccounts(): void { diff --git a/src/app/pages/accounts/create-account/create-account.component.ts b/src/app/pages/accounts/create-account/create-account.component.ts index 18f09ea..1dbdf06 100644 --- a/src/app/pages/accounts/create-account/create-account.component.ts +++ b/src/app/pages/accounts/create-account/create-account.component.ts @@ -1,7 +1,6 @@ import {ChangeDetectionStrategy, Component, OnInit} from '@angular/core'; -import {Router} from '@angular/router'; import {FormBuilder, FormGroup, Validators} from '@angular/forms'; -import {LocationService, UserService} from '@app/_services'; +import {LocationService} from '@app/_services'; import {CustomErrorStateMatcher} from '@app/_helpers'; @Component({ @@ -18,8 +17,6 @@ export class CreateAccountComponent implements OnInit { constructor( private formBuilder: FormBuilder, - private router: Router, - private userService: UserService, private locationService: LocationService ) { } @@ -47,21 +44,6 @@ export class CreateAccountComponent implements OnInit { onSubmit(): void { this.submitted = true; if (this.createForm.invalid) { return; } - // this.userService.createAccount( - // this.createFormStub.accountType.value, - // this.createFormStub.idNumber.value, - // this.createFormStub.phoneNumber.value, - // this.createFormStub.givenName.value, - // this.createFormStub.surname.value, - // this.createFormStub.directoryEntry.value, - // this.createFormStub.location.value, - // this.createFormStub.gender.value, - // this.createFormStub.referrer.value, - // this.createFormStub.businessCategory.value, - // ).pipe(first()).subscribe(res => { - // console.log(res); - // }); - // this.router.navigateByUrl(`/accounts`); this.submitted = false; } diff --git a/src/app/pages/admin/admin.component.ts b/src/app/pages/admin/admin.component.ts index 1dc5613..129083a 100644 --- a/src/app/pages/admin/admin.component.ts +++ b/src/app/pages/admin/admin.component.ts @@ -2,7 +2,7 @@ import {ChangeDetectionStrategy, Component, OnInit, ViewChild} from '@angular/co import {MatTableDataSource} from '@angular/material/table'; import {MatPaginator} from '@angular/material/paginator'; import {MatSort} from '@angular/material/sort'; -import {UserService} from '@app/_services'; +import {LoggingService, UserService} from '@app/_services'; import {animate, state, style, transition, trigger} from '@angular/animations'; import {first} from 'rxjs/operators'; @@ -28,7 +28,8 @@ export class AdminComponent implements OnInit { @ViewChild(MatSort) sort: MatSort; constructor( - private userService: UserService + private userService: UserService, + private loggingService: LoggingService ) { this.userService.getActions(); this.userService.actionsSubject.subscribe(actions => { @@ -50,12 +51,12 @@ export class AdminComponent implements OnInit { } approveAction(action: any): void { - this.userService.approveAction(action.id).pipe(first()).subscribe(res => console.log(res.body)); + this.userService.approveAction(action.id).pipe(first()).subscribe(res => this.loggingService.sendInfoLevelMessage(res.body)); this.userService.getActions(); } revertAction(action: any): void { - this.userService.revokeAction(action.id).pipe(first()).subscribe(res => console.log(res.body)); + this.userService.revokeAction(action.id).pipe(first()).subscribe(res => this.loggingService.sendInfoLevelMessage(res.body)); this.userService.getActions(); } diff --git a/src/app/pages/pages.component.ts b/src/app/pages/pages.component.ts index 1766d38..14ba106 100644 --- a/src/app/pages/pages.component.ts +++ b/src/app/pages/pages.component.ts @@ -1,7 +1,7 @@ import {ChangeDetectionStrategy, Component, OnInit} from '@angular/core'; import {Color, Label} from 'ng2-charts'; import {ChartDataSets, ChartOptions, ChartType} from 'chart.js'; -import {LocationService, UserService} from '@app/_services'; +import {LocationService, LoggingService} from '@app/_services'; import {ArraySum} from '@app/_helpers'; @Component({ @@ -149,8 +149,8 @@ export class PagesComponent implements OnInit { ]; constructor( - private userService: UserService, - private locationService: LocationService + private locationService: LocationService, + private loggingService: LoggingService ) { this.locationService.getLocations(); this.locationService.locationsSubject.subscribe(locations => { @@ -177,11 +177,11 @@ export class PagesComponent implements OnInit { } public chartClicked({ event, active}: { event: MouseEvent, active: {}[] }): void { - console.log(event, active); + this.loggingService.sendInfoLevelMessage(`Event: ${event}, ${active}`); } public chartHovered({ event, active }: { event: MouseEvent, active: {}[] }): void { - console.log(event, active); + this.loggingService.sendInfoLevelMessage(`Event: ${event}, ${active}`); } public trackByName(index, item): string { diff --git a/src/app/pages/settings/settings.component.html b/src/app/pages/settings/settings.component.html index 24fcdaa..7fdd713 100644 --- a/src/app/pages/settings/settings.component.html +++ b/src/app/pages/settings/settings.component.html @@ -58,8 +58,7 @@
- USERS - + TRUSTED USERS
@@ -70,46 +69,24 @@ + NAME {{user.name}} - - ACCOUNT TYPE - {{user.accountType}} + + EMAIL + {{user.email}} - - CREATED - {{user.created}} - - - - STATUS - - {{user.status}} - {{user.status}} - - - - - OPTIONS - - - - - - - - - - - + + USER ID + {{user.userid}} - + diff --git a/src/app/pages/settings/settings.component.ts b/src/app/pages/settings/settings.component.ts index fb95121..2154554 100644 --- a/src/app/pages/settings/settings.component.ts +++ b/src/app/pages/settings/settings.component.ts @@ -2,8 +2,8 @@ import {ChangeDetectionStrategy, Component, OnInit, ViewChild} from '@angular/co import {MatTableDataSource} from '@angular/material/table'; import {MatPaginator} from '@angular/material/paginator'; import {MatSort} from '@angular/material/sort'; -import {UserService} from '@app/_services'; -import {first} from 'rxjs/operators'; +import {AuthService} from '@app/_services'; +import {Staff} from '@app/_models/staff'; @Component({ selector: 'app-settings', @@ -14,43 +14,26 @@ import {first} from 'rxjs/operators'; export class SettingsComponent implements OnInit { date: string; dataSource: MatTableDataSource; - displayedColumns = ['name', 'accountType', 'created', 'status', 'options']; + displayedColumns = ['name', 'email', 'userId']; + trustedUsers: Staff[]; @ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatSort) sort: MatSort; constructor( - private userService: UserService - ) { - this.userService.getStaff(); - } + private authService: AuthService + ) { } ngOnInit(): void { - this.userService.staffSubject.subscribe(staff => { - this.dataSource = new MatTableDataSource(staff); - this.dataSource.paginator = this.paginator; - this.dataSource.sort = this.sort; - }); const d = new Date(); this.date = `${d.getDate()}/${d.getMonth()}/${d.getFullYear()}`; + this.trustedUsers = this.authService.getTrustedUsers(); + this.dataSource = new MatTableDataSource(this.trustedUsers); + this.dataSource.paginator = this.paginator; + this.dataSource.sort = this.sort; } doFilter(value: string): void { this.dataSource.filter = value.trim().toLocaleLowerCase(); } - - activateStaff(id: string): void { - this.userService.activateStaff(id).pipe(first()).subscribe(res => console.log(res.body)); - this.userService.getStaff(); - } - - deactivateStaff(id: string): void { - this.userService.deactivateStaff(id).pipe(first()).subscribe(res => console.log(res.body)); - this.userService.getStaff(); - } - - changeStaffType(id: string, type: string): void { - this.userService.changeStaffType(id, type).pipe(first()).subscribe(res => console.log(res.body)); - this.userService.getStaff(); - } } diff --git a/src/app/pages/tokens/tokens.component.ts b/src/app/pages/tokens/tokens.component.ts index ad6cade..d25ce51 100644 --- a/src/app/pages/tokens/tokens.component.ts +++ b/src/app/pages/tokens/tokens.component.ts @@ -1,7 +1,7 @@ import {ChangeDetectionStrategy, Component, OnInit, ViewChild} from '@angular/core'; import {MatPaginator} from '@angular/material/paginator'; import {MatSort} from '@angular/material/sort'; -import {TokenService} from '@app/_services'; +import {LoggingService, TokenService} from '@app/_services'; import {MatTableDataSource} from '@angular/material/table'; import {Router} from '@angular/router'; @@ -16,15 +16,17 @@ export class TokensComponent implements OnInit { columnsToDisplay = ['name', 'symbol', 'address', 'supply']; @ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatSort) sort: MatSort; + tokens: any; constructor( private tokenService: TokenService, + private loggingService: LoggingService, private router: Router - ) { - tokenService.getTokens(); - } + ) { } - ngOnInit(): void { + async ngOnInit(): Promise { + this.tokens = await this.tokenService.getTokens(); + this.loggingService.sendInfoLevelMessage(this.tokens); this.tokenService.tokensSubject.subscribe(tokens => { this.dataSource = new MatTableDataSource(tokens); this.dataSource.paginator = this.paginator; @@ -36,7 +38,7 @@ export class TokensComponent implements OnInit { this.dataSource.filter = value.trim().toLocaleLowerCase(); } - viewToken(token): void { - this.router.navigateByUrl(`/tokens/${token.symbol}`).then(); + async viewToken(token): Promise { + await this.router.navigateByUrl(`/tokens/${token.symbol}`); } } diff --git a/src/app/pages/transactions/transaction-details/transaction-details.component.ts b/src/app/pages/transactions/transaction-details/transaction-details.component.ts index 3848d0c..36f647a 100644 --- a/src/app/pages/transactions/transaction-details/transaction-details.component.ts +++ b/src/app/pages/transactions/transaction-details/transaction-details.component.ts @@ -19,11 +19,11 @@ export class TransactionDetailsComponent implements OnInit { this.recipientBloxbergLink = 'https://blockexplorer.bloxberg.org/address/' + this.transaction?.to + '/transactions'; } - viewSender(): void { - this.router.navigateByUrl(`/accounts/${this.transaction.from}`).then(); + async viewSender(): Promise { + await this.router.navigateByUrl(`/accounts/${this.transaction.from}`); } - viewRecipient(): void { - this.router.navigateByUrl(`/accounts/${this.transaction.to}`).then(); + async viewRecipient(): Promise { + await this.router.navigateByUrl(`/accounts/${this.transaction.to}`); } }