From 506be2eb5b290b162c36c70f9ee2fe359546dff3 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Tue, 18 May 2021 10:33:38 +0300 Subject: [PATCH 01/34] Add private key user info to settings page. --- src/app/_services/auth.service.ts | 4 ++++ src/app/pages/settings/settings.component.html | 7 ++++--- src/app/pages/settings/settings.component.ts | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/app/_services/auth.service.ts b/src/app/_services/auth.service.ts index d29bc43..3be119e 100644 --- a/src/app/_services/auth.service.ts +++ b/src/app/_services/auth.service.ts @@ -211,4 +211,8 @@ export class AuthService { getPrivateKey(): any { return this.mutableKeyStore.getPrivateKey(); } + + getPrivateKeyInfo(): any { + return this.getPrivateKey().users[0].userId; + } } diff --git a/src/app/pages/settings/settings.component.html b/src/app/pages/settings/settings.component.html index 9ed5869..b531bc7 100644 --- a/src/app/pages/settings/settings.component.html +++ b/src/app/pages/settings/settings.component.html @@ -23,9 +23,10 @@ SETTINGS
-

Kobo Toolbox Credentials

- Username: admin_reserve
- Password: ******** +

CICADA Admin Credentials

+ UserId: {{ userInfo.userid }}
+ Username: {{ userInfo.name }}
+ Email: {{ userInfo.email }}

diff --git a/src/app/pages/settings/settings.component.ts b/src/app/pages/settings/settings.component.ts index 4806258..b8ff67d 100644 --- a/src/app/pages/settings/settings.component.ts +++ b/src/app/pages/settings/settings.component.ts @@ -17,6 +17,7 @@ export class SettingsComponent implements OnInit { dataSource: MatTableDataSource; displayedColumns: Array = ['name', 'email', 'userId']; trustedUsers: Array; + userInfo: Staff; @ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatSort) sort: MatSort; @@ -30,6 +31,7 @@ export class SettingsComponent implements OnInit { this.dataSource = new MatTableDataSource(this.trustedUsers); this.dataSource.paginator = this.paginator; this.dataSource.sort = this.sort; + this.userInfo = this.authService.getPrivateKeyInfo(); } doFilter(value: string): void { From 08fda5390abd5f0fcb44d19e09d8c62e58a7a019 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Tue, 18 May 2021 10:38:19 +0300 Subject: [PATCH 02/34] Fix ABI query using http getter. --- src/app/_helpers/http-getter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/_helpers/http-getter.ts b/src/app/_helpers/http-getter.ts index 4c1719e..d4c253f 100644 --- a/src/app/_helpers/http-getter.ts +++ b/src/app/_helpers/http-getter.ts @@ -6,7 +6,7 @@ HttpGetter.prototype.get = (filename) => new Promise((resolve, reject) => { fetch(filename).then((response) => { if (response.ok) { - resolve(response.json()); + resolve(response.text()); } else { reject(rejectBody(response)); } From 405199cfe32dd89a71d953b314d9f0c1b997b0c4 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Tue, 18 May 2021 10:42:24 +0300 Subject: [PATCH 03/34] Refactor loop to avoid passing index limit. --- src/app/_eth/accountIndex.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/_eth/accountIndex.ts b/src/app/_eth/accountIndex.ts index bc861e8..564479f 100644 --- a/src/app/_eth/accountIndex.ts +++ b/src/app/_eth/accountIndex.ts @@ -34,7 +34,7 @@ export class AccountIndex { lowest = 0; } const accounts: Array = []; - for (let i = count; i > lowest; i--) { + for (let i = count - 1; i >= lowest; i--) { const account: string = await this.contract.methods.entry(i).call(); accounts.push(account); } From 8ae6436460027a8018d6ca173610ede03ce792e8 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Tue, 18 May 2021 12:38:27 +0300 Subject: [PATCH 04/34] Refactor registry service imports. --- src/app/_services/block-sync.service.ts | 8 +-- src/app/_services/registry.service.ts | 8 --- src/app/_services/token.service.ts | 3 +- src/app/_services/transaction.service.ts | 79 ++++++++++++------------ src/app/_services/user.service.ts | 28 +++++---- 5 files changed, 59 insertions(+), 67 deletions(-) diff --git a/src/app/_services/block-sync.service.ts b/src/app/_services/block-sync.service.ts index 9d0c32e..e532113 100644 --- a/src/app/_services/block-sync.service.ts +++ b/src/app/_services/block-sync.service.ts @@ -25,8 +25,8 @@ export class BlockSyncService { const settings: Settings = new Settings(this.scan); const readyStateElements: { network: number } = { network: 2 }; settings.w3.provider = environment.web3Provider; - settings.w3.engine = this.registryService.getWeb3(); - settings.registry = this.registryService.getRegistry(); + settings.w3.engine = this.registryService.web3; + settings.registry = this.registryService.registry; settings.txHelper = new TransactionHelper(settings.w3.engine, settings.registry); settings.txHelper.ontransfer = async (transaction: any): Promise => { @@ -35,12 +35,10 @@ export class BlockSyncService { settings.txHelper.onconversion = async (transaction: any): Promise => { window.dispatchEvent(this.newConversionEvent(transaction)); }; - settings.registry.onload = (addressReturned: number): void => { + settings.registry.onload = (addressReturned: string): void => { this.loggingService.sendInfoLevelMessage(`Loaded network contracts ${addressReturned}`); this.readyStateProcessor(settings, readyStateElements.network, address, offset, limit); }; - - settings.registry.load(); } readyStateProcessor( diff --git a/src/app/_services/registry.service.ts b/src/app/_services/registry.service.ts index 0600f5e..7e845ea 100644 --- a/src/app/_services/registry.service.ts +++ b/src/app/_services/registry.service.ts @@ -22,12 +22,4 @@ export class RegistryService { this.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress); this.registry.load(); } - - getRegistry(): any { - return this.registry; - } - - getWeb3(): any { - return this.web3; - } } diff --git a/src/app/_services/token.service.ts b/src/app/_services/token.service.ts index fd7072b..748361f 100644 --- a/src/app/_services/token.service.ts +++ b/src/app/_services/token.service.ts @@ -15,8 +15,7 @@ export class TokenService { LoadEvent: EventEmitter = new EventEmitter(); constructor(private httpClient: HttpClient, private registryService: RegistryService) { - this.registry = registryService.getRegistry(); - this.registry.load(); + this.registry = registryService.registry; this.registry.onload = async (address: string): Promise => { this.tokenRegistry = new TokenRegistry( await this.registry.getContractAddressByName('TokenRegistry') diff --git a/src/app/_services/transaction.service.ts b/src/app/_services/transaction.service.ts index d822354..94164ae 100644 --- a/src/app/_services/transaction.service.ts +++ b/src/app/_services/transaction.service.ts @@ -37,9 +37,8 @@ export class TransactionService { private loggingService: LoggingService, private registryService: RegistryService ) { - this.web3 = this.registryService.getWeb3(); - this.registry = registryService.getRegistry(); - this.registry.load(); + this.web3 = this.registryService.web3; + this.registry = registryService.registry; } getAllTransactions(offset: number, limit: number): Observable { @@ -133,41 +132,43 @@ export class TransactionService { recipientAddress: string, value: number ): Promise { - const transferAuthAddress = await this.registry.getContractAddressByName( - 'TransferAuthorization' - ); - const hashFunction = new Keccak(256); - hashFunction.update('createRequest(address,address,address,uint256)'); - const hash = hashFunction.digest(); - const methodSignature = hash.toString('hex').substring(0, 8); - const abiCoder = new utils.AbiCoder(); - const abi = await abiCoder.encode( - ['address', 'address', 'address', 'uint256'], - [senderAddress, recipientAddress, tokenAddress, value] - ); - const data = fromHex(methodSignature + strip0x(abi)); - const tx = new Tx(environment.bloxbergChainId); - tx.nonce = await this.web3.eth.getTransactionCount(senderAddress); - tx.gasPrice = Number(await this.web3.eth.getGasPrice()); - tx.gasLimit = 8000000; - tx.to = fromHex(strip0x(transferAuthAddress)); - tx.value = toValue(value); - tx.data = data; - const txMsg = tx.message(); - const privateKey = this.authService.mutableKeyStore.getPrivateKey(); - if (!privateKey.isDecrypted()) { - const password = window.prompt('password'); - await privateKey.decrypt(password); - } - const signatureObject = secp256k1.ecdsaSign(txMsg, privateKey.keyPacket.privateParams.d); - const r = signatureObject.signature.slice(0, 32); - const s = signatureObject.signature.slice(32); - const v = signatureObject.recid; - tx.setSignature(r, s, v); - const txWire = add0x(toHex(tx.serializeRLP())); - const result = await this.web3.eth.sendSignedTransaction(txWire); - this.loggingService.sendInfoLevelMessage(`Result: ${result}`); - const transaction = await this.web3.eth.getTransaction(result.transactionHash); - this.loggingService.sendInfoLevelMessage(`Transaction: ${transaction}`); + this.registry.onload = async (addressReturned: string): Promise => { + const transferAuthAddress = await this.registry.getContractAddressByName( + 'TransferAuthorization' + ); + const hashFunction = new Keccak(256); + hashFunction.update('createRequest(address,address,address,uint256)'); + const hash = hashFunction.digest(); + const methodSignature = hash.toString('hex').substring(0, 8); + const abiCoder = new utils.AbiCoder(); + const abi = await abiCoder.encode( + ['address', 'address', 'address', 'uint256'], + [senderAddress, recipientAddress, tokenAddress, value] + ); + const data = fromHex(methodSignature + strip0x(abi)); + const tx = new Tx(environment.bloxbergChainId); + tx.nonce = await this.web3.eth.getTransactionCount(senderAddress); + tx.gasPrice = Number(await this.web3.eth.getGasPrice()); + tx.gasLimit = 8000000; + tx.to = fromHex(strip0x(transferAuthAddress)); + tx.value = toValue(value); + tx.data = data; + const txMsg = tx.message(); + const privateKey = this.authService.mutableKeyStore.getPrivateKey(); + if (!privateKey.isDecrypted()) { + const password = window.prompt('password'); + await privateKey.decrypt(password); + } + const signatureObject = secp256k1.ecdsaSign(txMsg, privateKey.keyPacket.privateParams.d); + const r = signatureObject.signature.slice(0, 32); + const s = signatureObject.signature.slice(32); + const v = signatureObject.recid; + tx.setSignature(r, s, v); + const txWire = add0x(toHex(tx.serializeRLP())); + const result = await this.web3.eth.sendSignedTransaction(txWire); + this.loggingService.sendInfoLevelMessage(`Result: ${result}`); + const transaction = await this.web3.eth.getTransaction(result.transactionHash); + this.loggingService.sendInfoLevelMessage(`Transaction: ${transaction}`); + }; } } diff --git a/src/app/_services/user.service.ts b/src/app/_services/user.service.ts index 2ee24ca..80ef2d2 100644 --- a/src/app/_services/user.service.ts +++ b/src/app/_services/user.service.ts @@ -46,8 +46,7 @@ export class UserService { this.keystore = authService.mutableKeyStore; this.signer = new PGPSigner(this.keystore); }); - this.registry = registryService.getRegistry(); - this.registry.load(); + this.registry = registryService.registry; } resetPin(phone: string): Observable { @@ -179,17 +178,20 @@ export class UserService { async loadAccounts(limit: number = 100, offset: number = 0): Promise { this.resetAccountsList(); - const accountIndexAddress: string = await this.registry.getContractAddressByName( - 'AccountRegistry' - ); - const accountIndexQuery = new AccountIndex(accountIndexAddress); - const accountAddresses: Array = await accountIndexQuery.last( - await accountIndexQuery.totalAccounts() - ); - this.loggingService.sendInfoLevelMessage(accountAddresses); - for (const accountAddress of accountAddresses.slice(offset, offset + limit)) { - await this.getAccountByAddress(accountAddress, limit); - } + this.registry.onload = async (addressReturned: string): Promise => { + const accountIndexAddress: string = await this.registry.getContractAddressByName( + 'AccountRegistry' + ); + const accountIndexQuery = new AccountIndex(accountIndexAddress); + const accountAddresses: Array = await accountIndexQuery.last( + await accountIndexQuery.totalAccounts() + ); + console.log(accountAddresses); + this.loggingService.sendInfoLevelMessage(accountAddresses); + for (const accountAddress of accountAddresses.slice(offset, offset + limit)) { + await this.getAccountByAddress(accountAddress, limit); + } + }; } async getAccountByAddress( From ac231dc03e6dfe9ffd420a3901ebe33daa45ed1a Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Tue, 18 May 2021 13:24:41 +0300 Subject: [PATCH 05/34] Add token service load event. --- src/app/_helpers/schema-validation.ts | 4 ++-- src/app/_services/token.service.ts | 12 ++++++------ src/app/_services/user.service.ts | 8 +++++--- src/app/pages/tokens/tokens.component.ts | 15 ++++++--------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/app/_helpers/schema-validation.ts b/src/app/_helpers/schema-validation.ts index f8779a5..371ff44 100644 --- a/src/app/_helpers/schema-validation.ts +++ b/src/app/_helpers/schema-validation.ts @@ -4,7 +4,7 @@ async function personValidation(person: any): Promise { const personValidationErrors: any = await validatePerson(person); if (personValidationErrors) { - personValidationErrors.map((error) => console.error(`${error.message}`)); + personValidationErrors.map((error) => console.error(`${error.message}`, person, error)); } } @@ -12,7 +12,7 @@ async function vcardValidation(vcard: any): Promise { const vcardValidationErrors: any = await validateVcard(vcard); if (vcardValidationErrors) { - vcardValidationErrors.map((error) => console.error(`${error.message}`)); + vcardValidationErrors.map((error) => console.error(`${error.message}`, vcard, error)); } } diff --git a/src/app/_services/token.service.ts b/src/app/_services/token.service.ts index 748361f..b644b4d 100644 --- a/src/app/_services/token.service.ts +++ b/src/app/_services/token.service.ts @@ -1,6 +1,6 @@ -import { EventEmitter, Injectable } from '@angular/core'; +import { Injectable } from '@angular/core'; import { environment } from '@src/environments/environment'; -import { BehaviorSubject, Observable } from 'rxjs'; +import { Observable } from 'rxjs'; import { CICRegistry } from 'cic-client'; import { TokenRegistry } from '@app/_eth'; import { HttpClient } from '@angular/common/http'; @@ -12,15 +12,15 @@ import { RegistryService } from '@app/_services/registry.service'; export class TokenService { registry: CICRegistry; tokenRegistry: TokenRegistry; - LoadEvent: EventEmitter = new EventEmitter(); + onload: (status: boolean) => void; constructor(private httpClient: HttpClient, private registryService: RegistryService) { - this.registry = registryService.registry; + this.registry = this.registryService.registry; this.registry.onload = async (address: string): Promise => { this.tokenRegistry = new TokenRegistry( await this.registry.getContractAddressByName('TokenRegistry') ); - this.LoadEvent.next(Date.now()); + this.onload(this.tokenRegistry !== undefined); }; } @@ -33,7 +33,7 @@ export class TokenService { return this.httpClient.get(`${environment.cicCacheUrl}/tokens/${symbol}`); } - async getTokenBalance(address: string): Promise { + async getTokenBalance(address: string): Promise<(address: string) => Promise> { const sarafuToken = await this.registry.addToken(await this.tokenRegistry.entry(0)); return await sarafuToken.methods.balanceOf(address).call(); } diff --git a/src/app/_services/user.service.ts b/src/app/_services/user.service.ts index 80ef2d2..cb418d4 100644 --- a/src/app/_services/user.service.ts +++ b/src/app/_services/user.service.ts @@ -205,9 +205,11 @@ export class UserService { const account: Syncable = Envelope.fromJSON(JSON.stringify(res)).unwrap(); const accountInfo = account.m.data; await personValidation(accountInfo); - accountInfo.balance = await this.tokenService.getTokenBalance( - accountInfo.identities.evm[`bloxberg:${environment.bloxbergChainId}`][0] - ); + this.tokenService.onload = async (status: boolean): Promise => { + accountInfo.balance = await this.tokenService.getTokenBalance( + accountInfo.identities.evm[`bloxberg:${environment.bloxbergChainId}`][0] + ); + }; accountInfo.vcard = vCard.parse(atob(accountInfo.vcard)); await vcardValidation(accountInfo.vcard); this.accounts.unshift(accountInfo); diff --git a/src/app/pages/tokens/tokens.component.ts b/src/app/pages/tokens/tokens.component.ts index 767694a..b4b4012 100644 --- a/src/app/pages/tokens/tokens.component.ts +++ b/src/app/pages/tokens/tokens.component.ts @@ -5,8 +5,6 @@ import { LoggingService, TokenService } from '@app/_services'; import { MatTableDataSource } from '@angular/material/table'; import { Router } from '@angular/router'; import { exportCsv } from '@app/_helpers'; -import { TokenRegistry } from '../../_eth'; -import { Token } from '../../_models'; @Component({ selector: 'app-tokens', @@ -28,14 +26,13 @@ export class TokensComponent implements OnInit { ) {} async ngOnInit(): Promise { - this.tokenService.LoadEvent.subscribe(async () => { + this.tokenService.onload = async (status: boolean): Promise => { this.tokens = await this.tokenService.getTokens(); - }); - this.tokens = await this.tokenService.getTokens(); - this.loggingService.sendInfoLevelMessage(this.tokens); - this.dataSource = new MatTableDataSource(this.tokens); - this.dataSource.paginator = this.paginator; - this.dataSource.sort = this.sort; + this.loggingService.sendInfoLevelMessage(this.tokens); + this.dataSource = new MatTableDataSource(this.tokens); + this.dataSource.paginator = this.paginator; + this.dataSource.sort = this.sort; + }; } doFilter(value: string): void { From 9235c969fa3db3e5096c834f3e390d21460de177 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Tue, 18 May 2021 15:37:30 +0300 Subject: [PATCH 06/34] Use limit to query account index. --- src/app/_services/user.service.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/app/_services/user.service.ts b/src/app/_services/user.service.ts index cb418d4..fd1d3e1 100644 --- a/src/app/_services/user.service.ts +++ b/src/app/_services/user.service.ts @@ -183,10 +183,7 @@ export class UserService { 'AccountRegistry' ); const accountIndexQuery = new AccountIndex(accountIndexAddress); - const accountAddresses: Array = await accountIndexQuery.last( - await accountIndexQuery.totalAccounts() - ); - console.log(accountAddresses); + const accountAddresses: Array = await accountIndexQuery.last(limit); this.loggingService.sendInfoLevelMessage(accountAddresses); for (const accountAddress of accountAddresses.slice(offset, offset + limit)) { await this.getAccountByAddress(accountAddress, limit); From a003bd7124236089d38dd8fac7c60696817c4621 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Tue, 18 May 2021 16:08:25 +0300 Subject: [PATCH 07/34] Add check for transaction in current transactions list. --- src/app/_services/transaction.service.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/app/_services/transaction.service.ts b/src/app/_services/transaction.service.ts index 94164ae..bcd4ca6 100644 --- a/src/app/_services/transaction.service.ts +++ b/src/app/_services/transaction.service.ts @@ -108,9 +108,14 @@ export class TransactionService { } addTransaction(transaction, cacheSize: number): void { + const savedIndex = this.transactions.findIndex(tx => tx.tx.txHash === transaction.tx.txHash); + if (savedIndex === 0) { return; } + if (savedIndex > 0) { + this.transactions.splice(savedIndex, 1); + } this.transactions.unshift(transaction); if (this.transactions.length > cacheSize) { - this.transactions.length = cacheSize; + this.transactions.length = Math.min(this.transactions.length, cacheSize); } this.transactionList.next(this.transactions); } From be3d38907800562f8073750bd24ffb8dd9f6f0cd Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Tue, 18 May 2021 16:17:35 +0300 Subject: [PATCH 08/34] Refactor transaction events generator into one interface. --- src/app/_services/block-sync.service.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/app/_services/block-sync.service.ts b/src/app/_services/block-sync.service.ts index e532113..cf63667 100644 --- a/src/app/_services/block-sync.service.ts +++ b/src/app/_services/block-sync.service.ts @@ -30,10 +30,10 @@ export class BlockSyncService { settings.txHelper = new TransactionHelper(settings.w3.engine, settings.registry); settings.txHelper.ontransfer = async (transaction: any): Promise => { - window.dispatchEvent(this.newTransferEvent(transaction)); + window.dispatchEvent(this.newEvent(transaction, 'cic_transfer')); }; settings.txHelper.onconversion = async (transaction: any): Promise => { - window.dispatchEvent(this.newConversionEvent(transaction)); + window.dispatchEvent(this.newEvent(transaction, 'cic_convert')); }; settings.registry.onload = (addressReturned: string): void => { this.loggingService.sendInfoLevelMessage(`Loaded network contracts ${addressReturned}`); @@ -76,16 +76,8 @@ export class BlockSyncService { } } - newTransferEvent(tx: any): any { - return new CustomEvent('cic_transfer', { - detail: { - tx, - }, - }); - } - - newConversionEvent(tx: any): any { - return new CustomEvent('cic_convert', { + newEvent(tx: any, eventType: string): any { + return new CustomEvent(eventType, { detail: { tx, }, From 7a2321f444723490b16412daa019f8cf17329889 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Tue, 18 May 2021 19:06:57 +0300 Subject: [PATCH 09/34] Parse incoming data from meta into JSON format. --- src/app/_services/user.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/_services/user.service.ts b/src/app/_services/user.service.ts index fd1d3e1..f632866 100644 --- a/src/app/_services/user.service.ts +++ b/src/app/_services/user.service.ts @@ -200,7 +200,7 @@ export class UserService { .pipe(first()) .subscribe(async (res) => { const account: Syncable = Envelope.fromJSON(JSON.stringify(res)).unwrap(); - const accountInfo = account.m.data; + const accountInfo = JSON.parse(account.m.data); await personValidation(accountInfo); this.tokenService.onload = async (status: boolean): Promise => { accountInfo.balance = await this.tokenService.getTokenBalance( From 872bf657869fbe63e7fed6e608048bc373613ce8 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Tue, 18 May 2021 22:10:08 +0300 Subject: [PATCH 10/34] Refactor services to handle data from meta service. --- src/app/_services/transaction.service.ts | 10 +++++----- src/app/_services/user.service.ts | 1 + .../data/{Declarator.json => AddressDeclarator.json} | 0 src/assets/js/block-sync/driver.js | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) rename src/assets/js/block-sync/data/{Declarator.json => AddressDeclarator.json} (100%) diff --git a/src/app/_services/transaction.service.ts b/src/app/_services/transaction.service.ts index bcd4ca6..f3a271c 100644 --- a/src/app/_services/transaction.service.ts +++ b/src/app/_services/transaction.service.ts @@ -46,7 +46,7 @@ export class TransactionService { } getAddressTransactions(address: string, offset: number, limit: number): Observable { - return this.httpClient.get(`${environment.cicCacheUrl}/tx/${address}/${offset}/${limit}`); + return this.httpClient.get(`${environment.cicCacheUrl}/tx/user/${address}/${offset}/${limit}`); } async setTransaction(transaction, cacheSize: number): Promise { @@ -61,7 +61,7 @@ export class TransactionService { .pipe(first()) .subscribe( (res) => { - transaction.sender = this.getAccountInfo(res.body); + transaction.sender = this.getAccountInfo(res); }, (error) => { transaction.sender = defaultAccount; @@ -72,7 +72,7 @@ export class TransactionService { .pipe(first()) .subscribe( (res) => { - transaction.recipient = this.getAccountInfo(res.body); + transaction.recipient = this.getAccountInfo(res); }, (error) => { transaction.recipient = defaultAccount; @@ -96,7 +96,7 @@ export class TransactionService { .pipe(first()) .subscribe( (res) => { - conversion.sender = conversion.recipient = this.getAccountInfo(res.body); + conversion.sender = conversion.recipient = this.getAccountInfo(res); }, (error) => { conversion.sender = conversion.recipient = defaultAccount; @@ -126,7 +126,7 @@ export class TransactionService { } getAccountInfo(account: string): any { - const accountInfo = Envelope.fromJSON(JSON.stringify(account)).unwrap().m.data; + const accountInfo = JSON.parse(Envelope.fromJSON(JSON.stringify(account)).unwrap().m.data); accountInfo.vcard = vCard.parse(atob(accountInfo.vcard)); return accountInfo; } diff --git a/src/app/_services/user.service.ts b/src/app/_services/user.service.ts index f632866..68941fa 100644 --- a/src/app/_services/user.service.ts +++ b/src/app/_services/user.service.ts @@ -103,6 +103,7 @@ export class UserService { .subscribe( async (res) => { const syncableAccount: Syncable = Envelope.fromJSON(JSON.stringify(res)).unwrap(); + syncableAccount.m.data = JSON.parse(syncableAccount.m.data); const update: Array = []; for (const prop of Object.keys(accountInfo)) { update.push(new ArgPair(prop, accountInfo[prop])); diff --git a/src/assets/js/block-sync/data/Declarator.json b/src/assets/js/block-sync/data/AddressDeclarator.json similarity index 100% rename from src/assets/js/block-sync/data/Declarator.json rename to src/assets/js/block-sync/data/AddressDeclarator.json diff --git a/src/assets/js/block-sync/driver.js b/src/assets/js/block-sync/driver.js index 3f65340..f6f8bf7 100644 --- a/src/assets/js/block-sync/driver.js +++ b/src/assets/js/block-sync/driver.js @@ -42,7 +42,7 @@ Driver.prototype.sync = function (n) { const processor = async (b, t) => { return await self.process(b, t); }; - self.syncer(self, self.lo, self.hi, self.filters[0], self.filters[1], countGetter, processor); + self.syncer(self.lo, self.hi, self.filters[0], self.filters[1], countGetter, processor); }; Driver.prototype.process = function (b, t) { From 8ad736de20891ddf772743a558c7aaf9860a71b4 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 19 May 2021 09:32:35 +0300 Subject: [PATCH 11/34] Fix async pipe. --- .../transaction-details/transaction-details.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/pages/transactions/transaction-details/transaction-details.component.html b/src/app/pages/transactions/transaction-details/transaction-details.component.html index 4789857..87e178b 100644 --- a/src/app/pages/transactions/transaction-details/transaction-details.component.html +++ b/src/app/pages/transactions/transaction-details/transaction-details.component.html @@ -1,4 +1,4 @@ -
+
From 4e06b42cc6101f3201c1fcbee8a178f6dac2c1fa Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 19 May 2021 10:56:39 +0300 Subject: [PATCH 12/34] Fix user traded accounts list. --- src/app/_services/transaction.service.ts | 16 ++-- src/app/_services/user.service.ts | 25 ++++-- .../account-details.component.html | 10 +-- .../account-details.component.ts | 85 ++++++++++--------- 4 files changed, 79 insertions(+), 57 deletions(-) diff --git a/src/app/_services/transaction.service.ts b/src/app/_services/transaction.service.ts index f3a271c..6a4897d 100644 --- a/src/app/_services/transaction.service.ts +++ b/src/app/_services/transaction.service.ts @@ -61,10 +61,11 @@ export class TransactionService { .pipe(first()) .subscribe( (res) => { - transaction.sender = this.getAccountInfo(res); + transaction.sender = this.getAccountInfo(res, cacheSize); }, (error) => { transaction.sender = defaultAccount; + this.userService.addAccount(defaultAccount, cacheSize); } ); this.userService @@ -72,10 +73,11 @@ export class TransactionService { .pipe(first()) .subscribe( (res) => { - transaction.recipient = this.getAccountInfo(res); + transaction.recipient = this.getAccountInfo(res, cacheSize); }, (error) => { transaction.recipient = defaultAccount; + this.userService.addAccount(defaultAccount, cacheSize); } ); } finally { @@ -100,6 +102,7 @@ export class TransactionService { }, (error) => { conversion.sender = conversion.recipient = defaultAccount; + this.userService.addAccount(defaultAccount, cacheSize); } ); } finally { @@ -108,8 +111,10 @@ export class TransactionService { } addTransaction(transaction, cacheSize: number): void { - const savedIndex = this.transactions.findIndex(tx => tx.tx.txHash === transaction.tx.txHash); - if (savedIndex === 0) { return; } + const savedIndex = this.transactions.findIndex((tx) => tx.tx.txHash === transaction.tx.txHash); + if (savedIndex === 0) { + return; + } if (savedIndex > 0) { this.transactions.splice(savedIndex, 1); } @@ -125,9 +130,10 @@ export class TransactionService { this.transactionList.next(this.transactions); } - getAccountInfo(account: string): any { + getAccountInfo(account: string, cacheSize: number = 100): any { const accountInfo = JSON.parse(Envelope.fromJSON(JSON.stringify(account)).unwrap().m.data); accountInfo.vcard = vCard.parse(atob(accountInfo.vcard)); + this.userService.addAccount(accountInfo, cacheSize); return accountInfo; } diff --git a/src/app/_services/user.service.ts b/src/app/_services/user.service.ts index 68941fa..85ffc32 100644 --- a/src/app/_services/user.service.ts +++ b/src/app/_services/user.service.ts @@ -210,11 +210,7 @@ export class UserService { }; accountInfo.vcard = vCard.parse(atob(accountInfo.vcard)); await vcardValidation(accountInfo.vcard); - this.accounts.unshift(accountInfo); - if (this.accounts.length > limit) { - this.accounts.length = limit; - } - this.accountsList.next(this.accounts); + this.addAccount(accountInfo, limit); accountSubject.next(accountInfo); }); return accountSubject.asObservable(); @@ -266,4 +262,23 @@ export class UserService { getGenders(): Observable { return this.httpClient.get(`${environment.cicMetaUrl}/genders`); } + + addAccount(account: AccountDetails, cacheSize: number): void { + const savedIndex = this.accounts.findIndex( + (acc) => + acc.identities.evm[`bloxberg:${environment.bloxbergChainId}`][0] === + account.identities.evm[`bloxberg:${environment.bloxbergChainId}`][0] + ); + if (savedIndex === 0) { + return; + } + if (savedIndex > 0) { + this.accounts.splice(savedIndex, 1); + } + this.accounts.unshift(account); + if (this.accounts.length > cacheSize) { + this.accounts.length = Math.min(this.accounts.length, cacheSize); + } + this.accountsList.next(this.accounts); + } } 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 4cdec33..a784822 100644 --- a/src/app/pages/accounts/account-details/account-details.component.html +++ b/src/app/pages/accounts/account-details/account-details.component.html @@ -252,7 +252,7 @@ search - @@ -285,10 +285,10 @@ - - - + + + 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 5a26eab..39cdcbf 100644 --- a/src/app/pages/accounts/account-details/account-details.component.ts +++ b/src/app/pages/accounts/account-details/account-details.component.ts @@ -90,37 +90,54 @@ export class AccountDetailsComponent implements OnInit { location: ['', Validators.required], locationType: ['', Validators.required], }); - this.route.paramMap.subscribe(async (params: Params) => { + this.route.paramMap.subscribe((params: Params) => { 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) { - this.account = res; - this.cdr.detectChanges(); - this.loggingService.sendInfoLevelMessage(this.account); - // this.userService.getAccountStatus(this.account.vcard?.tel[0].value).pipe(first()) - // .subscribe(response => this.accountStatus = response); - this.accountInfoForm.patchValue({ - name: this.account.vcard?.fn[0].value, - phoneNumber: this.account.vcard?.tel[0].value, - age: this.account.age, - type: this.account.type, - bio: this.account.products, - gender: this.account.gender, - businessCategory: this.account.category, - userLocation: this.account.location.area_name, - location: this.account.location.area, - locationType: this.account.location.area_type, - }); - } else { - alert('Account not found!'); - } - } - ); this.blockSyncService.blockSync(this.accountAddress); }); + } + + async ngOnInit(): Promise { + (await this.userService.getAccountByAddress(this.accountAddress, 100)).subscribe( + async (res) => { + if (res !== undefined) { + this.account = res; + this.cdr.detectChanges(); + this.loggingService.sendInfoLevelMessage(this.account); + // this.userService.getAccountStatus(this.account.vcard?.tel[0].value).pipe(first()) + // .subscribe(response => this.accountStatus = response); + this.accountInfoForm.patchValue({ + name: this.account.vcard?.fn[0].value, + phoneNumber: this.account.vcard?.tel[0].value, + age: this.account.age, + type: this.account.type, + bio: this.account.products, + gender: this.account.gender, + businessCategory: this.account.category, + userLocation: this.account.location.area_name, + location: this.account.location.area, + locationType: this.account.location.area_type, + }); + } else { + alert('Account not found!'); + } + } + ); + this.userService.accountsSubject.subscribe((accounts) => { + this.userDataSource = new MatTableDataSource(accounts); + this.userDataSource.paginator = this.userTablePaginator; + this.userDataSource.sort = this.userTableSort; + this.accounts = accounts; + }); + + this.transactionService.transactionsSubject.subscribe((transactions) => { + this.transactionsDataSource = new MatTableDataSource(transactions); + this.transactionsDataSource.paginator = this.transactionTablePaginator; + this.transactionsDataSource.sort = this.transactionTableSort; + this.transactions = transactions; + this.cdr.detectChanges(); + }); this.userService .getCategories() .pipe(first()) @@ -147,22 +164,6 @@ export class AccountDetailsComponent implements OnInit { .subscribe((res) => (this.genders = res)); } - ngOnInit(): void { - this.userService.accountsSubject.subscribe((accounts) => { - this.userDataSource = new MatTableDataSource(accounts); - this.userDataSource.paginator = this.userTablePaginator; - this.userDataSource.sort = this.userTableSort; - this.accounts = accounts; - }); - - this.transactionService.transactionsSubject.subscribe((transactions) => { - this.transactionsDataSource = new MatTableDataSource(transactions); - this.transactionsDataSource.paginator = this.transactionTablePaginator; - this.transactionsDataSource.sort = this.transactionTableSort; - this.transactions = transactions; - }); - } - doTransactionFilter(value: string): void { this.transactionsDataSource.filter = value.trim().toLocaleLowerCase(); } From 5baffa5fef0445f010e332c5bfe5242f6f11d051 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 19 May 2021 15:35:28 +0300 Subject: [PATCH 13/34] Fix timestam. --- .../account-details/account-details.component.html | 8 ++++---- src/app/pages/accounts/accounts.component.html | 2 +- .../transaction-details.component.html | 2 +- src/app/pages/transactions/transactions.component.html | 2 +- src/app/shared/_pipes/unix-date.pipe.spec.ts | 8 ++++++++ src/app/shared/_pipes/unix-date.pipe.ts | 10 ++++++++++ src/app/shared/shared.module.ts | 3 +++ 7 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 src/app/shared/_pipes/unix-date.pipe.spec.ts create mode 100644 src/app/shared/_pipes/unix-date.pipe.ts 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 a784822..6f646d2 100644 --- a/src/app/pages/accounts/account-details/account-details.component.html +++ b/src/app/pages/accounts/account-details/account-details.component.html @@ -34,7 +34,7 @@ {{account?.vcard?.fn[0].value}} Balance: {{account?.balance | tokenRatio}} SRF - Created: {{account?.date_registered | date}} + Created: {{account?.date_registered | unixDate}} Address: {{accountAddress}} Copy @@ -210,7 +210,7 @@ {{account?.vcard?.fn[0].value}} {{account?.balance | tokenRatio}} - {{account?.date_registered | date}} + {{account?.date_registered | unixDate}} {{accountStatus}} @@ -275,7 +275,7 @@ Created - {{transaction?.tx.timestamp | date}} + {{transaction?.tx.timestamp | unixDate}} @@ -337,7 +337,7 @@ CREATED - {{user?.date_registered | date}} + {{user?.date_registered | unixDate}} diff --git a/src/app/pages/accounts/accounts.component.html b/src/app/pages/accounts/accounts.component.html index 7252fcf..43628aa 100644 --- a/src/app/pages/accounts/accounts.component.html +++ b/src/app/pages/accounts/accounts.component.html @@ -56,7 +56,7 @@ CREATED - {{user?.date_registered | date}} + {{user?.date_registered | unixDate}} diff --git a/src/app/pages/transactions/transaction-details/transaction-details.component.html b/src/app/pages/transactions/transaction-details/transaction-details.component.html index 87e178b..39f90e1 100644 --- a/src/app/pages/transactions/transaction-details/transaction-details.component.html +++ b/src/app/pages/transactions/transaction-details/transaction-details.component.html @@ -66,7 +66,7 @@ Success: {{transaction.tx.success}}
  • - Timestamp: {{transaction.tx.timestamp | date}} + Timestamp: {{transaction.tx.timestamp | unixDate}}

  • diff --git a/src/app/pages/transactions/transactions.component.html b/src/app/pages/transactions/transactions.component.html index 7491a36..23bbe77 100644 --- a/src/app/pages/transactions/transactions.component.html +++ b/src/app/pages/transactions/transactions.component.html @@ -66,7 +66,7 @@ Created - {{transaction?.tx.timestamp | date}} + {{transaction?.tx.timestamp | unixDate}} diff --git a/src/app/shared/_pipes/unix-date.pipe.spec.ts b/src/app/shared/_pipes/unix-date.pipe.spec.ts new file mode 100644 index 0000000..3a2e039 --- /dev/null +++ b/src/app/shared/_pipes/unix-date.pipe.spec.ts @@ -0,0 +1,8 @@ +import { UnixDatePipe } from './unix-date.pipe'; + +describe('UnixDatePipe', () => { + it('create an instance', () => { + const pipe = new UnixDatePipe(); + expect(pipe).toBeTruthy(); + }); +}); diff --git a/src/app/shared/_pipes/unix-date.pipe.ts b/src/app/shared/_pipes/unix-date.pipe.ts new file mode 100644 index 0000000..b2bb75e --- /dev/null +++ b/src/app/shared/_pipes/unix-date.pipe.ts @@ -0,0 +1,10 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ + name: 'unixDate', +}) +export class UnixDatePipe implements PipeTransform { + transform(timestamp: number, ...args: unknown[]): any { + return new Date(timestamp * 1000).toLocaleDateString('en-GB'); + } +} diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index f27267f..353faf8 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -12,6 +12,7 @@ import { ErrorDialogComponent } from '@app/shared/error-dialog/error-dialog.comp import { MatDialogModule } from '@angular/material/dialog'; import { SafePipe } from '@app/shared/_pipes/safe.pipe'; import { NetworkStatusComponent } from './network-status/network-status.component'; +import { UnixDatePipe } from './_pipes/unix-date.pipe'; @NgModule({ declarations: [ @@ -24,6 +25,7 @@ import { NetworkStatusComponent } from './network-status/network-status.componen ErrorDialogComponent, SafePipe, NetworkStatusComponent, + UnixDatePipe, ], exports: [ TopbarComponent, @@ -33,6 +35,7 @@ import { NetworkStatusComponent } from './network-status/network-status.componen TokenRatioPipe, SafePipe, NetworkStatusComponent, + UnixDatePipe, ], imports: [CommonModule, RouterModule, MatIconModule, MatDialogModule], }) From a4c0e26be9235259708881c906c40da78aa630de Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 19 May 2021 19:57:10 +0300 Subject: [PATCH 14/34] Clean up constructors. --- src/app/_services/block-sync.service.ts | 13 ++++---- src/app/_services/registry.service.ts | 30 +++++++++++-------- src/app/_services/token.service.ts | 6 ++-- src/app/_services/transaction.service.ts | 12 +++++--- src/app/_services/user.service.ts | 15 +++++----- src/app/app.component.ts | 30 ++++++++----------- .../account-details.component.ts | 22 ++++++++------ .../account-search.component.ts | 3 +- src/app/pages/accounts/accounts.component.ts | 28 ++++++++--------- .../create-account.component.ts | 3 +- src/app/pages/admin/admin.component.ts | 7 +++-- src/app/pages/settings/settings.component.ts | 3 +- .../token-details/token-details.component.ts | 7 +++-- src/app/pages/tokens/tokens.component.ts | 1 + .../transaction-details.component.ts | 3 +- .../transactions/transactions.component.ts | 10 ++++--- 16 files changed, 107 insertions(+), 86 deletions(-) diff --git a/src/app/_services/block-sync.service.ts b/src/app/_services/block-sync.service.ts index cf63667..60f5670 100644 --- a/src/app/_services/block-sync.service.ts +++ b/src/app/_services/block-sync.service.ts @@ -16,17 +16,20 @@ export class BlockSyncService { constructor( private transactionService: TransactionService, - private loggingService: LoggingService, - private registryService: RegistryService + private loggingService: LoggingService ) {} - blockSync(address: string = null, offset: number = 0, limit: number = 100): void { + async init(): Promise { + await this.transactionService.init(); + } + + async blockSync(address: string = null, offset: number = 0, limit: number = 100): Promise { this.transactionService.resetTransactionsList(); const settings: Settings = new Settings(this.scan); const readyStateElements: { network: number } = { network: 2 }; settings.w3.provider = environment.web3Provider; - settings.w3.engine = this.registryService.web3; - settings.registry = this.registryService.registry; + settings.w3.engine = RegistryService.web3; + settings.registry = await RegistryService.getRegistry(); settings.txHelper = new TransactionHelper(settings.w3.engine, settings.registry); settings.txHelper.ontransfer = async (transaction: any): Promise => { diff --git a/src/app/_services/registry.service.ts b/src/app/_services/registry.service.ts index 7e845ea..0346f05 100644 --- a/src/app/_services/registry.service.ts +++ b/src/app/_services/registry.service.ts @@ -8,18 +8,24 @@ import { HttpGetter } from '@app/_helpers'; providedIn: 'root', }) export class RegistryService { - web3: Web3 = new Web3(environment.web3Provider); - fileGetter: FileGetter = new HttpGetter(); - registry: CICRegistry = new CICRegistry( - this.web3, - environment.registryAddress, - 'Registry', - this.fileGetter, - ['../../assets/js/block-sync/data'] - ); + static web3: Web3 = new Web3(environment.web3Provider); + static fileGetter: FileGetter = new HttpGetter(); + private static registry: CICRegistry; - constructor() { - this.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress); - this.registry.load(); + constructor() {} + + public static async getRegistry(): Promise { + if (!RegistryService.registry) { + RegistryService.registry = new CICRegistry( + RegistryService.web3, + environment.registryAddress, + 'Registry', + RegistryService.fileGetter, + ['../../assets/js/block-sync/data'] + ); + RegistryService.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress); + await RegistryService.registry.load(); + } + return RegistryService.registry; } } diff --git a/src/app/_services/token.service.ts b/src/app/_services/token.service.ts index b644b4d..1444458 100644 --- a/src/app/_services/token.service.ts +++ b/src/app/_services/token.service.ts @@ -14,8 +14,10 @@ export class TokenService { tokenRegistry: TokenRegistry; onload: (status: boolean) => void; - constructor(private httpClient: HttpClient, private registryService: RegistryService) { - this.registry = this.registryService.registry; + constructor(private httpClient: HttpClient) {} + + async init(): Promise { + this.registry = await RegistryService.getRegistry(); this.registry.onload = async (address: string): Promise => { this.tokenRegistry = new TokenRegistry( await this.registry.getContractAddressByName('TokenRegistry') diff --git a/src/app/_services/transaction.service.ts b/src/app/_services/transaction.service.ts index 6a4897d..3d554e7 100644 --- a/src/app/_services/transaction.service.ts +++ b/src/app/_services/transaction.service.ts @@ -34,11 +34,15 @@ export class TransactionService { private httpClient: HttpClient, private authService: AuthService, private userService: UserService, - private loggingService: LoggingService, - private registryService: RegistryService + private loggingService: LoggingService ) { - this.web3 = this.registryService.web3; - this.registry = registryService.registry; + this.web3 = RegistryService.web3; + } + + async init(): Promise { + await this.authService.init(); + await this.userService.init(); + this.registry = await RegistryService.getRegistry(); } getAllTransactions(offset: number, limit: number): Observable { diff --git a/src/app/_services/user.service.ts b/src/app/_services/user.service.ts index 85ffc32..ff1adf0 100644 --- a/src/app/_services/user.service.ts +++ b/src/app/_services/user.service.ts @@ -39,14 +39,15 @@ export class UserService { private httpClient: HttpClient, private loggingService: LoggingService, private tokenService: TokenService, - private registryService: RegistryService, private authService: AuthService - ) { - this.authService.init().then(() => { - this.keystore = authService.mutableKeyStore; - this.signer = new PGPSigner(this.keystore); - }); - this.registry = registryService.registry; + ) {} + + async init(): Promise { + await this.authService.init(); + await this.tokenService.init(); + this.keystore = this.authService.mutableKeyStore; + this.signer = new PGPSigner(this.keystore); + this.registry = await RegistryService.getRegistry(); } resetPin(phone: string): Observable { diff --git a/src/app/app.component.ts b/src/app/app.component.ts index dfda722..4ac8e8b 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -27,28 +27,22 @@ export class AppComponent implements OnInit { private errorDialogService: ErrorDialogService, private swUpdate: SwUpdate ) { - (async () => { - try { - await this.authService.init(); - // this.authService.getPublicKeys() - // .pipe(catchError(async (error) => { - // this.loggingService.sendErrorLevelMessage('Unable to load trusted public keys.', this, {error}); - // this.errorDialogService.openDialog({message: 'Trusted keys endpoint can\'t be reached. Please try again later.'}); - // })).subscribe(this.authService.mutableKeyStore.importPublicKey); - const publicKeys = await this.authService.getPublicKeys(); - await this.authService.mutableKeyStore.importPublicKey(publicKeys); - } catch (error) { - this.errorDialogService.openDialog({ - message: 'Trusted keys endpoint cannot be reached. Please try again later.', - }); - // TODO do something to halt user progress...show a sad cicada page 🦗? - } - })(); this.mediaQuery.addEventListener('change', this.onResize); this.onResize(this.mediaQuery); } - ngOnInit(): void { + async ngOnInit(): Promise { + await this.authService.init(); + await this.transactionService.init(); + try { + const publicKeys = await this.authService.getPublicKeys(); + await this.authService.mutableKeyStore.importPublicKey(publicKeys); + } catch (error) { + this.errorDialogService.openDialog({ + message: 'Trusted keys endpoint cannot be reached. Please try again later.', + }); + // TODO do something to halt user progress...show a sad cicada page 🦗? + } if (!this.swUpdate.isEnabled) { this.swUpdate.available.subscribe(() => { if (confirm('New Version available. Load New Version?')) { 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 39cdcbf..dedcc42 100644 --- a/src/app/pages/accounts/account-details/account-details.component.ts +++ b/src/app/pages/accounts/account-details/account-details.component.ts @@ -78,6 +78,14 @@ export class AccountDetailsComponent implements OnInit { private cdr: ChangeDetectorRef, private snackBar: MatSnackBar ) { + this.route.paramMap.subscribe((params: Params) => { + this.accountAddress = add0x(params.get('id')); + this.bloxbergLink = + 'https://blockexplorer.bloxberg.org/address/' + this.accountAddress + '/transactions'; + }); + } + + async ngOnInit(): Promise { this.accountInfoForm = this.formBuilder.group({ name: ['', Validators.required], phoneNumber: ['', Validators.required], @@ -90,15 +98,11 @@ export class AccountDetailsComponent implements OnInit { location: ['', Validators.required], locationType: ['', Validators.required], }); - this.route.paramMap.subscribe((params: Params) => { - this.accountAddress = add0x(params.get('id')); - this.bloxbergLink = - 'https://blockexplorer.bloxberg.org/address/' + this.accountAddress + '/transactions'; - this.blockSyncService.blockSync(this.accountAddress); - }); - } - - async ngOnInit(): Promise { + await this.blockSyncService.init(); + await this.tokenService.init(); + await this.transactionService.init(); + await this.userService.init(); + await this.blockSyncService.blockSync(this.accountAddress); (await this.userService.getAccountByAddress(this.accountAddress, 100)).subscribe( async (res) => { if (res !== undefined) { 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 ef665f8..800b0ce 100644 --- a/src/app/pages/accounts/account-search/account-search.component.ts +++ b/src/app/pages/accounts/account-search/account-search.component.ts @@ -30,7 +30,8 @@ export class AccountSearchComponent implements OnInit { private router: Router ) {} - ngOnInit(): void { + async ngOnInit(): Promise { + await this.userService.init(); this.nameSearchForm = this.formBuilder.group({ name: ['', Validators.required], }); diff --git a/src/app/pages/accounts/accounts.component.ts b/src/app/pages/accounts/accounts.component.ts index 853997a..c009f46 100644 --- a/src/app/pages/accounts/accounts.component.ts +++ b/src/app/pages/accounts/accounts.component.ts @@ -32,28 +32,26 @@ export class AccountsComponent implements OnInit { private userService: UserService, private loggingService: LoggingService, private router: Router - ) { - (async () => { - try { - // TODO it feels like this should be in the onInit handler - await this.userService.loadAccounts(100); - } catch (error) { - this.loggingService.sendErrorLevelMessage('Failed to load accounts', this, { error }); - } - })(); - this.userService - .getAccountTypes() - .pipe(first()) - .subscribe((res) => (this.accountTypes = res)); - } + ) {} - ngOnInit(): void { + async ngOnInit(): Promise { + await this.userService.init(); + try { + // TODO it feels like this should be in the onInit handler + await this.userService.loadAccounts(100); + } catch (error) { + this.loggingService.sendErrorLevelMessage('Failed to load accounts', this, { error }); + } this.userService.accountsSubject.subscribe((accounts) => { this.dataSource = new MatTableDataSource(accounts); this.dataSource.paginator = this.paginator; this.dataSource.sort = this.sort; this.accounts = accounts; }); + this.userService + .getAccountTypes() + .pipe(first()) + .subscribe((res) => (this.accountTypes = res)); } doFilter(value: string): void { diff --git a/src/app/pages/accounts/create-account/create-account.component.ts b/src/app/pages/accounts/create-account/create-account.component.ts index 2f196e7..30692ef 100644 --- a/src/app/pages/accounts/create-account/create-account.component.ts +++ b/src/app/pages/accounts/create-account/create-account.component.ts @@ -26,7 +26,8 @@ export class CreateAccountComponent implements OnInit { private userService: UserService ) {} - ngOnInit(): void { + async ngOnInit(): Promise { + await this.userService.init(); this.createForm = this.formBuilder.group({ accountType: ['', Validators.required], idNumber: ['', Validators.required], diff --git a/src/app/pages/admin/admin.component.ts b/src/app/pages/admin/admin.component.ts index cace112..d33be3c 100644 --- a/src/app/pages/admin/admin.component.ts +++ b/src/app/pages/admin/admin.component.ts @@ -30,7 +30,10 @@ export class AdminComponent implements OnInit { @ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatSort) sort: MatSort; - constructor(private userService: UserService, private loggingService: LoggingService) { + constructor(private userService: UserService, private loggingService: LoggingService) {} + + async ngOnInit(): Promise { + await this.userService.init(); this.userService.getActions(); this.userService.actionsSubject.subscribe((actions) => { this.dataSource = new MatTableDataSource(actions); @@ -40,8 +43,6 @@ export class AdminComponent implements OnInit { }); } - ngOnInit(): void {} - doFilter(value: string): void { this.dataSource.filter = value.trim().toLocaleLowerCase(); } diff --git a/src/app/pages/settings/settings.component.ts b/src/app/pages/settings/settings.component.ts index b8ff67d..2b6825f 100644 --- a/src/app/pages/settings/settings.component.ts +++ b/src/app/pages/settings/settings.component.ts @@ -24,7 +24,8 @@ export class SettingsComponent implements OnInit { constructor(private authService: AuthService) {} - ngOnInit(): void { + async ngOnInit(): Promise { + await this.authService.init(); const d = new Date(); this.date = `${d.getDate()}/${d.getMonth()}/${d.getFullYear()}`; this.trustedUsers = this.authService.getTrustedUsers(); diff --git a/src/app/pages/tokens/token-details/token-details.component.ts b/src/app/pages/tokens/token-details/token-details.component.ts index bb0ece6..795bf30 100644 --- a/src/app/pages/tokens/token-details/token-details.component.ts +++ b/src/app/pages/tokens/token-details/token-details.component.ts @@ -13,7 +13,10 @@ import { Token } from '../../../_models'; export class TokenDetailsComponent implements OnInit { token: Token; - constructor(private route: ActivatedRoute, private tokenService: TokenService) { + constructor(private route: ActivatedRoute, private tokenService: TokenService) {} + + async ngOnInit(): Promise { + await this.tokenService.init(); this.route.paramMap.subscribe((params: Params) => { this.tokenService .getTokenBySymbol(params.get('id')) @@ -23,6 +26,4 @@ export class TokenDetailsComponent implements OnInit { }); }); } - - ngOnInit(): void {} } diff --git a/src/app/pages/tokens/tokens.component.ts b/src/app/pages/tokens/tokens.component.ts index b4b4012..3e76575 100644 --- a/src/app/pages/tokens/tokens.component.ts +++ b/src/app/pages/tokens/tokens.component.ts @@ -26,6 +26,7 @@ export class TokensComponent implements OnInit { ) {} async ngOnInit(): Promise { + await this.tokenService.init(); this.tokenService.onload = async (status: boolean): Promise => { this.tokens = await this.tokenService.getTokens(); this.loggingService.sendInfoLevelMessage(this.tokens); 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 b99ac13..fded333 100644 --- a/src/app/pages/transactions/transaction-details/transaction-details.component.ts +++ b/src/app/pages/transactions/transaction-details/transaction-details.component.ts @@ -23,7 +23,8 @@ export class TransactionDetailsComponent implements OnInit { private snackBar: MatSnackBar ) {} - ngOnInit(): void { + async ngOnInit(): Promise { + await this.transactionService.init(); if (this.transaction?.type === 'conversion') { this.traderBloxbergLink = 'https://blockexplorer.bloxberg.org/address/' + this.transaction?.trader + '/transactions'; diff --git a/src/app/pages/transactions/transactions.component.ts b/src/app/pages/transactions/transactions.component.ts index 56e1f8d..b0b3543 100644 --- a/src/app/pages/transactions/transactions.component.ts +++ b/src/app/pages/transactions/transactions.component.ts @@ -36,17 +36,19 @@ export class TransactionsComponent implements OnInit, AfterViewInit { private blockSyncService: BlockSyncService, private transactionService: TransactionService, private userService: UserService - ) { - this.blockSyncService.blockSync(); - } + ) {} - ngOnInit(): void { + async ngOnInit(): Promise { this.transactionService.transactionsSubject.subscribe((transactions) => { this.transactionDataSource = new MatTableDataSource(transactions); this.transactionDataSource.paginator = this.paginator; this.transactionDataSource.sort = this.sort; this.transactions = transactions; }); + await this.blockSyncService.init(); + await this.transactionService.init(); + await this.userService.init(); + await this.blockSyncService.blockSync(); this.userService .getTransactionTypes() .pipe(first()) From c60d28a053dc3281177b2dfd6842c4c93f87e650 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Thu, 20 May 2021 21:27:06 +0300 Subject: [PATCH 15/34] Add web3 singleton service. --- src/app/_eth/accountIndex.ts | 4 ++-- src/app/_eth/token-registry.ts | 4 ++-- src/app/_services/block-sync.service.ts | 3 ++- src/app/_services/index.ts | 1 + src/app/_services/registry.service.ts | 5 ++--- src/app/_services/transaction.service.ts | 3 ++- src/app/_services/web3.service.spec.ts | 16 ++++++++++++++++ src/app/_services/web3.service.ts | 19 +++++++++++++++++++ 8 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 src/app/_services/web3.service.spec.ts create mode 100644 src/app/_services/web3.service.ts diff --git a/src/app/_eth/accountIndex.ts b/src/app/_eth/accountIndex.ts index 564479f..2300a9f 100644 --- a/src/app/_eth/accountIndex.ts +++ b/src/app/_eth/accountIndex.ts @@ -1,8 +1,8 @@ -import { environment } from '@src/environments/environment'; import Web3 from 'web3'; +import {Web3Service} from '@app/_services/web3.service'; const abi: Array = require('@src/assets/js/block-sync/data/AccountsIndex.json'); -const web3: Web3 = new Web3(environment.web3Provider); +const web3: Web3 = Web3Service.getInstance(); export class AccountIndex { contractAddress: string; diff --git a/src/app/_eth/token-registry.ts b/src/app/_eth/token-registry.ts index 24cfa00..2124752 100644 --- a/src/app/_eth/token-registry.ts +++ b/src/app/_eth/token-registry.ts @@ -1,8 +1,8 @@ import Web3 from 'web3'; -import { environment } from '@src/environments/environment'; +import {Web3Service} from '@app/_services/web3.service'; const abi: Array = require('@src/assets/js/block-sync/data/TokenUniqueSymbolIndex.json'); -const web3: Web3 = new Web3(environment.web3Provider); +const web3: Web3 = Web3Service.getInstance(); export class TokenRegistry { contractAddress: string; diff --git a/src/app/_services/block-sync.service.ts b/src/app/_services/block-sync.service.ts index 60f5670..26fbcd2 100644 --- a/src/app/_services/block-sync.service.ts +++ b/src/app/_services/block-sync.service.ts @@ -6,6 +6,7 @@ import { TransactionService } from '@app/_services/transaction.service'; import { environment } from '@src/environments/environment'; import { LoggingService } from '@app/_services/logging.service'; import { RegistryService } from '@app/_services/registry.service'; +import {Web3Service} from '@app/_services/web3.service'; @Injectable({ providedIn: 'root', @@ -28,7 +29,7 @@ export class BlockSyncService { const settings: Settings = new Settings(this.scan); const readyStateElements: { network: number } = { network: 2 }; settings.w3.provider = environment.web3Provider; - settings.w3.engine = RegistryService.web3; + settings.w3.engine = Web3Service.getInstance(); settings.registry = await RegistryService.getRegistry(); settings.txHelper = new TransactionHelper(settings.w3.engine, settings.registry); diff --git a/src/app/_services/index.ts b/src/app/_services/index.ts index 6ded947..88db87d 100644 --- a/src/app/_services/index.ts +++ b/src/app/_services/index.ts @@ -6,3 +6,4 @@ export * from '@app/_services/block-sync.service'; export * from '@app/_services/location.service'; export * from '@app/_services/logging.service'; export * from '@app/_services/error-dialog.service'; +export * from '@app/_services/web3.service'; diff --git a/src/app/_services/registry.service.ts b/src/app/_services/registry.service.ts index 0346f05..4bcd4dc 100644 --- a/src/app/_services/registry.service.ts +++ b/src/app/_services/registry.service.ts @@ -1,14 +1,13 @@ import { Injectable } from '@angular/core'; -import Web3 from 'web3'; import { environment } from '@src/environments/environment'; import { CICRegistry, FileGetter } from 'cic-client'; import { HttpGetter } from '@app/_helpers'; +import {Web3Service} from '@app/_services/web3.service'; @Injectable({ providedIn: 'root', }) export class RegistryService { - static web3: Web3 = new Web3(environment.web3Provider); static fileGetter: FileGetter = new HttpGetter(); private static registry: CICRegistry; @@ -17,7 +16,7 @@ export class RegistryService { public static async getRegistry(): Promise { if (!RegistryService.registry) { RegistryService.registry = new CICRegistry( - RegistryService.web3, + Web3Service.getInstance(), environment.registryAddress, 'Registry', RegistryService.fileGetter, diff --git a/src/app/_services/transaction.service.ts b/src/app/_services/transaction.service.ts index 3d554e7..8788905 100644 --- a/src/app/_services/transaction.service.ts +++ b/src/app/_services/transaction.service.ts @@ -17,6 +17,7 @@ import { HttpClient } from '@angular/common/http'; import { CICRegistry } from 'cic-client'; import { RegistryService } from '@app/_services/registry.service'; import Web3 from 'web3'; +import {Web3Service} from '@app/_services/web3.service'; const vCard = require('vcard-parser'); @Injectable({ @@ -36,7 +37,7 @@ export class TransactionService { private userService: UserService, private loggingService: LoggingService ) { - this.web3 = RegistryService.web3; + this.web3 = Web3Service.getInstance(); } async init(): Promise { diff --git a/src/app/_services/web3.service.spec.ts b/src/app/_services/web3.service.spec.ts new file mode 100644 index 0000000..0abf88f --- /dev/null +++ b/src/app/_services/web3.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { Web3Service } from './web3.service'; + +describe('Web3Service', () => { + let service: Web3Service; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(Web3Service); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/_services/web3.service.ts b/src/app/_services/web3.service.ts new file mode 100644 index 0000000..797611f --- /dev/null +++ b/src/app/_services/web3.service.ts @@ -0,0 +1,19 @@ +import { Injectable } from '@angular/core'; +import Web3 from 'web3'; +import {environment} from '@src/environments/environment'; + +@Injectable({ + providedIn: 'root' +}) +export class Web3Service { + private static web3: Web3; + + constructor() { } + + public static getInstance(): Web3 { + if (!Web3Service.web3) { + Web3Service.web3 = new Web3(environment.web3Provider); + } + return Web3Service.web3; + } +} From cef7b8dc04792af3099c1cf5c9a6abb65f8e8cff Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 26 May 2021 10:19:14 +0300 Subject: [PATCH 16/34] Refactor ussd service url. --- src/environments/environment.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 1b716c1..df02af7 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -10,7 +10,7 @@ export const environment = { publicKeysUrl: 'https://dev.grassrootseconomics.net/.well-known/publickeys/', cicCacheUrl: 'https://cache.dev.grassrootseconomics.net', web3Provider: 'wss://bloxberg-ws.dev.grassrootseconomics.net', - cicUssdUrl: 'https://ussd.dev.grassrootseconomics.net', + cicUssdUrl: 'https://user.dev.grassrootseconomics.net', registryAddress: '0xea6225212005e86a4490018ded4bf37f3e772161', trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C', }; From 9782c919d5d64d23257e43a5f9a69aa703f212fa Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 26 May 2021 10:26:11 +0300 Subject: [PATCH 17/34] Refactor calls to ussd service. --- src/app/_services/user.service.ts | 2 +- .../accounts/account-details/account-details.component.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/_services/user.service.ts b/src/app/_services/user.service.ts index ff1adf0..cc9685e 100644 --- a/src/app/_services/user.service.ts +++ b/src/app/_services/user.service.ts @@ -52,7 +52,7 @@ export class UserService { resetPin(phone: string): Observable { const params: HttpParams = new HttpParams().set('phoneNumber', phone); - return this.httpClient.get(`${environment.cicUssdUrl}/pin`, { params }); + return this.httpClient.put(`${environment.cicUssdUrl}/pin`, { params }); } getAccountStatus(phone: string): Observable { 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 dedcc42..e7e01f3 100644 --- a/src/app/pages/accounts/account-details/account-details.component.ts +++ b/src/app/pages/accounts/account-details/account-details.component.ts @@ -109,8 +109,6 @@ export class AccountDetailsComponent implements OnInit { this.account = res; this.cdr.detectChanges(); this.loggingService.sendInfoLevelMessage(this.account); - // this.userService.getAccountStatus(this.account.vcard?.tel[0].value).pipe(first()) - // .subscribe(response => this.accountStatus = response); this.accountInfoForm.patchValue({ name: this.account.vcard?.fn[0].value, phoneNumber: this.account.vcard?.tel[0].value, @@ -123,6 +121,8 @@ export class AccountDetailsComponent implements OnInit { location: this.account.location.area, locationType: this.account.location.area_type, }); + this.userService.getAccountStatus(this.account.vcard?.tel[0].value).pipe(first()) + .subscribe(response => this.accountStatus = response.status); } else { alert('Account not found!'); } From 16af939af7312770aba5d01cde2ce95c2af15bab Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 26 May 2021 11:30:38 +0300 Subject: [PATCH 18/34] Refactor transactions table to show address before loading account meta. --- src/app/_eth/accountIndex.ts | 2 +- src/app/_eth/token-registry.ts | 2 +- src/app/_services/block-sync.service.ts | 2 +- src/app/_services/registry.service.ts | 2 +- src/app/_services/transaction.service.ts | 2 +- src/app/_services/web3.service.ts | 6 +++--- .../accounts/account-details/account-details.component.ts | 6 ++++-- src/app/pages/transactions/transactions.component.html | 4 ++-- 8 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/app/_eth/accountIndex.ts b/src/app/_eth/accountIndex.ts index 2300a9f..bf7445b 100644 --- a/src/app/_eth/accountIndex.ts +++ b/src/app/_eth/accountIndex.ts @@ -1,5 +1,5 @@ import Web3 from 'web3'; -import {Web3Service} from '@app/_services/web3.service'; +import { Web3Service } from '@app/_services/web3.service'; const abi: Array = require('@src/assets/js/block-sync/data/AccountsIndex.json'); const web3: Web3 = Web3Service.getInstance(); diff --git a/src/app/_eth/token-registry.ts b/src/app/_eth/token-registry.ts index 2124752..e1d56fb 100644 --- a/src/app/_eth/token-registry.ts +++ b/src/app/_eth/token-registry.ts @@ -1,5 +1,5 @@ import Web3 from 'web3'; -import {Web3Service} from '@app/_services/web3.service'; +import { Web3Service } from '@app/_services/web3.service'; const abi: Array = require('@src/assets/js/block-sync/data/TokenUniqueSymbolIndex.json'); const web3: Web3 = Web3Service.getInstance(); diff --git a/src/app/_services/block-sync.service.ts b/src/app/_services/block-sync.service.ts index 26fbcd2..06f2794 100644 --- a/src/app/_services/block-sync.service.ts +++ b/src/app/_services/block-sync.service.ts @@ -6,7 +6,7 @@ import { TransactionService } from '@app/_services/transaction.service'; import { environment } from '@src/environments/environment'; import { LoggingService } from '@app/_services/logging.service'; import { RegistryService } from '@app/_services/registry.service'; -import {Web3Service} from '@app/_services/web3.service'; +import { Web3Service } from '@app/_services/web3.service'; @Injectable({ providedIn: 'root', diff --git a/src/app/_services/registry.service.ts b/src/app/_services/registry.service.ts index 4bcd4dc..3aa990c 100644 --- a/src/app/_services/registry.service.ts +++ b/src/app/_services/registry.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { environment } from '@src/environments/environment'; import { CICRegistry, FileGetter } from 'cic-client'; import { HttpGetter } from '@app/_helpers'; -import {Web3Service} from '@app/_services/web3.service'; +import { Web3Service } from '@app/_services/web3.service'; @Injectable({ providedIn: 'root', diff --git a/src/app/_services/transaction.service.ts b/src/app/_services/transaction.service.ts index 8788905..09367ee 100644 --- a/src/app/_services/transaction.service.ts +++ b/src/app/_services/transaction.service.ts @@ -17,7 +17,7 @@ import { HttpClient } from '@angular/common/http'; import { CICRegistry } from 'cic-client'; import { RegistryService } from '@app/_services/registry.service'; import Web3 from 'web3'; -import {Web3Service} from '@app/_services/web3.service'; +import { Web3Service } from '@app/_services/web3.service'; const vCard = require('vcard-parser'); @Injectable({ diff --git a/src/app/_services/web3.service.ts b/src/app/_services/web3.service.ts index 797611f..b7f5cd4 100644 --- a/src/app/_services/web3.service.ts +++ b/src/app/_services/web3.service.ts @@ -1,14 +1,14 @@ import { Injectable } from '@angular/core'; import Web3 from 'web3'; -import {environment} from '@src/environments/environment'; +import { environment } from '@src/environments/environment'; @Injectable({ - providedIn: 'root' + providedIn: 'root', }) export class Web3Service { private static web3: Web3; - constructor() { } + constructor() {} public static getInstance(): Web3 { if (!Web3Service.web3) { 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 e7e01f3..1abc6a1 100644 --- a/src/app/pages/accounts/account-details/account-details.component.ts +++ b/src/app/pages/accounts/account-details/account-details.component.ts @@ -121,8 +121,10 @@ export class AccountDetailsComponent implements OnInit { location: this.account.location.area, locationType: this.account.location.area_type, }); - this.userService.getAccountStatus(this.account.vcard?.tel[0].value).pipe(first()) - .subscribe(response => this.accountStatus = response.status); + this.userService + .getAccountStatus(this.account.vcard?.tel[0].value) + .pipe(first()) + .subscribe((response) => (this.accountStatus = response.status)); } else { alert('Account not found!'); } diff --git a/src/app/pages/transactions/transactions.component.html b/src/app/pages/transactions/transactions.component.html index 23bbe77..1d4adc8 100644 --- a/src/app/pages/transactions/transactions.component.html +++ b/src/app/pages/transactions/transactions.component.html @@ -48,12 +48,12 @@ Sender - {{transaction?.sender?.vcard.fn[0].value}} + {{transaction?.sender?.vcard.fn[0].value || transaction.from}} Recipient - {{transaction?.recipient?.vcard.fn[0].value}} + {{transaction?.recipient?.vcard.fn[0].value || transaction.to }} From 48ef7cd58d8cb6144c359de1f3dafa31de597745 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 26 May 2021 11:53:44 +0300 Subject: [PATCH 19/34] Refactor USSD url. --- src/environments/environment.dev.ts | 2 +- src/environments/environment.prod.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/environments/environment.dev.ts b/src/environments/environment.dev.ts index d83c942..978f71f 100644 --- a/src/environments/environment.dev.ts +++ b/src/environments/environment.dev.ts @@ -10,7 +10,7 @@ export const environment = { publicKeysUrl: 'https://dev.grassrootseconomics.net/.well-known/publickeys/', cicCacheUrl: 'https://cache.dev.grassrootseconomics.net', web3Provider: 'wss://bloxberg-ws.dev.grassrootseconomics.net', - cicUssdUrl: 'https://ussd.dev.grassrootseconomics.net', + cicUssdUrl: 'https://user.dev.grassrootseconomics.net', registryAddress: '0xea6225212005e86a4490018ded4bf37f3e772161', trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C', }; diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index e7af5b9..f4786c1 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -10,7 +10,7 @@ export const environment = { publicKeysUrl: 'https://dev.grassrootseconomics.net/.well-known/publickeys/', cicCacheUrl: 'https://cache.dev.grassrootseconomics.net', web3Provider: 'wss://bloxberg-ws.dev.grassrootseconomics.net', - cicUssdUrl: 'https://ussd.dev.grassrootseconomics.net', + cicUssdUrl: 'https://user.dev.grassrootseconomics.net', registryAddress: '0xea6225212005e86a4490018ded4bf37f3e772161', trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C', }; From 9fed6fcaf3e55a82e0354961e349d31c0ddc517c Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 26 May 2021 12:21:25 +0300 Subject: [PATCH 20/34] Add close event to transaction details presentation component. --- .../account-details.component.html | 6 +++--- .../transaction-details.component.html | 2 +- .../transaction-details.component.ts | 17 ++++++++++++++++- .../transactions/transactions.component.html | 4 ++-- 4 files changed, 22 insertions(+), 7 deletions(-) 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 6f646d2..8d9b7b6 100644 --- a/src/app/pages/accounts/account-details/account-details.component.html +++ b/src/app/pages/accounts/account-details/account-details.component.html @@ -228,7 +228,7 @@ - +
    @@ -257,12 +257,12 @@ Sender - {{transaction?.sender?.vcard.fn[0].value}} + {{transaction?.sender?.vcard.fn[0].value || transaction.from}} Recipient - {{transaction?.recipient?.vcard.fn[0].value}} + {{transaction?.recipient?.vcard.fn[0].value || transaction.to}} diff --git a/src/app/pages/transactions/transaction-details/transaction-details.component.html b/src/app/pages/transactions/transaction-details/transaction-details.component.html index 39f90e1..fb1c6b0 100644 --- a/src/app/pages/transactions/transaction-details/transaction-details.component.html +++ b/src/app/pages/transactions/transaction-details/transaction-details.component.html @@ -3,7 +3,7 @@
    TRANSACTION DETAILS - +
    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 fded333..e6efb47 100644 --- a/src/app/pages/transactions/transaction-details/transaction-details.component.ts +++ b/src/app/pages/transactions/transaction-details/transaction-details.component.ts @@ -1,4 +1,11 @@ -import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core'; +import { + ChangeDetectionStrategy, + Component, + EventEmitter, + Input, + OnInit, + Output, +} from '@angular/core'; import { Router } from '@angular/router'; import { TransactionService } from '@app/_services'; import { copyToClipboard } from '@app/_helpers'; @@ -13,6 +20,9 @@ import { strip0x } from '@src/assets/js/ethtx/dist/hex'; }) export class TransactionDetailsComponent implements OnInit { @Input() transaction; + + @Output() closeWindow: EventEmitter = new EventEmitter(); + senderBloxbergLink: string; recipientBloxbergLink: string; traderBloxbergLink: string; @@ -62,4 +72,9 @@ export class TransactionDetailsComponent implements OnInit { this.snackBar.open(address + ' copied successfully!', 'Close', { duration: 3000 }); } } + + close(): void { + this.transaction = null; + this.closeWindow.emit(this.transaction); + } } diff --git a/src/app/pages/transactions/transactions.component.html b/src/app/pages/transactions/transactions.component.html index 1d4adc8..2099255 100644 --- a/src/app/pages/transactions/transactions.component.html +++ b/src/app/pages/transactions/transactions.component.html @@ -22,7 +22,7 @@
    - +
    @@ -53,7 +53,7 @@ Recipient - {{transaction?.recipient?.vcard.fn[0].value || transaction.to }} + {{transaction?.recipient?.vcard.fn[0].value || transaction.to}} From 228bca564e2193b4cb95acfd216e3c1f6f55a67e Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 26 May 2021 12:51:54 +0300 Subject: [PATCH 21/34] Refactor footer. --- src/app/shared/footer/footer.component.html | 5 ++++- src/app/shared/footer/footer.component.ts | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app/shared/footer/footer.component.html b/src/app/shared/footer/footer.component.html index 75dbf07..fa0028d 100644 --- a/src/app/shared/footer/footer.component.html +++ b/src/app/shared/footer/footer.component.html @@ -1,5 +1,8 @@ diff --git a/src/app/shared/footer/footer.component.ts b/src/app/shared/footer/footer.component.ts index a2971c8..ad2233a 100644 --- a/src/app/shared/footer/footer.component.ts +++ b/src/app/shared/footer/footer.component.ts @@ -7,6 +7,7 @@ import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; changeDetection: ChangeDetectionStrategy.OnPush, }) export class FooterComponent implements OnInit { + currentYear = new Date().getFullYear(); constructor() {} ngOnInit(): void {} From cfe558cccf11aa2502cc02d1137571a27986fe6d Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 26 May 2021 13:06:18 +0300 Subject: [PATCH 22/34] Move online status tracker to sidebar. --- src/app/app.component.html | 1 - src/app/auth/auth.component.html | 3 ++- src/app/auth/auth.module.ts | 22 ++++++++++--------- .../network-status.component.html | 2 +- src/app/shared/sidebar/sidebar.component.html | 1 + src/styles.scss | 4 ++-- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/app/app.component.html b/src/app/app.component.html index 83fd567..f17c3b3 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,2 +1 @@ - diff --git a/src/app/auth/auth.component.html b/src/app/auth/auth.component.html index 2355239..501293c 100644 --- a/src/app/auth/auth.component.html +++ b/src/app/auth/auth.component.html @@ -1,8 +1,9 @@ +
    - +

    CICADA

    diff --git a/src/app/auth/auth.module.ts b/src/app/auth/auth.module.ts index 495ff88..49e9576 100644 --- a/src/app/auth/auth.module.ts +++ b/src/app/auth/auth.module.ts @@ -10,18 +10,20 @@ import { MatSelectModule } from '@angular/material/select'; import { MatInputModule } from '@angular/material/input'; import { MatButtonModule } from '@angular/material/button'; import { MatRippleModule } from '@angular/material/core'; +import {SharedModule} from '@app/shared/shared.module'; @NgModule({ declarations: [AuthComponent, PasswordToggleDirective], - imports: [ - CommonModule, - AuthRoutingModule, - ReactiveFormsModule, - MatCardModule, - MatSelectModule, - MatInputModule, - MatButtonModule, - MatRippleModule, - ], + imports: [ + CommonModule, + AuthRoutingModule, + ReactiveFormsModule, + MatCardModule, + MatSelectModule, + MatInputModule, + MatButtonModule, + MatRippleModule, + SharedModule, + ], }) export class AuthModule {} diff --git a/src/app/shared/network-status/network-status.component.html b/src/app/shared/network-status/network-status.component.html index e0a1f01..1f907f7 100644 --- a/src/app/shared/network-status/network-status.component.html +++ b/src/app/shared/network-status/network-status.component.html @@ -1,4 +1,4 @@ -