From 6efa247934edb4c4b4656e942a846c534779dbb0 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 21 Jul 2021 15:37:15 +0300 Subject: [PATCH] Add metadata history datatable. --- src/app/_services/user.service.ts | 16 +++++- .../account-details.component.html | 52 +++++++++++++++++++ .../account-details.component.ts | 27 +++++++++- 3 files changed, 93 insertions(+), 2 deletions(-) diff --git a/src/app/_services/user.service.ts b/src/app/_services/user.service.ts index f8f258f..c065f23 100644 --- a/src/app/_services/user.service.ts +++ b/src/app/_services/user.service.ts @@ -13,6 +13,7 @@ import { CICRegistry } from '@cicnet/cic-client'; import { personValidation, updateSyncable, vcardValidation } from '@app/_helpers'; import { add0x } from '@src/assets/js/ethtx/dist/hex'; import { KeystoreService } from '@app/_services/keystore.service'; +import * as Automerge from 'automerge'; const vCard = require('vcard-parser'); @Injectable({ @@ -38,6 +39,10 @@ export class UserService { private categoriesList: BehaviorSubject = new BehaviorSubject(this.categories); categoriesSubject: Observable = this.categoriesList.asObservable(); + history: Array = []; + private historyList: BehaviorSubject = new BehaviorSubject(this.history); + historySubject: Observable> = this.historyList.asObservable(); + constructor( private httpClient: HttpClient, private loggingService: LoggingService, @@ -234,13 +239,22 @@ export class UserService { async getAccountByAddress( accountAddress: string, - limit: number = 100 + limit: number = 100, + history: boolean = false ): Promise> { const accountSubject: Subject = new Subject(); this.getAccountDetailsFromMeta(await User.toKey(add0x(accountAddress))) .pipe(first()) .subscribe(async (res) => { const account: Syncable = Envelope.fromJSON(JSON.stringify(res)).unwrap(); + if (history) { + try { + // @ts-ignore + this.historyList.next(Automerge.getHistory(account.m)); + } catch (error) { + this.loggingService.sendErrorLevelMessage('No history found', this, { error }); + } + } const accountInfo = account.m.data; await personValidation(accountInfo); this.tokenService.load.subscribe(async (status: boolean) => { 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 672da8a..bfc9b1e 100644 --- a/src/app/pages/accounts/account-details/account-details.component.html +++ b/src/app/pages/accounts/account-details/account-details.component.html @@ -333,6 +333,58 @@ +
+ HISTORY +
+
+

Loading History!

+ +
+ + + + + + + + + + + + + + + + + + + +
Actor + {{ history?.change.actor }} + Message + {{ history?.change.message }} + Sequence + {{ history?.change.seq }} +
+ + +
+
+ ; + historyDisplayedColumns: Array = ['actor', 'message', 'sequence']; + historyDefaultPageSize: number = 10; + historyPageSizeOptions: Array = [10, 20, 50, 100]; + @ViewChild('HistoryTablePaginator', { static: true }) historyPaginator: MatPaginator; + @ViewChild('HistoryTableSort', { static: true }) historyTableSort: MatSort; + accountInfoForm: FormGroup; account: AccountDetails; accountAddress: string; @@ -71,6 +78,8 @@ export class AccountDetailsComponent implements OnInit, AfterViewInit { areaType: string; accountsLoading: boolean = true; transactionsLoading: boolean = true; + history: Array = []; + historyLoading: boolean = true; constructor( private formBuilder: FormBuilder, @@ -109,7 +118,7 @@ export class AccountDetailsComponent implements OnInit, AfterViewInit { this.transactionService.resetTransactionsList(); await this.blockSyncService.blockSync(this.accountAddress); this.userService.resetAccountsList(); - (await this.userService.getAccountByAddress(this.accountAddress, 100)).subscribe( + (await this.userService.getAccountByAddress(this.accountAddress, 100, true)).subscribe( async (res) => { if (res !== undefined) { this.account = res; @@ -173,6 +182,18 @@ export class AccountDetailsComponent implements OnInit, AfterViewInit { } this.cdr.detectChanges(); }); + + this.userService.historySubject.subscribe((history) => { + this.historyDataSource = new MatTableDataSource(history); + this.historyDataSource.paginator = this.historyPaginator; + this.historyDataSource.sort = this.historyTableSort; + this.history = history; + if (history.length > 0) { + this.historyLoading = false; + } + this.cdr.detectChanges(); + }); + this.userService.getCategories(); this.userService.categoriesSubject.subscribe((res) => { this.categories = Object.keys(res); @@ -213,6 +234,10 @@ export class AccountDetailsComponent implements OnInit, AfterViewInit { this.transactionsDataSource.paginator = this.transactionTablePaginator; this.transactionsDataSource.sort = this.transactionTableSort; } + if (this.historyDataSource) { + this.historyDataSource.paginator = this.historyPaginator; + this.historyDataSource.sort = this.historyTableSort; + } } doTransactionFilter(value: string): void {