diff --git a/src/app/_services/user.service.ts b/src/app/_services/user.service.ts index fdbf300..6b85554 100644 --- a/src/app/_services/user.service.ts +++ b/src/app/_services/user.service.ts @@ -1,10 +1,10 @@ import {Injectable} from '@angular/core'; -import {BehaviorSubject, Observable} from 'rxjs'; +import {BehaviorSubject, Observable, of, Subject} from 'rxjs'; import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http'; import {environment} from '@src/environments/environment'; import {first} from 'rxjs/operators'; -import {ArgPair, Envelope, Syncable, User} from 'cic-client-meta'; -import {MetaResponse} from '@app/_models'; +import {ArgPair, Envelope, Phone, Syncable, User} from 'cic-client-meta'; +import {AccountDetails, MetaResponse} from '@app/_models'; import {LoggingService} from '@app/_services/logging.service'; import {TokenService} from '@app/_services/token.service'; import {AccountIndex, Registry} from '@app/_eth'; @@ -157,21 +157,35 @@ export class UserService { const accountAddresses = await accountIndexQuery.last(await accountIndexQuery.totalAccounts()); this.loggingService.sendInfoLevelMessage(accountAddresses); for (const accountAddress of accountAddresses.slice(offset, offset + limit)) { - this.getAccountDetailsFromMeta(await User.toKey(accountAddress)).pipe(first()).subscribe(async res => { - const account = Envelope.fromJSON(JSON.stringify(res)).unwrap(); - this.accountsMeta.push(account); - const accountInfo = account.m.data; - accountInfo.balance = await this.tokenService.getTokenBalance(accountInfo.identities.evm['bloxberg:8996'][0]); - accountInfo.vcard = vCard.parse(atob(accountInfo.vcard)); - this.accounts.unshift(accountInfo); - if (this.accounts.length > limit) { - this.accounts.length = limit; - } - this.accountsList.next(this.accounts); - }); + await this.getAccountByAddress(accountAddress, limit); } } + async getAccountByAddress(accountAddress: string, limit: number = 100): Promise> { + let accountSubject = new Subject(); + this.getAccountDetailsFromMeta(await User.toKey(accountAddress)).pipe(first()).subscribe(async res => { + const account = Envelope.fromJSON(JSON.stringify(res)).unwrap(); + this.accountsMeta.push(account); + const accountInfo = account.m.data; + accountInfo.balance = await this.tokenService.getTokenBalance(accountInfo.identities.evm['bloxberg:8996'][0]); + accountInfo.vcard = vCard.parse(atob(accountInfo.vcard)); + this.accounts.unshift(accountInfo); + if (this.accounts.length > limit) { + this.accounts.length = limit; + } + this.accountsList.next(this.accounts); + accountSubject.next(accountInfo); + console.log(accountInfo); + }); + return accountSubject.asObservable(); + } + + async getAccountByPhone(phoneNumber: string): Promise { + this.getAccountDetailsFromMeta(await Phone.toKey(Number(phoneNumber))).pipe(first()).subscribe(res => { + console.log(res); + }); + } + resetAccountsList(): void { this.accounts = []; this.accountsList.next(this.accounts); @@ -180,6 +194,4 @@ export class UserService { searchAccountByName(name: string): any { return; } searchAccountByPhone(phoneNumber: string): any { return; } - - searchAccountByAddress(address: string): any { return; } } diff --git a/src/app/pages/accounts/account-search/account-search.component.html b/src/app/pages/accounts/account-search/account-search.component.html index 88fd21a..56a17cc 100644 --- a/src/app/pages/accounts/account-search/account-search.component.html +++ b/src/app/pages/accounts/account-search/account-search.component.html @@ -23,18 +23,6 @@
- -
- - Search - - Name is required. - face - Name - - -
-
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 7b6accd..464debd 100644 --- a/src/app/pages/accounts/account-search/account-search.component.ts +++ b/src/app/pages/accounts/account-search/account-search.component.ts @@ -2,6 +2,7 @@ import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core'; import {FormBuilder, FormGroup, Validators} from '@angular/forms'; import {CustomErrorStateMatcher} from '@app/_helpers'; import {UserService} from '@app/_services'; +import {Router} from '@angular/router'; @Component({ selector: 'app-account-search', @@ -24,6 +25,7 @@ export class AccountSearchComponent implements OnInit { constructor( private formBuilder: FormBuilder, private userService: UserService, + private router: Router, ) { } ngOnInit(): void { @@ -50,19 +52,25 @@ export class AccountSearchComponent implements OnInit { this.nameSearchLoading = false; } - onPhoneSearch(): void { + async onPhoneSearch(): Promise { this.phoneSearchSubmitted = true; if (this.phoneSearchForm.invalid) { return; } this.phoneSearchLoading = true; - this.userService.searchAccountByPhone(this.phoneSearchFormStub.phoneNumber.value); + await this.userService.getAccountByPhone(this.phoneSearchFormStub.phoneNumber.value); this.phoneSearchLoading = false; } - onAddressSearch(): void { + async onAddressSearch(): Promise { this.addressSearchSubmitted = true; if (this.addressSearchForm.invalid) { return; } this.addressSearchLoading = true; - this.userService.searchAccountByAddress(this.addressSearchFormStub.address.value); + (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']}`); + } else { + alert('Account not found!'); + } + }); this.addressSearchLoading = false; } }