diff --git a/src/app/_services/transaction.service.ts b/src/app/_services/transaction.service.ts index f3a271c..6a4897d 100644 --- a/src/app/_services/transaction.service.ts +++ b/src/app/_services/transaction.service.ts @@ -61,10 +61,11 @@ export class TransactionService { .pipe(first()) .subscribe( (res) => { - transaction.sender = this.getAccountInfo(res); + transaction.sender = this.getAccountInfo(res, cacheSize); }, (error) => { transaction.sender = defaultAccount; + this.userService.addAccount(defaultAccount, cacheSize); } ); this.userService @@ -72,10 +73,11 @@ export class TransactionService { .pipe(first()) .subscribe( (res) => { - transaction.recipient = this.getAccountInfo(res); + transaction.recipient = this.getAccountInfo(res, cacheSize); }, (error) => { transaction.recipient = defaultAccount; + this.userService.addAccount(defaultAccount, cacheSize); } ); } finally { @@ -100,6 +102,7 @@ export class TransactionService { }, (error) => { conversion.sender = conversion.recipient = defaultAccount; + this.userService.addAccount(defaultAccount, cacheSize); } ); } finally { @@ -108,8 +111,10 @@ export class TransactionService { } addTransaction(transaction, cacheSize: number): void { - const savedIndex = this.transactions.findIndex(tx => tx.tx.txHash === transaction.tx.txHash); - if (savedIndex === 0) { return; } + const savedIndex = this.transactions.findIndex((tx) => tx.tx.txHash === transaction.tx.txHash); + if (savedIndex === 0) { + return; + } if (savedIndex > 0) { this.transactions.splice(savedIndex, 1); } @@ -125,9 +130,10 @@ export class TransactionService { this.transactionList.next(this.transactions); } - getAccountInfo(account: string): any { + getAccountInfo(account: string, cacheSize: number = 100): any { const accountInfo = JSON.parse(Envelope.fromJSON(JSON.stringify(account)).unwrap().m.data); accountInfo.vcard = vCard.parse(atob(accountInfo.vcard)); + this.userService.addAccount(accountInfo, cacheSize); return accountInfo; } diff --git a/src/app/_services/user.service.ts b/src/app/_services/user.service.ts index 68941fa..85ffc32 100644 --- a/src/app/_services/user.service.ts +++ b/src/app/_services/user.service.ts @@ -210,11 +210,7 @@ export class UserService { }; accountInfo.vcard = vCard.parse(atob(accountInfo.vcard)); await vcardValidation(accountInfo.vcard); - this.accounts.unshift(accountInfo); - if (this.accounts.length > limit) { - this.accounts.length = limit; - } - this.accountsList.next(this.accounts); + this.addAccount(accountInfo, limit); accountSubject.next(accountInfo); }); return accountSubject.asObservable(); @@ -266,4 +262,23 @@ export class UserService { getGenders(): Observable { return this.httpClient.get(`${environment.cicMetaUrl}/genders`); } + + addAccount(account: AccountDetails, cacheSize: number): void { + const savedIndex = this.accounts.findIndex( + (acc) => + acc.identities.evm[`bloxberg:${environment.bloxbergChainId}`][0] === + account.identities.evm[`bloxberg:${environment.bloxbergChainId}`][0] + ); + if (savedIndex === 0) { + return; + } + if (savedIndex > 0) { + this.accounts.splice(savedIndex, 1); + } + this.accounts.unshift(account); + if (this.accounts.length > cacheSize) { + this.accounts.length = Math.min(this.accounts.length, cacheSize); + } + this.accountsList.next(this.accounts); + } } diff --git a/src/app/pages/accounts/account-details/account-details.component.html b/src/app/pages/accounts/account-details/account-details.component.html index 4cdec33..a784822 100644 --- a/src/app/pages/accounts/account-details/account-details.component.html +++ b/src/app/pages/accounts/account-details/account-details.component.html @@ -252,7 +252,7 @@ search - @@ -285,10 +285,10 @@ - - - + + + 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 5a26eab..39cdcbf 100644 --- a/src/app/pages/accounts/account-details/account-details.component.ts +++ b/src/app/pages/accounts/account-details/account-details.component.ts @@ -90,37 +90,54 @@ export class AccountDetailsComponent implements OnInit { location: ['', Validators.required], locationType: ['', Validators.required], }); - this.route.paramMap.subscribe(async (params: Params) => { + this.route.paramMap.subscribe((params: Params) => { this.accountAddress = add0x(params.get('id')); this.bloxbergLink = 'https://blockexplorer.bloxberg.org/address/' + this.accountAddress + '/transactions'; - (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!'); - } - } - ); this.blockSyncService.blockSync(this.accountAddress); }); + } + + async ngOnInit(): Promise { + (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!'); + } + } + ); + this.userService.accountsSubject.subscribe((accounts) => { + this.userDataSource = new MatTableDataSource(accounts); + this.userDataSource.paginator = this.userTablePaginator; + this.userDataSource.sort = this.userTableSort; + this.accounts = accounts; + }); + + this.transactionService.transactionsSubject.subscribe((transactions) => { + this.transactionsDataSource = new MatTableDataSource(transactions); + this.transactionsDataSource.paginator = this.transactionTablePaginator; + this.transactionsDataSource.sort = this.transactionTableSort; + this.transactions = transactions; + this.cdr.detectChanges(); + }); this.userService .getCategories() .pipe(first()) @@ -147,22 +164,6 @@ export class AccountDetailsComponent implements OnInit { .subscribe((res) => (this.genders = res)); } - ngOnInit(): void { - this.userService.accountsSubject.subscribe((accounts) => { - this.userDataSource = new MatTableDataSource(accounts); - this.userDataSource.paginator = this.userTablePaginator; - this.userDataSource.sort = this.userTableSort; - this.accounts = accounts; - }); - - this.transactionService.transactionsSubject.subscribe((transactions) => { - this.transactionsDataSource = new MatTableDataSource(transactions); - this.transactionsDataSource.paginator = this.transactionTablePaginator; - this.transactionsDataSource.sort = this.transactionTableSort; - this.transactions = transactions; - }); - } - doTransactionFilter(value: string): void { this.transactionsDataSource.filter = value.trim().toLocaleLowerCase(); }