From 9e03990334de1fc2664a376c1be929bb53fc3376 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 28 Apr 2021 12:09:51 +0300 Subject: [PATCH] Refactor account details page to use address with stripped 0x. --- src/app/_services/user.service.ts | 7 ++++--- .../account-details/account-details.component.ts | 5 +++-- .../accounts/account-search/account-search.component.ts | 6 ++++-- src/app/pages/accounts/accounts.component.ts | 3 ++- .../transaction-details/transaction-details.component.ts | 9 +++++---- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/app/_services/user.service.ts b/src/app/_services/user.service.ts index 0f88a80..f064776 100644 --- a/src/app/_services/user.service.ts +++ b/src/app/_services/user.service.ts @@ -11,8 +11,9 @@ import {AccountIndex} from '@app/_eth'; import {MutableKeyStore, PGPSigner, Signer} from '@app/_pgp'; import {RegistryService} from '@app/_services/registry.service'; import {CICRegistry} from 'cic-client'; -import {AuthService} from './auth.service'; +import {AuthService} from '@app/_services/auth.service'; import {personValidation, vcardValidation} from '@app/_helpers'; +import {add0x} from '@src/assets/js/ethtx/dist/hex'; const vCard = require('vcard-parser'); @Injectable({ @@ -182,7 +183,7 @@ export class UserService { async getAccountByAddress(accountAddress: string, limit: number = 100): Promise> { let accountSubject = new Subject(); - this.getAccountDetailsFromMeta(await User.toKey(accountAddress)).pipe(first()).subscribe(async res => { + this.getAccountDetailsFromMeta(await User.toKey(add0x(accountAddress))).pipe(first()).subscribe(async res => { const account = Envelope.fromJSON(JSON.stringify(res)).unwrap(); this.accountsMeta.push(account); const accountInfo = account.m.data; @@ -204,7 +205,7 @@ export class UserService { let accountSubject = new Subject(); this.getAccountDetailsFromMeta(await Phone.toKey(phoneNumber)).pipe(first()).subscribe(async res => { const response = Envelope.fromJSON(JSON.stringify(res)).unwrap(); - const address = '0x' + response.m.data; + const address = response.m.data; const account = await this.getAccountByAddress(address, limit); account.subscribe(result => { accountSubject.next(result); 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 2d667ff..8f39912 100644 --- a/src/app/pages/accounts/account-details/account-details.component.ts +++ b/src/app/pages/accounts/account-details/account-details.component.ts @@ -8,6 +8,7 @@ import {first} from 'rxjs/operators'; import {FormBuilder, FormGroup, Validators} from '@angular/forms'; import {copyToClipboard, CustomErrorStateMatcher, exportCsv} from '@app/_helpers'; import {MatSnackBar} from '@angular/material/snack-bar'; +import {add0x, strip0x} from '@src/assets/js/ethtx/dist/hex'; @Component({ selector: 'app-account-details', @@ -70,7 +71,7 @@ export class AccountDetailsComponent implements OnInit { locationType: ['', Validators.required], }); this.route.paramMap.subscribe(async (params: Params) => { - this.accountAddress = params.get('id'); + 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) { @@ -132,7 +133,7 @@ export class AccountDetailsComponent implements OnInit { } viewAccount(account): void { - this.router.navigateByUrl(`/accounts/${account.id}`); + this.router.navigateByUrl(`/accounts/${strip0x(account.identities.evm['bloxberg:8996'][0])}`); } get accountInfoFormStub(): any { return this.accountInfoForm.controls; } diff --git a/src/app/pages/accounts/account-search/account-search.component.ts b/src/app/pages/accounts/account-search/account-search.component.ts index 48d1b10..6d5a981 100644 --- a/src/app/pages/accounts/account-search/account-search.component.ts +++ b/src/app/pages/accounts/account-search/account-search.component.ts @@ -3,6 +3,7 @@ import {FormBuilder, FormGroup, Validators} from '@angular/forms'; import {CustomErrorStateMatcher} from '@app/_helpers'; import {UserService} from '@app/_services'; import {Router} from '@angular/router'; +import {strip0x} from '@src/assets/js/ethtx/dist/hex'; @Component({ selector: 'app-account-search', @@ -57,8 +58,9 @@ export class AccountSearchComponent implements OnInit { if (this.phoneSearchForm.invalid) { return; } this.phoneSearchLoading = true; (await this.userService.getAccountByPhone(this.phoneSearchFormStub.phoneNumber.value, 100)).subscribe(async res => { + console.log(res); if (res !== undefined) { - await this.router.navigateByUrl(`/accounts/${res.identities.evm['bloxberg:8996']}`); + await this.router.navigateByUrl(`/accounts/${strip0x(res.identities.evm['bloxberg:8996'][0])}`); } else { alert('Account not found!'); } @@ -72,7 +74,7 @@ export class AccountSearchComponent implements OnInit { this.addressSearchLoading = true; (await this.userService.getAccountByAddress(this.addressSearchFormStub.address.value, 100)).subscribe(async res => { if (res !== undefined) { - await this.router.navigateByUrl(`/accounts/${res.identities.evm['bloxberg:8996']}`); + await this.router.navigateByUrl(`/accounts/${strip0x(res.identities.evm['bloxberg:8996'][0])}`); } else { alert('Account not found!'); } diff --git a/src/app/pages/accounts/accounts.component.ts b/src/app/pages/accounts/accounts.component.ts index 007152c..b317bfa 100644 --- a/src/app/pages/accounts/accounts.component.ts +++ b/src/app/pages/accounts/accounts.component.ts @@ -5,6 +5,7 @@ import {MatSort} from '@angular/material/sort'; import {LoggingService, UserService} from '@app/_services'; import {Router} from '@angular/router'; import {exportCsv} from '@app/_helpers'; +import {strip0x} from '@src/assets/js/ethtx/dist/hex'; @Component({ selector: 'app-accounts', @@ -51,7 +52,7 @@ export class AccountsComponent implements OnInit { } async viewAccount(account): Promise { - await this.router.navigateByUrl(`/accounts/${account.identities.evm['bloxberg:8996']}`); + await this.router.navigateByUrl(`/accounts/${strip0x(account.identities.evm['bloxberg:8996'][0])}`); } filterAccounts(): void { 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 a676399..dd4f23a 100644 --- a/src/app/pages/transactions/transaction-details/transaction-details.component.ts +++ b/src/app/pages/transactions/transaction-details/transaction-details.component.ts @@ -1,8 +1,9 @@ import {ChangeDetectionStrategy, Component, Input, OnInit} from '@angular/core'; import {Router} from '@angular/router'; import {TransactionService} from '@app/_services'; -import {copyToClipboard} from '../../../_helpers'; +import {copyToClipboard} from '@app/_helpers'; import {MatSnackBar} from '@angular/material/snack-bar'; +import {strip0x} from '@src/assets/js/ethtx/dist/hex'; @Component({ selector: 'app-transaction-details', @@ -32,15 +33,15 @@ export class TransactionDetailsComponent implements OnInit { } async viewSender(): Promise { - await this.router.navigateByUrl(`/accounts/${this.transaction.from}`); + await this.router.navigateByUrl(`/accounts/${strip0x(this.transaction.from)}`); } async viewRecipient(): Promise { - await this.router.navigateByUrl(`/accounts/${this.transaction.to}`); + await this.router.navigateByUrl(`/accounts/${strip0x(this.transaction.to)}`); } async viewTrader(): Promise { - await this.router.navigateByUrl(`/accounts/${this.transaction.trader}`); + await this.router.navigateByUrl(`/accounts/${strip0x(this.transaction.trader)}`); } async reverseTransaction(): Promise {