diff --git a/README.md b/README.md index 2d203d4..6048d66 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,9 @@ Run `npm install -g @angular/cli` to install the angular CLI. ## Development server -Run `npm run start:dev` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. +Run `ng serve` for a local server, `npm run start:dev` for a dev server and `npm run start:prod` for a prod server.. + +Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. ## Code scaffolding @@ -22,14 +24,21 @@ Run `ng generate module module-name --route module-name --module app.module` to ## Build -set you environment variables - set these via environment variables as found in set-env.ts -// TODO create a .env file so people don't have to set these one-by-one +Run `ng build` to build the project using local configurations. +The build artifacts will be stored in the `dist/` directory. -Run `npm run build:dev` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `build:prod` script for a production build. +Use the `npm run build:dev` script for a development build and the `npm run build:prod` script for a production build. + +## PWA + +The app supports Progressive Web App capabilities. + +Run `npm run start:pwa` to run the project in PWA mode. +PWA mode works using production configurations. ## Running unit tests -Run `npm run test:dev` to execute the unit tests via [Karma](https://karma-runner.github.io). +Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). ## Running end-to-end tests @@ -37,11 +46,19 @@ Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protrac ## Environment variables -Environment variables are contained in the `.env` file. See `.env.example` for a template. +Default environment variables are located in the `src/environments/` directory. +Custom environment variables are contained in the `.env` file. See `.env.example` for a template. -Default environment variables are set in the `set-env.ts` file. +Custom environment variables are set via the `set-env.ts` file. Once loaded they will be populated in the directory `src/environments/`. -It contains environment variables for development on `environment.ts` and production on `environment.prod.ts`. +It contains environment variables for development on `environment.dev.ts` and production on `environment.prod.ts`. + +## Code formatting + +The system has automated code formatting using [Prettier](https://prettier.io/) and [TsLint](https://palantir.github.io/tslint/). +To view the styling rules set, check out `.prettierrc` and `tslint.json`. + +Run `npm run format:lint` To perform formatting and linting of the codebase. ## Further help diff --git a/package.json b/package.json index d8a286f..73e8177 100644 --- a/package.json +++ b/package.json @@ -9,13 +9,14 @@ "build:dev": "ng build -c dev", "build:prod": "ng build --prod", "start:pwa": "npm run build:prod && http-server -p 4200 dist/cic-staff-client", - "test:dev": "ng test", + "test": "ng test", "format:check": "prettier --config ./.prettierrc --list-different \"src/{app,environments,assets}/**/*.{ts,js,json,css,scss}\"", "format:refactor": "prettier --config ./.prettierrc --write \"src/{app,environments,assets}/**/*.{ts,js,json,css,scss}\"", "format:fix": "pretty-quick --staged", + "format:lint": "npm run format:refactor && npm run lint", "lint": "ng lint", "e2e": "ng e2e", - "precommit": "format:fix && lint", + "precommit": "npm run format:fix && npm run lint", "postinstall": "node patch-webpack.js", "prepare": "husky install", "compodoc": "npx compodoc -p tsconfig.doc.json -d docs/compodoc -n CICADA", diff --git a/set-env.ts b/set-env.ts index 754d897..d53c85c 100644 --- a/set-env.ts +++ b/set-env.ts @@ -6,7 +6,7 @@ require('dotenv').config(); const environment = argv.environment; const isProduction = environment === 'prod'; -const targetPath = isProduction ? `./src/environments/environment.prod.ts` : `./src/environments/environment.ts`; +const targetPath = isProduction ? `./src/environments/environment.prod.ts` : `./src/environments/environment.dev.ts`; const environmentVars = `import {NgxLoggerLevel} from 'ngx-logger'; @@ -15,13 +15,13 @@ export const environment = { bloxbergChainId: ${process.env.CIC_CHAIN_ID || 8996}, logLevel: ${process.env.LOG_LEVEL || 'NgxLoggerLevel.ERROR'}, serverLogLevel: ${process.env.SERVER_LOG_LEVEL || 'NgxLoggerLevel.OFF'}, - loggingUrl: '${process.env.CIC_LOGGING_URL || 'http://localhost:8000'}', + loggingUrl: '${process.env.CIC_LOGGING_URL || ''}', cicMetaUrl: '${process.env.CIC_META_URL || 'https://meta.dev.grassrootseconomics.net'}', - publicKeysUrl: '${process.env.CIC_KEYS_URL || 'http://localhost:8000/keys.asc'}', + publicKeysUrl: '${process.env.CIC_KEYS_URL || 'https://dev.grassrootseconomics.net/.well-known/publickeys'}', cicCacheUrl: '${process.env.CIC_CACHE_URL || 'https://cache.dev.grassrootseconomics.net'}', - web3Provider: '${process.env.CIC_WEB3_PROVIDER || 'ws://localhost:63546'}', + web3Provider: '${process.env.CIC_WEB3_PROVIDER || 'wss://bloxberg-ws.dev.grassrootseconomics.net'}', cicUssdUrl: '${process.env.CIC_USSD_URL || 'https://ussd.dev.grassrootseconomics.net'}', - registryAddress: '${process.env.CIC_REGISTRY_ADDRESS || '0x6Ca3cB14aA6F761712E1C18646AfBA4d5Ae249E8'}', + registryAddress: '${process.env.CIC_REGISTRY_ADDRESS || '0xea6225212005e86a4490018ded4bf37f3e772161'}', trustedDeclaratorAddress: '${process.env.CIC_TRUSTED_ADDRESS || '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C'}' }; `; diff --git a/src/app/_eth/accountIndex.ts b/src/app/_eth/accountIndex.ts index d85e542..7fdea15 100644 --- a/src/app/_eth/accountIndex.ts +++ b/src/app/_eth/accountIndex.ts @@ -5,7 +5,7 @@ import Web3 from 'web3'; import { environment } from '@src/environments/environment'; /** Fetch the account registry contract's ABI. */ -const abi: Array = require('@src/assets/js/block-sync/data/AccountRegistry.json'); +const abi: Array = require('@src/assets/js/block-sync/data/AccountsIndex.json'); /** Establish a connection to the blockchain network. */ const web3: Web3 = new Web3(environment.web3Provider); @@ -76,7 +76,7 @@ export class AccountIndex { * @returns true - If the address has been registered in the accounts registry. */ public async haveAccount(address: string): Promise { - return (await this.contract.methods.accountIndex(address).call()) !== 0; + return (await this.contract.methods.have(address).call()) !== 0; } /** @@ -100,7 +100,7 @@ export class AccountIndex { } const accounts: Array = []; for (let i = count - 1; i > lowest; i--) { - const account: string = await this.contract.methods.accounts(i).call(); + const account: string = await this.contract.methods.entry(i).call(); accounts.push(account); } return accounts; @@ -119,6 +119,6 @@ export class AccountIndex { * @returns The total number of registered accounts. */ public async totalAccounts(): Promise { - return await this.contract.methods.count().call(); + return await this.contract.methods.entryCount().call(); } } diff --git a/src/app/_eth/token-registry.ts b/src/app/_eth/token-registry.ts index c1bbe67..9dd11e0 100644 --- a/src/app/_eth/token-registry.ts +++ b/src/app/_eth/token-registry.ts @@ -5,7 +5,7 @@ import Web3 from 'web3'; import { environment } from '@src/environments/environment'; /** Fetch the token registry contract's ABI. */ -const abi: Array = require('@src/assets/js/block-sync/data/TokenUniqueSymbolIndex.json'); +const abi: Array = require('@src/assets/js/block-sync/data/AccountsIndex.json'); /** Establish a connection to the blockchain network. */ const web3: Web3 = new Web3(environment.web3Provider); diff --git a/src/app/_services/registry.service.ts b/src/app/_services/registry.service.ts index ae853cf..0600f5e 100644 --- a/src/app/_services/registry.service.ts +++ b/src/app/_services/registry.service.ts @@ -13,7 +13,7 @@ export class RegistryService { registry: CICRegistry = new CICRegistry( this.web3, environment.registryAddress, - 'CICRegistry', + 'Registry', this.fileGetter, ['../../assets/js/block-sync/data'] ); diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index bab41d3..93e5328 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -16,6 +16,7 @@ const routes: Routes = [ imports: [ RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules, + useHash: true, }), ], exports: [RouterModule], diff --git a/src/assets/js/block-sync/data/AccountRegistry.json b/src/assets/js/block-sync/data/AccountsIndex.json similarity index 55% rename from src/assets/js/block-sync/data/AccountRegistry.json rename to src/assets/js/block-sync/data/AccountsIndex.json index 13bbcb4..8ae6303 100644 --- a/src/assets/js/block-sync/data/AccountRegistry.json +++ b/src/assets/js/block-sync/data/AccountsIndex.json @@ -8,20 +8,6 @@ "name": "AccountAdded", "type": "event" }, - { - "inputs": [{ "internalType": "uint256", "name": "_idx", "type": "uint256" }], - "name": "accounts", - "outputs": [{ "internalType": "address", "name": "", "type": "address" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [{ "internalType": "address", "name": "_account", "type": "address" }], - "name": "accountsIndex", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, { "inputs": [{ "internalType": "address", "name": "_account", "type": "address" }], "name": "add", @@ -30,24 +16,17 @@ "type": "function" }, { - "inputs": [{ "internalType": "address", "name": "_writer", "type": "address" }], - "name": "addWriter", - "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "count", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "name": "entry", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { - "inputs": [{ "internalType": "address", "name": "_writer", "type": "address" }], - "name": "deleteWriter", - "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], - "stateMutability": "nonpayable", + "inputs": [], + "name": "entryCount", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", "type": "function" }, { diff --git a/src/assets/js/block-sync/data/AddressDeclarator.json b/src/assets/js/block-sync/data/Declarator.json similarity index 56% rename from src/assets/js/block-sync/data/AddressDeclarator.json rename to src/assets/js/block-sync/data/Declarator.json index 9759c56..7d2d536 100644 --- a/src/assets/js/block-sync/data/AddressDeclarator.json +++ b/src/assets/js/block-sync/data/Declarator.json @@ -1,18 +1,28 @@ [ { + "anonymous": false, "inputs": [ - { "internalType": "address", "name": "_address", "type": "address" }, + { "indexed": false, "internalType": "address", "name": "_declarator", "type": "address" }, + { "indexed": false, "internalType": "address", "name": "_subject", "type": "address" }, + { "indexed": false, "internalType": "bytes32", "name": "_proof", "type": "bytes32" } + ], + "name": "DeclarationAdded", + "type": "event" + }, + { + "inputs": [ + { "internalType": "address", "name": "_subject", "type": "address" }, { "internalType": "bytes32", "name": "_proof", "type": "bytes32" } ], "name": "addDeclaration", - "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ - { "internalType": "address", "name": "_subjectAddress", "type": "address" }, - { "internalType": "address", "name": "_objectAddress", "type": "address" } + { "internalType": "address", "name": "_declarator", "type": "address" }, + { "internalType": "address", "name": "_subject", "type": "address" } ], "name": "declaration", "outputs": [{ "internalType": "bytes32[]", "name": "", "type": "bytes32[]" }], @@ -21,7 +31,7 @@ }, { "inputs": [ - { "internalType": "address", "name": "_subjectAddress", "type": "address" }, + { "internalType": "address", "name": "_declarator", "type": "address" }, { "internalType": "uint256", "name": "_idx", "type": "uint256" } ], "name": "declarationAddressAt", @@ -30,7 +40,7 @@ "type": "function" }, { - "inputs": [{ "internalType": "address", "name": "_subjectAddress", "type": "address" }], + "inputs": [{ "internalType": "address", "name": "_declarator", "type": "address" }], "name": "declarationCount", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", @@ -38,7 +48,7 @@ }, { "inputs": [ - { "internalType": "address", "name": "_targetAddress", "type": "address" }, + { "internalType": "address", "name": "_subject", "type": "address" }, { "internalType": "uint256", "name": "_idx", "type": "uint256" } ], "name": "declaratorAddressAt", @@ -47,7 +57,7 @@ "type": "function" }, { - "inputs": [{ "internalType": "address", "name": "_objectAddress", "type": "address" }], + "inputs": [{ "internalType": "address", "name": "_subject", "type": "address" }], "name": "declaratorCount", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", diff --git a/src/assets/js/block-sync/data/ERC20.json b/src/assets/js/block-sync/data/ERC20.json index e2affcb..a4cf3d0 100644 --- a/src/assets/js/block-sync/data/ERC20.json +++ b/src/assets/js/block-sync/data/ERC20.json @@ -19,6 +19,17 @@ "name": "Transfer", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "_from", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "_to", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "_spender", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "_value", "type": "uint256" } + ], + "name": "TransferFrom", + "type": "event" + }, { "inputs": [ { "internalType": "address", "name": "_owner", "type": "address" }, @@ -39,17 +50,10 @@ "stateMutability": "nonpayable", "type": "function" }, - { - "inputs": [{ "internalType": "address", "name": "", "type": "address" }], - "name": "balanceOf", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, { "inputs": [], "name": "decimals", - "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, diff --git a/src/assets/js/block-sync/data/Registry.json b/src/assets/js/block-sync/data/Registry.json index 497cb29..ca53001 100644 --- a/src/assets/js/block-sync/data/Registry.json +++ b/src/assets/js/block-sync/data/Registry.json @@ -5,52 +5,5 @@ "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" - }, - { - "inputs": [{ "internalType": "bytes32", "name": "_identifier", "type": "bytes32" }], - "name": "chainOf", - "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [{ "internalType": "bytes32", "name": "_chain", "type": "bytes32" }], - "name": "configSumOf", - "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "identifiers", - "outputs": [{ "internalType": "bytes32[]", "name": "", "type": "bytes32[]" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "owner", - "outputs": [{ "internalType": "address", "name": "", "type": "address" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "seal", - "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "bytes32", "name": "_identifier", "type": "bytes32" }, - { "internalType": "address", "name": "_address", "type": "address" }, - { "internalType": "bytes32", "name": "_chainDescriptor", "type": "bytes32" }, - { "internalType": "bytes32", "name": "_chainConfig", "type": "bytes32" } - ], - "name": "set", - "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], - "stateMutability": "nonpayable", - "type": "function" } ] diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 3fa6650..e7af5b9 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -11,6 +11,6 @@ export const environment = { cicCacheUrl: 'https://cache.dev.grassrootseconomics.net', web3Provider: 'wss://bloxberg-ws.dev.grassrootseconomics.net', cicUssdUrl: 'https://ussd.dev.grassrootseconomics.net', - registryAddress: '0xAf1B487491073C2d49136Db3FD87E293302CF839', + registryAddress: '0xea6225212005e86a4490018ded4bf37f3e772161', trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C', }; diff --git a/src/index.html b/src/index.html index 83531d5..723b861 100644 --- a/src/index.html +++ b/src/index.html @@ -8,34 +8,34 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/manifest.webmanifest b/src/manifest.webmanifest index 306c464..0838ddd 100644 --- a/src/manifest.webmanifest +++ b/src/manifest.webmanifest @@ -19,13 +19,13 @@ ], "icons": [ { - "src": "src/assets/icons/manifest-icon-192.png", + "src": "assets/icons/manifest-icon-192.png", "sizes": "192x192", "type": "image/png", "purpose": "maskable any" }, { - "src": "src/assets/icons/manifest-icon-512.png", + "src": "assets/icons/manifest-icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable any"