diff --git a/src/app/_helpers/accountIndex.ts b/src/app/_helpers/accountIndex.ts index 112d5e2..72df009 100644 --- a/src/app/_helpers/accountIndex.ts +++ b/src/app/_helpers/accountIndex.ts @@ -1,10 +1,9 @@ // @ts-ignore -import * as accountIndex from '@src/assets/json/accountIndex.abi.json'; +import * as accountIndex from '@src/assets/js/block-sync/data/AccountRegistry.json'; import {environment} from '@src/environments/environment'; const Web3 = require('web3'); const web3 = new Web3(environment.web3Provider); -// @ts-ignore const abi = accountIndex.default; export class AccountIndex { diff --git a/src/app/_helpers/index.ts b/src/app/_helpers/index.ts index c071fe8..6339460 100644 --- a/src/app/_helpers/index.ts +++ b/src/app/_helpers/index.ts @@ -7,3 +7,4 @@ export * from '@app/_helpers/array-sum'; export * from '@app/_helpers/accountIndex'; export * from '@app/_helpers/http-getter'; export * from '@app/_helpers/pgp-signer'; +export * from '@app/_helpers/registry'; diff --git a/src/app/_helpers/registry.spec.ts b/src/app/_helpers/registry.spec.ts new file mode 100644 index 0000000..e75820c --- /dev/null +++ b/src/app/_helpers/registry.spec.ts @@ -0,0 +1,7 @@ +import { Registry } from './registry'; + +describe('Registry', () => { + it('should create an instance', () => { + expect(new Registry()).toBeTruthy(); + }); +}); diff --git a/src/app/_helpers/registry.ts b/src/app/_helpers/registry.ts new file mode 100644 index 0000000..451506e --- /dev/null +++ b/src/app/_helpers/registry.ts @@ -0,0 +1,32 @@ +// @ts-ignore +import * as registry from '@src/assets/js/block-sync/data/Registry.json'; +import {environment} from '@src/environments/environment'; +const Web3 = require('web3'); + +const web3 = new Web3(environment.web3Provider); +const abi = registry.default; + +export class Registry { + contractAddress: string; + signerAddress: string; + contract: any; + + constructor(contractAddress: string, signerAddress?: string) { + this.contractAddress = contractAddress; + this.contract = new web3.eth.Contract(abi, contractAddress); + if (signerAddress) { + this.signerAddress = signerAddress; + } else { + this.signerAddress = web3.eth.accounts[0]; + } + } + + public async owner(): Promise { + return await this.contract.methods.owner().call(); + } + + public async addressOf(identifier: string): Promise { + const id = '0x' + web3.utils.padRight(new Buffer(identifier).toString('hex'), 64); + return await this.contract.methods.addressOf(id).call(); + } +} diff --git a/src/app/_models/account.ts b/src/app/_models/account.ts index dadca5a..7e6eb06 100644 --- a/src/app/_models/account.ts +++ b/src/app/_models/account.ts @@ -5,7 +5,9 @@ export interface AccountDetails { evm: { 'bloxberg:8996': string[]; 'oldchain:1': string[]; - } + }; + latitude: number; + longitude: number; }; location: { area_name: string; diff --git a/src/app/_services/transaction.service.ts b/src/app/_services/transaction.service.ts index c3e08f6..39f62e9 100644 --- a/src/app/_services/transaction.service.ts +++ b/src/app/_services/transaction.service.ts @@ -5,7 +5,6 @@ import {BehaviorSubject, Observable} from 'rxjs'; import {environment} from '@src/environments/environment'; import {Envelope, User} from 'cic-client-meta'; import {UserService} from '@app/_services/user.service'; -import { AccountIndex } from '@app/_helpers'; import { Keccak } from 'sha3'; import { utils } from 'ethers'; import {add0x, fromHex, strip0x, toHex} from '@src/assets/js/ethtx/dist/hex'; @@ -13,6 +12,7 @@ import {Tx} from '@src/assets/js/ethtx/dist'; import {toValue} from '@src/assets/js/ethtx/dist/tx'; import * as secp256k1 from 'secp256k1'; import {AuthService} from '@app/_services/auth.service'; +import {Registry} from '@app/_helpers'; const Web3 = require('web3'); const vCard = require('vcard-parser'); @@ -24,8 +24,8 @@ export class TransactionService { private transactionList = new BehaviorSubject(this.transactions); transactionsSubject = this.transactionList.asObservable(); userInfo: any; - request = new AccountIndex(environment.contractAddress); web3 = new Web3(environment.web3Provider); + registry = new Registry(environment.registryAddress); constructor( private http: HttpClient, @@ -83,6 +83,7 @@ export class TransactionService { } async transferRequest(tokenAddress: string, senderAddress: string, recipientAddress: string, value: number): Promise { + const transferAuthAddress = await this.registry.addressOf('TransferAuthorization'); const hashFunction = new Keccak(256); hashFunction.update('createRequest(address,address,address,uint256)'); const hash = hashFunction.digest(); @@ -94,7 +95,7 @@ export class TransactionService { tx.nonce = await this.web3.eth.getTransactionCount(senderAddress); tx.gasPrice = await this.web3.eth.getGasPrice(); tx.gasLimit = 8000000; - tx.to = fromHex(strip0x(recipientAddress)); + tx.to = fromHex(strip0x(transferAuthAddress)); tx.value = toValue(value); tx.data = data; const txMsg = tx.message(); diff --git a/src/app/_services/user.service.ts b/src/app/_services/user.service.ts index 889f80e..f786db8 100644 --- a/src/app/_services/user.service.ts +++ b/src/app/_services/user.service.ts @@ -3,7 +3,7 @@ import {BehaviorSubject, Observable} from 'rxjs'; import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http'; import {environment} from '@src/environments/environment'; import {first} from 'rxjs/operators'; -import {AccountIndex, MutableKeyStore, MutablePgpKeyStore, PGPSigner, Signer} from '@app/_helpers'; +import {AccountIndex, MutableKeyStore, MutablePgpKeyStore, PGPSigner, Registry, Signer} from '@app/_helpers'; import {ArgPair, Envelope, Syncable, User} from 'cic-client-meta'; const vCard = require('vcard-parser'); @@ -14,7 +14,7 @@ export class UserService { headers: HttpHeaders = new HttpHeaders({'x-cic-automerge': 'client'}); keystore: MutableKeyStore = new MutablePgpKeyStore(); signer: Signer = new PGPSigner(this.keystore); - accountIndexQuery = new AccountIndex(environment.contractAddress); + registry = new Registry(environment.registryAddress); accountsMeta = []; accounts: any = []; @@ -29,7 +29,8 @@ export class UserService { private staffList = new BehaviorSubject(this.staff); staffSubject = this.staffList.asObservable(); - constructor(private http: HttpClient) { } + constructor(private http: HttpClient) { + } resetPin(phone: string): Observable { const params = new HttpParams().set('phoneNumber', phone); @@ -153,7 +154,10 @@ export class UserService { } async loadAccounts(limit: number, offset: number = 0): Promise { - const accountAddresses = await this.accountIndexQuery.last(await this.accountIndexQuery.totalAccounts()); + const accountIndexAddress = await this.registry.addressOf('AccountRegistry'); + const accountIndexQuery = new AccountIndex(accountIndexAddress); + const accountAddresses = await accountIndexQuery.last(await accountIndexQuery.totalAccounts()); + console.log(accountAddresses); for (const accountAddress of accountAddresses.slice(offset, offset + limit)) { this.getAccountDetailsFromMeta(await User.toKey(accountAddress)).pipe(first()).subscribe(res => { const account = Envelope.fromJSON(JSON.stringify(res)).unwrap(); 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 c2d1179..d210d4e 100644 --- a/src/app/pages/accounts/account-details/account-details.component.html +++ b/src/app/pages/accounts/account-details/account-details.component.html @@ -9,22 +9,22 @@
-
+

- {{account?.name}} + {{account?.fn[0].value}}

Balance: {{account?.balance}} RCU - Created: {{account?.created}} - Address: {{account?.address}} + Created: {{account?.date_registered | date}} +
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 c7d12c2..c15093d 100644 --- a/src/app/pages/accounts/account-details/account-details.component.ts +++ b/src/app/pages/accounts/account-details/account-details.component.ts @@ -9,6 +9,7 @@ import {first} from 'rxjs/operators'; import {FormBuilder, FormGroup, Validators} from '@angular/forms'; import {CustomErrorStateMatcher} from '@app/_helpers'; import {Envelope, User} from 'cic-client-meta'; +const vCard = require('vcard-parser'); @Component({ selector: 'app-account-details', @@ -74,49 +75,30 @@ export class AccountDetailsComponent implements OnInit { locationType: ['', Validators.required], referrer: ['', Validators.required] }); - this.route.paramMap.subscribe((params: Params) => { - this.userService.getAccountById(params.get('id')).pipe(first()).subscribe(async account => { - this.account = account; - this.userService.getAccountDetailsFromMeta(await User.toKey(account.address)).pipe(first()).subscribe(res => { - this.metaAccount = Envelope.fromJSON(JSON.stringify(res)).unwrap(); - const accountInfo = this.metaAccount.m.data; - console.log(accountInfo); - this.accountInfoForm.patchValue({ - status: accountInfo.status, - name: accountInfo.name, - phoneNumber: accountInfo.phoneNumber, - age: accountInfo.age, - type: accountInfo.type, - token: accountInfo.token, - failedPinAttempts: accountInfo.failedPinAttempts, - bio: accountInfo.bio, - gender: accountInfo.gender, - businessCategory: accountInfo.businessCategory, - userLocation: accountInfo.userLocation, - location: accountInfo.location, - locationType: accountInfo.locationType, - referrer: accountInfo.referrer - }); - }, error => { - this.accountInfoForm.patchValue({ - status: account.status, - name: account.name, - phoneNumber: account.phone, - age: account.age, - type: account.type, - token: account.token, - failedPinAttempts: account.failedPinAttempts, - bio: account.bio, - gender: account.gender, - businessCategory: account.category, - userLocation: account.userLocation, - location: account.location, - locationType: account.locationType, - referrer: account.referrer - }); + this.route.paramMap.subscribe(async (params: Params) => { + this.userService.getAccountDetailsFromMeta(await User.toKey(params.get('id'))).pipe(first()).subscribe(res => { + this.metaAccount = Envelope.fromJSON(JSON.stringify(res)).unwrap(); + this.account = this.metaAccount.m.data; + this.account.vcard = vCard.parse(atob(this.account.vcard)); + console.log(this.account); + this.accountInfoForm.patchValue({ + status: this.account.status, + name: this.account.vcard?.fn[0].value, + phoneNumber: this.account.vcard?.tel[0].value, + age: this.account.age, + type: this.account.type, + token: this.account.token, + failedPinAttempts: this.account.failedPinAttempts, + bio: this.account.bio, + gender: this.account.gender, + businessCategory: this.account.businessCategory, + userLocation: this.account.location.area_name, + location: this.account.location, + locationType: this.account.locationType, + referrer: this.account.referrer }); - this.bloxbergLink = 'https://blockexplorer.bloxberg.org/address/' + this.account.address + '/transactions'; - this.userService.getHistoryByUser(this.account?.id).pipe(first()).subscribe(history => { + this.bloxbergLink = 'https://blockexplorer.bloxberg.org/address/' + this.account.identities.evm['bloxberg:8996'] + '/transactions'; + this.userService.getHistoryByUser(params.get('id')).pipe(first()).subscribe(history => { this.historyDataSource = new MatTableDataSource(history); this.historyDataSource.paginator = this.historyTablePaginator; this.historyDataSource.sort = this.historyTableSort; diff --git a/src/app/pages/accounts/accounts.component.ts b/src/app/pages/accounts/accounts.component.ts index 91629b4..58efad0 100644 --- a/src/app/pages/accounts/accounts.component.ts +++ b/src/app/pages/accounts/accounts.component.ts @@ -55,7 +55,7 @@ export class AccountsComponent implements OnInit { } viewAccount(account): void { - this.router.navigateByUrl(`/accounts/${account.id}`).then(); + this.router.navigateByUrl(`/accounts/${account.identities.evm['bloxberg:8996']}`).then(); } approveAccount(): void { diff --git a/src/assets/json/accountIndex.abi.json b/src/assets/json/accountIndex.abi.json deleted file mode 100644 index 28e6b51..0000000 --- a/src/assets/json/accountIndex.abi.json +++ /dev/null @@ -1,153 +0,0 @@ -[ - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "addedAccount", - "type": "address" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "accountIndex", - "type": "uint256" - } - ], - "name": "AccountAdded", - "type": "event" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_account", - "type": "address" - } - ], - "name": "add", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_writer", - "type": "address" - } - ], - "name": "addWriter", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_writer", - "type": "address" - } - ], - "name": "deleteWriter", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "accounts", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "accountsIndex", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "count", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_account", - "type": "address" - } - ], - "name": "have", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - } -] diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 0511dda..5970095 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -9,8 +9,6 @@ export const environment = { web3Provider: 'ws://localhost:63546', cicUssdUrl: 'http://localhost:63315', cicEthUrl: 'http://localhost:63314', - contractAddress: '0xd0097a901AF4ac2E63A5b6E86be8Ad91f10b05d7', registryAddress: '0xf374d7B507767101a4bf3bA2a6B99AC737A44f6d', - trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C', - transferAuthorizationAddress: '0xB542fd8bCb777f058997b7D8D06381A0571BF224' + trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C' }; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 69fea52..002aedd 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -13,10 +13,8 @@ export const environment = { web3Provider: 'ws://localhost:63546', cicUssdUrl: 'http://localhost:63315', cicEthUrl: 'http://localhost:63314', - contractAddress: '0xd0097a901AF4ac2E63A5b6E86be8Ad91f10b05d7', registryAddress: '0xf374d7B507767101a4bf3bA2a6B99AC737A44f6d', - trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C', - transferAuthorizationAddress: '0xB542fd8bCb777f058997b7D8D06381A0571BF224' + trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C' }; /*