2021-04-25 12:32:23 +02:00
|
|
|
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit, ViewChild} from '@angular/core';
|
2020-11-25 08:57:17 +01:00
|
|
|
import {MatTableDataSource} from '@angular/material/table';
|
|
|
|
import {MatPaginator} from '@angular/material/paginator';
|
|
|
|
import {MatSort} from '@angular/material/sort';
|
2021-03-15 12:58:18 +01:00
|
|
|
import {BlockSyncService, LocationService, LoggingService, TokenService, TransactionService, UserService} from '@app/_services';
|
2020-12-05 07:30:30 +01:00
|
|
|
import {ActivatedRoute, Params, Router} from '@angular/router';
|
|
|
|
import {first} from 'rxjs/operators';
|
2021-02-08 12:47:07 +01:00
|
|
|
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
|
2021-04-26 12:14:36 +02:00
|
|
|
import {copyToClipboard, CustomErrorStateMatcher, exportCsv} from '@app/_helpers';
|
|
|
|
import {MatSnackBar} from '@angular/material/snack-bar';
|
2020-11-25 08:57:17 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-account-details',
|
|
|
|
templateUrl: './account-details.component.html',
|
2021-03-14 09:23:20 +01:00
|
|
|
styleUrls: ['./account-details.component.scss'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
2020-11-25 08:57:17 +01:00
|
|
|
})
|
2020-12-05 07:30:30 +01:00
|
|
|
export class AccountDetailsComponent implements OnInit {
|
|
|
|
transactionsDataSource: MatTableDataSource<any>;
|
2021-03-15 12:58:18 +01:00
|
|
|
transactionsDisplayedColumns = ['sender', 'recipient', 'value', 'created', 'type'];
|
|
|
|
transactionsDefaultPageSize = 10;
|
|
|
|
transactionsPageSizeOptions = [10, 20, 50, 100];
|
2020-12-05 07:30:30 +01:00
|
|
|
@ViewChild('TransactionTablePaginator', {static: true}) transactionTablePaginator: MatPaginator;
|
|
|
|
@ViewChild('TransactionTableSort', {static: true}) transactionTableSort: MatSort;
|
|
|
|
|
|
|
|
userDataSource: MatTableDataSource<any>;
|
2021-03-15 12:58:18 +01:00
|
|
|
userDisplayedColumns = ['name', 'phone', 'created', 'balance', 'location'];
|
|
|
|
usersDefaultPageSize = 10;
|
|
|
|
usersPageSizeOptions = [10, 20, 50, 100];
|
2020-12-05 07:30:30 +01:00
|
|
|
@ViewChild('UserTablePaginator', {static: true}) userTablePaginator: MatPaginator;
|
|
|
|
@ViewChild('UserTableSort', {static: true}) userTableSort: MatSort;
|
|
|
|
|
2021-02-08 12:47:07 +01:00
|
|
|
accountInfoForm: FormGroup;
|
2020-12-05 07:30:30 +01:00
|
|
|
account: any;
|
2021-03-15 12:58:18 +01:00
|
|
|
accountAddress: string;
|
2021-03-24 10:42:19 +01:00
|
|
|
accountStatus: any;
|
2020-12-05 07:30:30 +01:00
|
|
|
accounts: any[] = [];
|
|
|
|
accountsType = 'all';
|
|
|
|
locations: any;
|
|
|
|
transaction: any;
|
|
|
|
transactions: any[];
|
|
|
|
transactionsType = 'all';
|
2021-02-08 12:47:07 +01:00
|
|
|
matcher = new CustomErrorStateMatcher();
|
|
|
|
submitted: boolean = false;
|
2021-02-23 13:32:02 +01:00
|
|
|
bloxbergLink: string;
|
2020-11-25 08:57:17 +01:00
|
|
|
|
|
|
|
constructor(
|
2021-02-08 12:47:07 +01:00
|
|
|
private formBuilder: FormBuilder,
|
2020-12-05 07:30:30 +01:00
|
|
|
private locationService: LocationService,
|
2020-11-25 08:57:17 +01:00
|
|
|
private transactionService: TransactionService,
|
|
|
|
private userService: UserService,
|
2020-12-05 07:30:30 +01:00
|
|
|
private route: ActivatedRoute,
|
2021-03-10 10:47:01 +01:00
|
|
|
private router: Router,
|
2021-03-14 09:23:20 +01:00
|
|
|
private tokenService: TokenService,
|
2021-03-15 12:58:18 +01:00
|
|
|
private loggingService: LoggingService,
|
2021-04-25 12:32:23 +02:00
|
|
|
private blockSyncService: BlockSyncService,
|
|
|
|
private cdr: ChangeDetectorRef,
|
2021-04-26 12:14:36 +02:00
|
|
|
private snackBar: MatSnackBar,
|
2020-11-25 08:57:17 +01:00
|
|
|
) {
|
2021-02-08 12:47:07 +01:00
|
|
|
this.accountInfoForm = this.formBuilder.group({
|
|
|
|
name: ['', Validators.required],
|
|
|
|
phoneNumber: ['', Validators.required],
|
2021-02-23 13:32:02 +01:00
|
|
|
age: ['', Validators.required],
|
2021-02-08 12:47:07 +01:00
|
|
|
type: ['', Validators.required],
|
|
|
|
bio: ['', Validators.required],
|
|
|
|
gender: ['', Validators.required],
|
|
|
|
businessCategory: ['', Validators.required],
|
|
|
|
userLocation: ['', Validators.required],
|
|
|
|
location: ['', Validators.required],
|
2021-02-23 13:32:02 +01:00
|
|
|
locationType: ['', Validators.required],
|
2021-02-08 12:47:07 +01:00
|
|
|
});
|
2021-03-06 07:28:29 +01:00
|
|
|
this.route.paramMap.subscribe(async (params: Params) => {
|
2021-03-15 12:58:18 +01:00
|
|
|
this.accountAddress = params.get('id');
|
|
|
|
this.bloxbergLink = 'https://blockexplorer.bloxberg.org/address/' + this.accountAddress + '/transactions';
|
2021-04-25 12:32:23 +02:00
|
|
|
(await this.userService.getAccountByAddress(this.accountAddress, 100)).subscribe(async res => {
|
|
|
|
if (res !== undefined) {
|
|
|
|
this.account = res;
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
this.loggingService.sendInfoLevelMessage(this.account);
|
|
|
|
// this.userService.getAccountStatus(this.account.vcard?.tel[0].value).pipe(first()).subscribe(response => this.accountStatus = response);
|
|
|
|
this.accountInfoForm.patchValue({
|
|
|
|
name: this.account.vcard?.fn[0].value,
|
|
|
|
phoneNumber: this.account.vcard?.tel[0].value,
|
|
|
|
age: this.account.age,
|
|
|
|
type: this.account.type,
|
|
|
|
bio: this.account.products,
|
|
|
|
gender: this.account.gender,
|
|
|
|
businessCategory: this.account.category,
|
|
|
|
userLocation: this.account.location.area_name,
|
|
|
|
location: this.account.location.area,
|
|
|
|
locationType: this.account.location.area_type,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
alert('Account not found!');
|
|
|
|
}
|
2020-12-05 07:30:30 +01:00
|
|
|
});
|
2021-03-15 12:58:18 +01:00
|
|
|
this.blockSyncService.blockSync(this.accountAddress);
|
2020-12-05 07:30:30 +01:00
|
|
|
});
|
|
|
|
this.userService.getAccounts();
|
|
|
|
this.locationService.getLocations();
|
|
|
|
this.locationService.locationsSubject.subscribe(locations => {
|
|
|
|
this.locations = locations;
|
2020-11-25 08:57:17 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2020-12-05 07:30:30 +01:00
|
|
|
this.userService.accountsSubject.subscribe(accounts => {
|
|
|
|
this.userDataSource = new MatTableDataSource<any>(accounts);
|
|
|
|
this.userDataSource.paginator = this.userTablePaginator;
|
|
|
|
this.userDataSource.sort = this.userTableSort;
|
|
|
|
this.accounts = accounts;
|
|
|
|
});
|
|
|
|
|
2020-11-25 08:57:17 +01:00
|
|
|
this.transactionService.transactionsSubject.subscribe(transactions => {
|
2020-12-05 07:30:30 +01:00
|
|
|
this.transactionsDataSource = new MatTableDataSource<any>(transactions);
|
|
|
|
this.transactionsDataSource.paginator = this.transactionTablePaginator;
|
|
|
|
this.transactionsDataSource.sort = this.transactionTableSort;
|
|
|
|
this.transactions = transactions;
|
2020-11-25 08:57:17 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-12-05 07:30:30 +01:00
|
|
|
doTransactionFilter(value: string): void {
|
|
|
|
this.transactionsDataSource.filter = value.trim().toLocaleLowerCase();
|
2020-11-25 08:57:17 +01:00
|
|
|
}
|
|
|
|
|
2020-12-05 07:30:30 +01:00
|
|
|
doUserFilter(value: string): void {
|
|
|
|
this.userDataSource.filter = value.trim().toLocaleLowerCase();
|
2020-11-25 08:57:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
viewTransaction(transaction): void {
|
|
|
|
this.transaction = transaction;
|
|
|
|
}
|
2020-12-05 07:30:30 +01:00
|
|
|
|
|
|
|
viewAccount(account): void {
|
|
|
|
this.router.navigateByUrl(`/accounts/${account.id}`);
|
|
|
|
}
|
|
|
|
|
2021-02-08 12:47:07 +01:00
|
|
|
get accountInfoFormStub(): any { return this.accountInfoForm.controls; }
|
|
|
|
|
2021-03-18 10:10:55 +01:00
|
|
|
async saveInfo(): Promise<void> {
|
2021-02-08 12:47:07 +01:00
|
|
|
this.submitted = true;
|
2021-03-24 10:42:19 +01:00
|
|
|
if (this.accountInfoForm.invalid || !confirm('Change user\'s profile information?')) { return; }
|
2021-03-18 10:10:55 +01:00
|
|
|
const accountKey = await this.userService.changeAccountInfo(
|
2021-04-25 12:32:23 +02:00
|
|
|
this.accountAddress,
|
2021-02-08 12:47:07 +01:00
|
|
|
this.accountInfoFormStub.name.value,
|
|
|
|
this.accountInfoFormStub.phoneNumber.value,
|
2021-02-23 13:32:02 +01:00
|
|
|
this.accountInfoFormStub.age.value,
|
2021-02-08 12:47:07 +01:00
|
|
|
this.accountInfoFormStub.type.value,
|
|
|
|
this.accountInfoFormStub.bio.value,
|
|
|
|
this.accountInfoFormStub.gender.value,
|
|
|
|
this.accountInfoFormStub.businessCategory.value,
|
|
|
|
this.accountInfoFormStub.userLocation.value,
|
|
|
|
this.accountInfoFormStub.location.value,
|
2021-02-23 13:32:02 +01:00
|
|
|
this.accountInfoFormStub.locationType.value,
|
2021-04-27 19:16:12 +02:00
|
|
|
this.account.date_registered,
|
|
|
|
this.account.identities
|
2021-03-18 10:10:55 +01:00
|
|
|
);
|
2021-02-08 12:47:07 +01:00
|
|
|
this.submitted = false;
|
|
|
|
}
|
2020-12-05 07:30:30 +01:00
|
|
|
|
|
|
|
filterAccounts(): void {
|
|
|
|
if (this.accountsType === 'all') {
|
|
|
|
this.userService.accountsSubject.subscribe(accounts => {
|
|
|
|
this.userDataSource.data = accounts;
|
|
|
|
this.accounts = accounts;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.userDataSource.data = this.accounts.filter(account => account.type === this.accountsType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
filterTransactions(): void {
|
|
|
|
if (this.transactionsType === 'all') {
|
|
|
|
this.transactionService.transactionsSubject.subscribe(transactions => {
|
|
|
|
this.transactionsDataSource.data = transactions;
|
|
|
|
this.transactions = transactions;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.transactionsDataSource.data = this.transactions.filter(transaction => transaction.type === this.transactionsType);
|
|
|
|
}
|
|
|
|
}
|
2021-02-08 12:47:07 +01:00
|
|
|
|
|
|
|
resetPin(): void {
|
2021-03-24 10:42:19 +01:00
|
|
|
if (!confirm('Reset user\'s pin?')) { return; }
|
2021-02-08 12:47:07 +01:00
|
|
|
this.userService.resetPin(this.account.phone).pipe(first()).subscribe(res => {
|
2021-03-21 12:02:18 +01:00
|
|
|
this.loggingService.sendInfoLevelMessage(`Response: ${res}`);
|
2021-02-08 12:47:07 +01:00
|
|
|
});
|
|
|
|
}
|
2021-03-14 09:23:20 +01:00
|
|
|
|
|
|
|
public trackByName(index, item): string {
|
|
|
|
return item.name;
|
|
|
|
}
|
2021-03-24 14:26:51 +01:00
|
|
|
|
|
|
|
downloadCsv(data: any, filename: string): void {
|
|
|
|
exportCsv(data, filename);
|
|
|
|
}
|
2021-04-26 12:14:36 +02:00
|
|
|
|
|
|
|
copyAddress(): void {
|
|
|
|
if (copyToClipboard(this.accountAddress)) {
|
|
|
|
this.snackBar.open(this.accountAddress + ' copied successfully!', 'Close', { duration: 3000 });
|
|
|
|
}
|
|
|
|
}
|
2020-11-25 08:57:17 +01:00
|
|
|
}
|