Refactor account details page to use address with stripped 0x.

This commit is contained in:
Spencer Ofwiti 2021-04-28 12:09:51 +03:00
parent 4167a7e6b7
commit 9e03990334
5 changed files with 18 additions and 12 deletions

View File

@ -11,8 +11,9 @@ import {AccountIndex} from '@app/_eth';
import {MutableKeyStore, PGPSigner, Signer} from '@app/_pgp'; import {MutableKeyStore, PGPSigner, Signer} from '@app/_pgp';
import {RegistryService} from '@app/_services/registry.service'; import {RegistryService} from '@app/_services/registry.service';
import {CICRegistry} from 'cic-client'; import {CICRegistry} from 'cic-client';
import {AuthService} from './auth.service'; import {AuthService} from '@app/_services/auth.service';
import {personValidation, vcardValidation} from '@app/_helpers'; import {personValidation, vcardValidation} from '@app/_helpers';
import {add0x} from '@src/assets/js/ethtx/dist/hex';
const vCard = require('vcard-parser'); const vCard = require('vcard-parser');
@Injectable({ @Injectable({
@ -182,7 +183,7 @@ export class UserService {
async getAccountByAddress(accountAddress: string, limit: number = 100): Promise<Observable<AccountDetails>> { async getAccountByAddress(accountAddress: string, limit: number = 100): Promise<Observable<AccountDetails>> {
let accountSubject = new Subject<any>(); let accountSubject = new Subject<any>();
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(); const account = Envelope.fromJSON(JSON.stringify(res)).unwrap();
this.accountsMeta.push(account); this.accountsMeta.push(account);
const accountInfo = account.m.data; const accountInfo = account.m.data;
@ -204,7 +205,7 @@ export class UserService {
let accountSubject = new Subject<any>(); let accountSubject = new Subject<any>();
this.getAccountDetailsFromMeta(await Phone.toKey(phoneNumber)).pipe(first()).subscribe(async res => { this.getAccountDetailsFromMeta(await Phone.toKey(phoneNumber)).pipe(first()).subscribe(async res => {
const response = Envelope.fromJSON(JSON.stringify(res)).unwrap(); 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); const account = await this.getAccountByAddress(address, limit);
account.subscribe(result => { account.subscribe(result => {
accountSubject.next(result); accountSubject.next(result);

View File

@ -8,6 +8,7 @@ import {first} from 'rxjs/operators';
import {FormBuilder, FormGroup, Validators} from '@angular/forms'; import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {copyToClipboard, CustomErrorStateMatcher, exportCsv} from '@app/_helpers'; import {copyToClipboard, CustomErrorStateMatcher, exportCsv} from '@app/_helpers';
import {MatSnackBar} from '@angular/material/snack-bar'; import {MatSnackBar} from '@angular/material/snack-bar';
import {add0x, strip0x} from '@src/assets/js/ethtx/dist/hex';
@Component({ @Component({
selector: 'app-account-details', selector: 'app-account-details',
@ -70,7 +71,7 @@ export class AccountDetailsComponent implements OnInit {
locationType: ['', Validators.required], locationType: ['', Validators.required],
}); });
this.route.paramMap.subscribe(async (params: Params) => { 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'; this.bloxbergLink = 'https://blockexplorer.bloxberg.org/address/' + this.accountAddress + '/transactions';
(await this.userService.getAccountByAddress(this.accountAddress, 100)).subscribe(async res => { (await this.userService.getAccountByAddress(this.accountAddress, 100)).subscribe(async res => {
if (res !== undefined) { if (res !== undefined) {
@ -132,7 +133,7 @@ export class AccountDetailsComponent implements OnInit {
} }
viewAccount(account): void { 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; } get accountInfoFormStub(): any { return this.accountInfoForm.controls; }

View File

@ -3,6 +3,7 @@ import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {CustomErrorStateMatcher} from '@app/_helpers'; import {CustomErrorStateMatcher} from '@app/_helpers';
import {UserService} from '@app/_services'; import {UserService} from '@app/_services';
import {Router} from '@angular/router'; import {Router} from '@angular/router';
import {strip0x} from '@src/assets/js/ethtx/dist/hex';
@Component({ @Component({
selector: 'app-account-search', selector: 'app-account-search',
@ -57,8 +58,9 @@ export class AccountSearchComponent implements OnInit {
if (this.phoneSearchForm.invalid) { return; } if (this.phoneSearchForm.invalid) { return; }
this.phoneSearchLoading = true; this.phoneSearchLoading = true;
(await this.userService.getAccountByPhone(this.phoneSearchFormStub.phoneNumber.value, 100)).subscribe(async res => { (await this.userService.getAccountByPhone(this.phoneSearchFormStub.phoneNumber.value, 100)).subscribe(async res => {
console.log(res);
if (res !== undefined) { 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 { } else {
alert('Account not found!'); alert('Account not found!');
} }
@ -72,7 +74,7 @@ export class AccountSearchComponent implements OnInit {
this.addressSearchLoading = true; this.addressSearchLoading = true;
(await this.userService.getAccountByAddress(this.addressSearchFormStub.address.value, 100)).subscribe(async res => { (await this.userService.getAccountByAddress(this.addressSearchFormStub.address.value, 100)).subscribe(async res => {
if (res !== undefined) { 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 { } else {
alert('Account not found!'); alert('Account not found!');
} }

View File

@ -5,6 +5,7 @@ import {MatSort} from '@angular/material/sort';
import {LoggingService, UserService} from '@app/_services'; import {LoggingService, UserService} from '@app/_services';
import {Router} from '@angular/router'; import {Router} from '@angular/router';
import {exportCsv} from '@app/_helpers'; import {exportCsv} from '@app/_helpers';
import {strip0x} from '@src/assets/js/ethtx/dist/hex';
@Component({ @Component({
selector: 'app-accounts', selector: 'app-accounts',
@ -51,7 +52,7 @@ export class AccountsComponent implements OnInit {
} }
async viewAccount(account): Promise<void> { async viewAccount(account): Promise<void> {
await this.router.navigateByUrl(`/accounts/${account.identities.evm['bloxberg:8996']}`); await this.router.navigateByUrl(`/accounts/${strip0x(account.identities.evm['bloxberg:8996'][0])}`);
} }
filterAccounts(): void { filterAccounts(): void {

View File

@ -1,8 +1,9 @@
import {ChangeDetectionStrategy, Component, Input, OnInit} from '@angular/core'; import {ChangeDetectionStrategy, Component, Input, OnInit} from '@angular/core';
import {Router} from '@angular/router'; import {Router} from '@angular/router';
import {TransactionService} from '@app/_services'; import {TransactionService} from '@app/_services';
import {copyToClipboard} from '../../../_helpers'; import {copyToClipboard} from '@app/_helpers';
import {MatSnackBar} from '@angular/material/snack-bar'; import {MatSnackBar} from '@angular/material/snack-bar';
import {strip0x} from '@src/assets/js/ethtx/dist/hex';
@Component({ @Component({
selector: 'app-transaction-details', selector: 'app-transaction-details',
@ -32,15 +33,15 @@ export class TransactionDetailsComponent implements OnInit {
} }
async viewSender(): Promise<void> { async viewSender(): Promise<void> {
await this.router.navigateByUrl(`/accounts/${this.transaction.from}`); await this.router.navigateByUrl(`/accounts/${strip0x(this.transaction.from)}`);
} }
async viewRecipient(): Promise<void> { async viewRecipient(): Promise<void> {
await this.router.navigateByUrl(`/accounts/${this.transaction.to}`); await this.router.navigateByUrl(`/accounts/${strip0x(this.transaction.to)}`);
} }
async viewTrader(): Promise<void> { async viewTrader(): Promise<void> {
await this.router.navigateByUrl(`/accounts/${this.transaction.trader}`); await this.router.navigateByUrl(`/accounts/${strip0x(this.transaction.trader)}`);
} }
async reverseTransaction(): Promise<void> { async reverseTransaction(): Promise<void> {