Break accounts details component onInit function into multiple standalone functions.
This commit is contained in:
parent
742c589835
commit
aa8d9c5c73
@ -29,7 +29,7 @@ addEventListener('message', async ({ data }) => {
|
|||||||
async function getAccountByAddress(
|
async function getAccountByAddress(
|
||||||
accountAddress: string,
|
accountAddress: string,
|
||||||
metaUrl: string,
|
metaUrl: string,
|
||||||
token: string,
|
token: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const userKey = await User.toKey(add0x(accountAddress));
|
const userKey = await User.toKey(add0x(accountAddress));
|
||||||
|
|
||||||
|
@ -110,19 +110,7 @@ export class AccountDetailsComponent implements OnInit, AfterViewInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async ngOnInit(): Promise<void> {
|
async ngOnInit(): Promise<void> {
|
||||||
this.accountInfoForm = this.formBuilder.group({
|
this.buildAccountsInfoForm();
|
||||||
firstName: ['', Validators.required],
|
|
||||||
lastName: ['', Validators.required],
|
|
||||||
phoneNumber: ['', Validators.required],
|
|
||||||
age: [''],
|
|
||||||
type: ['', Validators.required],
|
|
||||||
bio: ['', Validators.required],
|
|
||||||
gender: ['', Validators.required],
|
|
||||||
businessCategory: ['', Validators.required],
|
|
||||||
userLocation: ['', Validators.required],
|
|
||||||
location: ['', Validators.required],
|
|
||||||
locationType: ['', Validators.required],
|
|
||||||
});
|
|
||||||
this.transactionService.resetTransactionsList();
|
this.transactionService.resetTransactionsList();
|
||||||
await this.blockSyncService.blockSync(this.accountAddress);
|
await this.blockSyncService.blockSync(this.accountAddress);
|
||||||
this.userService.resetAccountsList();
|
this.userService.resetAccountsList();
|
||||||
@ -131,35 +119,8 @@ export class AccountDetailsComponent implements OnInit, AfterViewInit {
|
|||||||
if (res !== undefined) {
|
if (res !== undefined) {
|
||||||
this.account = res;
|
this.account = res;
|
||||||
this.cdr.detectChanges();
|
this.cdr.detectChanges();
|
||||||
this.locationService.areaNamesSubject.subscribe((response) => {
|
this.queryLocationAndCategory(this.account);
|
||||||
this.area = this.locationService.getAreaNameByLocation(
|
this.populateAccountsInfoForm(this.account);
|
||||||
this.account.location.area_name,
|
|
||||||
response
|
|
||||||
);
|
|
||||||
this.cdr.detectChanges();
|
|
||||||
this.locationService.areaTypesSubject.subscribe((result) => {
|
|
||||||
this.areaType = this.locationService.getAreaTypeByArea(this.area, result);
|
|
||||||
this.cdr.detectChanges();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
this.userService.categoriesSubject.subscribe((result) => {
|
|
||||||
this.category = this.userService.getCategoryByProduct(this.account.products[0], result);
|
|
||||||
this.cdr.detectChanges();
|
|
||||||
});
|
|
||||||
const fullName = this.account.vcard?.fn[0].value.split(' ');
|
|
||||||
this.accountInfoForm.patchValue({
|
|
||||||
firstName: fullName[0].split(',')[0],
|
|
||||||
lastName: fullName.slice(1).join(' '),
|
|
||||||
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 || this.category || 'other',
|
|
||||||
userLocation: this.account.location.area_name,
|
|
||||||
location: this.account.location.area || this.area || 'other',
|
|
||||||
locationType: this.account.location.area_type || this.areaType || 'other',
|
|
||||||
});
|
|
||||||
this.userService
|
this.userService
|
||||||
.getAccountStatus(this.account.vcard?.tel[0].value)
|
.getAccountStatus(this.account.vcard?.tel[0].value)
|
||||||
.pipe(first())
|
.pipe(first())
|
||||||
@ -169,63 +130,8 @@ export class AccountDetailsComponent implements OnInit, AfterViewInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
this.userService.accountsSubject.subscribe((accounts) => {
|
this.populateDataTables();
|
||||||
this.userDataSource = new MatTableDataSource<any>(accounts);
|
this.loadSearchData();
|
||||||
this.userDataSource.paginator = this.userTablePaginator;
|
|
||||||
this.userDataSource.sort = this.userTableSort;
|
|
||||||
this.accounts = accounts;
|
|
||||||
if (accounts.length > 0) {
|
|
||||||
this.accountsLoading = false;
|
|
||||||
}
|
|
||||||
this.cdr.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
this.transactionService.transactionsSubject.subscribe((transactions) => {
|
|
||||||
this.transactionsDataSource = new MatTableDataSource<any>(transactions);
|
|
||||||
this.transactionsDataSource.paginator = this.transactionTablePaginator;
|
|
||||||
this.transactionsDataSource.sort = this.transactionTableSort;
|
|
||||||
this.transactions = transactions;
|
|
||||||
if (transactions.length > 0) {
|
|
||||||
this.transactionsLoading = false;
|
|
||||||
}
|
|
||||||
this.cdr.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
this.userService.historySubject.subscribe(async (histories) => {
|
|
||||||
this.historyDataSource = new MatTableDataSource<any>(histories);
|
|
||||||
this.historyDataSource.paginator = this.historyTablePaginator;
|
|
||||||
this.historyDataSource.sort = this.historyTableSort;
|
|
||||||
this.histories = histories;
|
|
||||||
if (histories.length > 0) {
|
|
||||||
this.historyLoading = false;
|
|
||||||
}
|
|
||||||
this.cdr.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
this.userService.getCategories();
|
|
||||||
this.userService.categoriesSubject.subscribe((res) => {
|
|
||||||
this.categories = Object.keys(res);
|
|
||||||
});
|
|
||||||
this.locationService.getAreaNames();
|
|
||||||
this.locationService.areaNamesSubject.subscribe((res) => {
|
|
||||||
this.areaNames = Object.keys(res);
|
|
||||||
});
|
|
||||||
this.locationService.getAreaTypes();
|
|
||||||
this.locationService.areaTypesSubject.subscribe((res) => {
|
|
||||||
this.areaTypes = Object.keys(res);
|
|
||||||
});
|
|
||||||
this.userService
|
|
||||||
.getAccountTypes()
|
|
||||||
.pipe(first())
|
|
||||||
.subscribe((res) => (this.accountTypes = res));
|
|
||||||
this.userService
|
|
||||||
.getTransactionTypes()
|
|
||||||
.pipe(first())
|
|
||||||
.subscribe((res) => (this.transactionsTypes = res));
|
|
||||||
this.userService
|
|
||||||
.getGenders()
|
|
||||||
.pipe(first())
|
|
||||||
.subscribe((res) => (this.genders = res));
|
|
||||||
this.tokenService.load.subscribe(async (status: boolean) => {
|
this.tokenService.load.subscribe(async (status: boolean) => {
|
||||||
if (status) {
|
if (status) {
|
||||||
this.tokenSymbol = await this.tokenService.getTokenSymbol();
|
this.tokenSymbol = await this.tokenService.getTokenSymbol();
|
||||||
@ -355,4 +261,117 @@ export class AccountDetailsComponent implements OnInit, AfterViewInit {
|
|||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildAccountsInfoForm(): void {
|
||||||
|
this.accountInfoForm = this.formBuilder.group({
|
||||||
|
firstName: ['', Validators.required],
|
||||||
|
lastName: ['', Validators.required],
|
||||||
|
phoneNumber: ['', Validators.required],
|
||||||
|
age: [''],
|
||||||
|
type: ['', Validators.required],
|
||||||
|
bio: ['', Validators.required],
|
||||||
|
gender: ['', Validators.required],
|
||||||
|
businessCategory: ['', Validators.required],
|
||||||
|
userLocation: ['', Validators.required],
|
||||||
|
location: ['', Validators.required],
|
||||||
|
locationType: ['', Validators.required],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
populateAccountsInfoForm(accountInfo: AccountDetails): void {
|
||||||
|
const fullName = accountInfo.vcard?.fn[0].value.split(' ');
|
||||||
|
this.accountInfoForm.patchValue({
|
||||||
|
firstName: fullName[0].split(',')[0],
|
||||||
|
lastName: fullName.slice(1).join(' '),
|
||||||
|
phoneNumber: accountInfo.vcard?.tel[0].value,
|
||||||
|
age: accountInfo.age,
|
||||||
|
type: accountInfo.type,
|
||||||
|
bio: accountInfo.products,
|
||||||
|
gender: accountInfo.gender,
|
||||||
|
businessCategory: accountInfo.category || this.category || 'other',
|
||||||
|
userLocation: accountInfo.location.area_name,
|
||||||
|
location: accountInfo.location.area || this.area || 'other',
|
||||||
|
locationType: accountInfo.location.area_type || this.areaType || 'other',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
populateDataTables(): void {
|
||||||
|
this.userService.accountsSubject.subscribe((accounts) => {
|
||||||
|
this.userDataSource = new MatTableDataSource<any>(accounts);
|
||||||
|
this.userDataSource.paginator = this.userTablePaginator;
|
||||||
|
this.userDataSource.sort = this.userTableSort;
|
||||||
|
this.accounts = accounts;
|
||||||
|
if (accounts.length > 0) {
|
||||||
|
this.accountsLoading = false;
|
||||||
|
}
|
||||||
|
this.cdr.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.transactionService.transactionsSubject.subscribe((transactions) => {
|
||||||
|
this.transactionsDataSource = new MatTableDataSource<any>(transactions);
|
||||||
|
this.transactionsDataSource.paginator = this.transactionTablePaginator;
|
||||||
|
this.transactionsDataSource.sort = this.transactionTableSort;
|
||||||
|
this.transactions = transactions;
|
||||||
|
if (transactions.length > 0) {
|
||||||
|
this.transactionsLoading = false;
|
||||||
|
}
|
||||||
|
this.cdr.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.userService.historySubject.subscribe(async (histories) => {
|
||||||
|
this.historyDataSource = new MatTableDataSource<any>(histories);
|
||||||
|
this.historyDataSource.paginator = this.historyTablePaginator;
|
||||||
|
this.historyDataSource.sort = this.historyTableSort;
|
||||||
|
this.histories = histories;
|
||||||
|
if (histories.length > 0) {
|
||||||
|
this.historyLoading = false;
|
||||||
|
}
|
||||||
|
this.cdr.detectChanges();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
queryLocationAndCategory(accountInfo: AccountDetails): void {
|
||||||
|
this.locationService.areaNamesSubject.subscribe((response) => {
|
||||||
|
this.area = this.locationService.getAreaNameByLocation(
|
||||||
|
accountInfo.location.area_name,
|
||||||
|
response
|
||||||
|
);
|
||||||
|
this.cdr.detectChanges();
|
||||||
|
this.locationService.areaTypesSubject.subscribe((result) => {
|
||||||
|
this.areaType = this.locationService.getAreaTypeByArea(this.area, result);
|
||||||
|
this.cdr.detectChanges();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
this.userService.categoriesSubject.subscribe((result) => {
|
||||||
|
this.category = this.userService.getCategoryByProduct(accountInfo.products[0], result);
|
||||||
|
this.cdr.detectChanges();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
loadSearchData(): void {
|
||||||
|
this.userService.getCategories();
|
||||||
|
this.userService.categoriesSubject.subscribe((res) => {
|
||||||
|
this.categories = Object.keys(res);
|
||||||
|
});
|
||||||
|
this.locationService.getAreaNames();
|
||||||
|
this.locationService.areaNamesSubject.subscribe((res) => {
|
||||||
|
this.areaNames = Object.keys(res);
|
||||||
|
});
|
||||||
|
this.locationService.getAreaTypes();
|
||||||
|
this.locationService.areaTypesSubject.subscribe((res) => {
|
||||||
|
this.areaTypes = Object.keys(res);
|
||||||
|
});
|
||||||
|
this.userService
|
||||||
|
.getAccountTypes()
|
||||||
|
.pipe(first())
|
||||||
|
.subscribe((res) => (this.accountTypes = res));
|
||||||
|
this.userService
|
||||||
|
.getTransactionTypes()
|
||||||
|
.pipe(first())
|
||||||
|
.subscribe((res) => (this.transactionsTypes = res));
|
||||||
|
this.userService
|
||||||
|
.getGenders()
|
||||||
|
.pipe(first())
|
||||||
|
.subscribe((res) => (this.genders = res));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user