From 87ee693f31c96af8df2515154b20b5292d7d38ce Mon Sep 17 00:00:00 2001 From: annakaz Date: Thu, 15 Aug 2019 15:11:05 -0700 Subject: [PATCH 01/21] Installing react-native-fbsdk --- .../app/src/main/java/org/celo/mobile/MainApplication.java | 4 +++- packages/mobile/android/settings.gradle | 2 ++ packages/mobile/package.json | 3 ++- yarn.lock | 5 +++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/mobile/android/app/src/main/java/org/celo/mobile/MainApplication.java b/packages/mobile/android/app/src/main/java/org/celo/mobile/MainApplication.java index d7d8bffc01a..c7abeb10c95 100644 --- a/packages/mobile/android/app/src/main/java/org/celo/mobile/MainApplication.java +++ b/packages/mobile/android/app/src/main/java/org/celo/mobile/MainApplication.java @@ -51,6 +51,7 @@ import me.furtado.smsretriever.RNSmsRetrieverPackage; import cl.json.RNSharePackage; import cl.json.ShareApplication; +import com.facebook.reactnative.androidsdk.FBSDKPackage; import android.util.Log; @@ -114,7 +115,8 @@ protected List getPackages() { new RNSystemClockPackage(), new RNRestartAndroidPackage(), new RNSmsRetrieverPackage(), - new RNSharePackage() + new RNSharePackage(), + new FBSDKPackage() // Disabled due to dex count // new RNScreensPackage(), }; diff --git a/packages/mobile/android/settings.gradle b/packages/mobile/android/settings.gradle index ea6f51a8924..eaf61d6ad82 100644 --- a/packages/mobile/android/settings.gradle +++ b/packages/mobile/android/settings.gradle @@ -65,4 +65,6 @@ include ':react-native-sms-retriever' project(':react-native-sms-retriever').projectDir = new File(rootProject.projectDir, '../../../node_modules/@celo/react-native-sms-retriever/android') include ':react-native-share' project(':react-native-share').projectDir = new File(rootProject.projectDir, '../../../node_modules/react-native-share/android') +include ':react-native-fbsdk' +project(':react-native-fbsdk').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fbsdk/android') include ':app' diff --git a/packages/mobile/package.json b/packages/mobile/package.json index 595f61e39fe..0c1032228c1 100644 --- a/packages/mobile/package.json +++ b/packages/mobile/package.json @@ -45,9 +45,9 @@ }, "dependencies": { "@celo/client": "f7095b7", - "@celo/walletkit": "^0.0.4", "@celo/react-native-sms-retriever": "git+https://github.com/celo-org/react-native-sms-retriever#d3a2fdb", "@celo/utils": "^0.0.5", + "@celo/walletkit": "^0.0.4", "@react-native-community/netinfo": "^2.0.4", "@segment/analytics-react-native": "^0.1.0-beta.0", "@segment/analytics-react-native-firebase": "^0.1.0-beta.0", @@ -89,6 +89,7 @@ "react-native-confirm-device-credentials": "^1.0.0", "react-native-contacts": "git://github.com/celo-org/react-native-contacts#4989b0b", "react-native-device-info": "^2.1.0", + "react-native-fbsdk": "^1.0.1", "react-native-firebase": "5.3.0", "react-native-flag-secure-android": "git://github.com/kristiansorens/react-native-flag-secure-android#e234251", "react-native-fs": "^2.12.1", diff --git a/yarn.lock b/yarn.lock index 2ca6ff22057..a9f7ed1fb4e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -24413,6 +24413,11 @@ react-native-device-info@^2.1.0: resolved "https://registry.yarnpkg.com/react-native-device-info/-/react-native-device-info-2.1.0.tgz#55eb82c1ba14c550cef6b71efc368d88b96b826a" integrity sha512-FdHFi0DtISiytXzE2KM16Qd4GPEGnbA8DjTP1vHjcUPFJCLBtm1P0/10Xn5x/kISjEvsz17grdtJxGrd83c6Pw== +react-native-fbsdk@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/react-native-fbsdk/-/react-native-fbsdk-1.0.1.tgz#0c34e519d4ef1c3d4b12c1b64dc645d719988ad8" + integrity sha512-5TNPOMb+Wq5Z7jmUHGF9f6WrmSl3LeKoZZcgTBUp6Qt/o7g1+VzbI3a9gCrGwJcvWZrdN8qlBhMNcwQ3y8ecyg== + react-native-firebase@5.3.0: version "5.3.0" resolved "https://registry.yarnpkg.com/react-native-firebase/-/react-native-firebase-5.3.0.tgz#3a5c31fa74c2edf9a1b82a62ae05b80dc976626e" From 23a9bc288eb00b17e1b9c7b715e157a66f078527 Mon Sep 17 00:00:00 2001 From: Nam Chu Hoai Date: Thu, 15 Aug 2019 15:15:43 -0700 Subject: [PATCH 02/21] Revert "Installing react-native-fbsdk" This reverts commit 9d145dade05b89da0fe40d25e8772b0537ad1701. --- .../app/src/main/java/org/celo/mobile/MainApplication.java | 4 +--- packages/mobile/android/settings.gradle | 2 -- packages/mobile/package.json | 3 +-- yarn.lock | 5 ----- 4 files changed, 2 insertions(+), 12 deletions(-) diff --git a/packages/mobile/android/app/src/main/java/org/celo/mobile/MainApplication.java b/packages/mobile/android/app/src/main/java/org/celo/mobile/MainApplication.java index c7abeb10c95..d7d8bffc01a 100644 --- a/packages/mobile/android/app/src/main/java/org/celo/mobile/MainApplication.java +++ b/packages/mobile/android/app/src/main/java/org/celo/mobile/MainApplication.java @@ -51,7 +51,6 @@ import me.furtado.smsretriever.RNSmsRetrieverPackage; import cl.json.RNSharePackage; import cl.json.ShareApplication; -import com.facebook.reactnative.androidsdk.FBSDKPackage; import android.util.Log; @@ -115,8 +114,7 @@ protected List getPackages() { new RNSystemClockPackage(), new RNRestartAndroidPackage(), new RNSmsRetrieverPackage(), - new RNSharePackage(), - new FBSDKPackage() + new RNSharePackage() // Disabled due to dex count // new RNScreensPackage(), }; diff --git a/packages/mobile/android/settings.gradle b/packages/mobile/android/settings.gradle index eaf61d6ad82..ea6f51a8924 100644 --- a/packages/mobile/android/settings.gradle +++ b/packages/mobile/android/settings.gradle @@ -65,6 +65,4 @@ include ':react-native-sms-retriever' project(':react-native-sms-retriever').projectDir = new File(rootProject.projectDir, '../../../node_modules/@celo/react-native-sms-retriever/android') include ':react-native-share' project(':react-native-share').projectDir = new File(rootProject.projectDir, '../../../node_modules/react-native-share/android') -include ':react-native-fbsdk' -project(':react-native-fbsdk').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fbsdk/android') include ':app' diff --git a/packages/mobile/package.json b/packages/mobile/package.json index 0c1032228c1..595f61e39fe 100644 --- a/packages/mobile/package.json +++ b/packages/mobile/package.json @@ -45,9 +45,9 @@ }, "dependencies": { "@celo/client": "f7095b7", + "@celo/walletkit": "^0.0.4", "@celo/react-native-sms-retriever": "git+https://github.com/celo-org/react-native-sms-retriever#d3a2fdb", "@celo/utils": "^0.0.5", - "@celo/walletkit": "^0.0.4", "@react-native-community/netinfo": "^2.0.4", "@segment/analytics-react-native": "^0.1.0-beta.0", "@segment/analytics-react-native-firebase": "^0.1.0-beta.0", @@ -89,7 +89,6 @@ "react-native-confirm-device-credentials": "^1.0.0", "react-native-contacts": "git://github.com/celo-org/react-native-contacts#4989b0b", "react-native-device-info": "^2.1.0", - "react-native-fbsdk": "^1.0.1", "react-native-firebase": "5.3.0", "react-native-flag-secure-android": "git://github.com/kristiansorens/react-native-flag-secure-android#e234251", "react-native-fs": "^2.12.1", diff --git a/yarn.lock b/yarn.lock index a9f7ed1fb4e..2ca6ff22057 100644 --- a/yarn.lock +++ b/yarn.lock @@ -24413,11 +24413,6 @@ react-native-device-info@^2.1.0: resolved "https://registry.yarnpkg.com/react-native-device-info/-/react-native-device-info-2.1.0.tgz#55eb82c1ba14c550cef6b71efc368d88b96b826a" integrity sha512-FdHFi0DtISiytXzE2KM16Qd4GPEGnbA8DjTP1vHjcUPFJCLBtm1P0/10Xn5x/kISjEvsz17grdtJxGrd83c6Pw== -react-native-fbsdk@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/react-native-fbsdk/-/react-native-fbsdk-1.0.1.tgz#0c34e519d4ef1c3d4b12c1b64dc645d719988ad8" - integrity sha512-5TNPOMb+Wq5Z7jmUHGF9f6WrmSl3LeKoZZcgTBUp6Qt/o7g1+VzbI3a9gCrGwJcvWZrdN8qlBhMNcwQ3y8ecyg== - react-native-firebase@5.3.0: version "5.3.0" resolved "https://registry.yarnpkg.com/react-native-firebase/-/react-native-firebase-5.3.0.tgz#3a5c31fa74c2edf9a1b82a62ae05b80dc976626e" From 02f772098c9439fdf7ea92e8331bbd65f711f23d Mon Sep 17 00:00:00 2001 From: Mariano Cortesi Date: Thu, 15 Aug 2019 21:15:09 -0300 Subject: [PATCH 03/21] New ContractKit (#480) Implemented features: -yarn build on protocol generates code for contractkit -cleanup protocol build -yarn build on root pkg breaks if contractkit doesn't compile with generated code -Fetch addresses from registry (only once) -Expose all web3 contract wrappers & cache them -Framework to create wrappers -Celo Wrappers for BondedDeposits, Exchange, Validators, GoldToken, StableToken -Contract kit is instantiable, can have many instances in one process -sendTransaction ported from walletkit Missing: Test, complete Wrappers, validate API Other changes -Cleanup protocol build process. - Fix celo/utils npm publish - hoist ts-node to the root package - Related issues Fixes #360 #359 #333 #257 --- .prettierignore | 2 + package.json | 8 +- packages/celotool/package.json | 3 +- packages/cli/package.json | 2 +- packages/contractkit/.gitignore | 3 + packages/contractkit/.npmignore | 7 + packages/contractkit/jest.config.js | 7 + packages/contractkit/package.json | 38 +++++ packages/contractkit/src/address-registry.ts | 37 +++++ packages/contractkit/src/base.ts | 27 ++++ packages/contractkit/src/contract-cache.ts | 104 +++++++++++++ packages/contractkit/src/index.ts | 8 + packages/contractkit/src/kit.ts | 74 +++++++++ .../contractkit/src/utils/external-promise.ts | 11 ++ packages/contractkit/src/utils/send-tx.ts | 51 ++++++ packages/contractkit/src/utils/tx-result.ts | 44 ++++++ .../contractkit/src/web3-contract-cache.ts | 102 ++++++++++++ .../contractkit/src/wrappers/BaseWrapper.ts | 39 +++++ .../src/wrappers/BondedDeposits.ts | 130 ++++++++++++++++ packages/contractkit/src/wrappers/Exchange.ts | 15 ++ .../src/wrappers/GoldTokenWrapper.ts | 16 ++ .../src/wrappers/StableTokenWrapper.ts | 23 +++ .../contractkit/src/wrappers/Validators.ts | 145 ++++++++++++++++++ packages/contractkit/test/tsconfig.json | 10 ++ packages/contractkit/tsconfig.json | 8 + packages/contractkit/tslint.json | 7 + packages/contractkit/types/web3.d.ts | 8 + packages/dappkit/package.json | 2 +- packages/mobile/package.json | 3 +- packages/protocol/lib/concrete-contracts.ts | 38 ----- packages/protocol/package.json | 7 +- packages/protocol/scripts/build.ts | 143 +++++++++++++++++ .../scripts/typescript/check-bytecode.ts | 35 ----- packages/react-components/package.json | 2 +- packages/typescript/tsconfig.library.json | 20 +++ packages/utils/.npmignore | 6 + packages/utils/package.json | 4 +- packages/utils/src/address.ts | 5 + packages/utils/src/bn.ts | 11 ++ packages/utils/src/collections.ts | 9 ++ packages/verification-pool-api/package.json | 1 - packages/verifier/package.json | 2 +- packages/walletkit/package.json | 2 +- packages/web/package.json | 1 - yarn.lock | 16 ++ 45 files changed, 1144 insertions(+), 92 deletions(-) create mode 100644 packages/contractkit/.gitignore create mode 100644 packages/contractkit/.npmignore create mode 100644 packages/contractkit/jest.config.js create mode 100644 packages/contractkit/package.json create mode 100644 packages/contractkit/src/address-registry.ts create mode 100644 packages/contractkit/src/base.ts create mode 100644 packages/contractkit/src/contract-cache.ts create mode 100644 packages/contractkit/src/index.ts create mode 100644 packages/contractkit/src/kit.ts create mode 100644 packages/contractkit/src/utils/external-promise.ts create mode 100644 packages/contractkit/src/utils/send-tx.ts create mode 100644 packages/contractkit/src/utils/tx-result.ts create mode 100644 packages/contractkit/src/web3-contract-cache.ts create mode 100644 packages/contractkit/src/wrappers/BaseWrapper.ts create mode 100644 packages/contractkit/src/wrappers/BondedDeposits.ts create mode 100644 packages/contractkit/src/wrappers/Exchange.ts create mode 100644 packages/contractkit/src/wrappers/GoldTokenWrapper.ts create mode 100644 packages/contractkit/src/wrappers/StableTokenWrapper.ts create mode 100644 packages/contractkit/src/wrappers/Validators.ts create mode 100644 packages/contractkit/test/tsconfig.json create mode 100644 packages/contractkit/tsconfig.json create mode 100644 packages/contractkit/tslint.json create mode 100644 packages/contractkit/types/web3.d.ts delete mode 100644 packages/protocol/lib/concrete-contracts.ts create mode 100644 packages/protocol/scripts/build.ts delete mode 100644 packages/protocol/scripts/typescript/check-bytecode.ts create mode 100644 packages/typescript/tsconfig.library.json create mode 100644 packages/utils/.npmignore create mode 100644 packages/utils/src/address.ts create mode 100644 packages/utils/src/bn.ts create mode 100644 packages/utils/src/collections.ts diff --git a/.prettierignore b/.prettierignore index 89bbc62ec64..0bd1d8c2574 100644 --- a/.prettierignore +++ b/.prettierignore @@ -9,6 +9,8 @@ packages/blockchain-api/dist packages/cli/lib +packages/contractkit/lib/ + packages/walletkit/lib/ packages/walletkit/.artifacts/ packages/walletkit/contracts/ diff --git a/package.json b/package.json index e8413e51915..29254db28ed 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ ] }, "devDependencies": { + "@types/jest": "^24.0.13", "husky": "^3.0.0", "lerna": "^3.16.0", "patch-package": "^5.1.1", @@ -51,7 +52,12 @@ "pretty-quick": "^1.11.1", "solc": "0.5.8", "tslint": "^5.12.1", - "typescript-tslint-plugin": "^0.5.0" + "typescript": "^3.3.3", + "jest": "^24.8.0", + "ts-jest": "^24.0.0", + "typescript-tslint-plugin": "^0.5.0", + "tsconfig-paths": "^3.8.0", + "ts-node": "^8" }, "dependencies": { "codecov": "^3.1.0" diff --git a/packages/celotool/package.json b/packages/celotool/package.json index 116bcc3c552..60b144b709f 100644 --- a/packages/celotool/package.json +++ b/packages/celotool/package.json @@ -38,8 +38,7 @@ "@types/web3": "^1.0.18", "@types/yargs": "^12.0.1", "jest": "^24.8.0", - "ts-jest": "^24.0.0", - "ts-node": "^7.0.1" + "ts-jest": "^24.0.0" }, "scripts": { "cli": "TS_NODE_FILES=true ts-node -r tsconfig-paths/register src/cli.ts", diff --git a/packages/cli/package.json b/packages/cli/package.json index 514d645dc57..8d2bbaf9488 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -60,7 +60,7 @@ "@types/node": "^10", "@types/web3": "^1.0.18", "globby": "^8", - "ts-node": "^8", + "tslint": "^5", "typescript": "^3.3.3" }, diff --git a/packages/contractkit/.gitignore b/packages/contractkit/.gitignore new file mode 100644 index 00000000000..aa84bca4682 --- /dev/null +++ b/packages/contractkit/.gitignore @@ -0,0 +1,3 @@ +src/generated +tsconfig.tsbuildinfo +lib/ \ No newline at end of file diff --git a/packages/contractkit/.npmignore b/packages/contractkit/.npmignore new file mode 100644 index 00000000000..5d78b5e0908 --- /dev/null +++ b/packages/contractkit/.npmignore @@ -0,0 +1,7 @@ +/node_modules +/coverage +/tslint.json +/tsconfig.json +/test +/src +/jest.config.json \ No newline at end of file diff --git a/packages/contractkit/jest.config.js b/packages/contractkit/jest.config.js new file mode 100644 index 00000000000..2589a882341 --- /dev/null +++ b/packages/contractkit/jest.config.js @@ -0,0 +1,7 @@ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', + moduleNameMapper: { + '^src/(.*)$': '/src/$1', + }, +} diff --git a/packages/contractkit/package.json b/packages/contractkit/package.json new file mode 100644 index 00000000000..05c596654ac --- /dev/null +++ b/packages/contractkit/package.json @@ -0,0 +1,38 @@ +{ + "name": "@celo/contractkit", + "version": "0.0.5-beta3", + "description": "Celo's ContractKit to interact with Celo network", + "main": "./lib/index.js", + "types": "./lib/index.d.ts", + "author": "Celo", + "license": "Apache-2.0", + "homepage": "https://github.com/celo-org/celo-monorepo/tree/master/packages/contractkit", + "repository": "https://github.com/celo-org/celo-monorepo/tree/master/packages/contractkit", + "keywords": ["celo", "blockchain", "contractkit", "defi"], + "scripts": { + "build": "tsc -b .", + "clean": "tsc -b . --clean && rm -rf src/generated", + "build:gen": "yarn --cwd ../protocol build", + "prepublishOnly": "yarn build:gen && yarn build", + "lint": "tslint -c tslint.json --project . && tslint -c tslint.json --project test" + }, + "dependencies": { + "@celo/utils": "^0.0.6-beta3", + "@types/debug": "^4.1.5", + "bignumber.js": "^7.2.0", + "debug": "^4.1.1", + "web3": "1.0.0-beta.37", + "web3-utils": "1.0.0-beta.37" + }, + "devDependencies": { + "@celo/protocol": "1.0.0", + "@types/jest": "^24.0.13", + "@types/web3": "^1.0.18" + }, + "engines": { + "node": ">=8.16.0" + }, + "files": [ + "lib/**/*" + ] +} diff --git a/packages/contractkit/src/address-registry.ts b/packages/contractkit/src/address-registry.ts new file mode 100644 index 00000000000..c05136357c7 --- /dev/null +++ b/packages/contractkit/src/address-registry.ts @@ -0,0 +1,37 @@ +import { Address, AllContracts, CeloContract, NULL_ADDRESS } from './base' +import { newRegistry } from './generated/Registry' +import { Registry } from './generated/types/Registry' +import { ContractKit } from './kit' + +// Registry contract is always predeployed to this address +const REGISTRY_CONTRACT_ADDRESS = '0x000000000000000000000000000000000000ce10' + +export class AddressRegistry { + private readonly registry: Registry + private readonly cache: Map = new Map() + + constructor(kit: ContractKit) { + this.cache.set(CeloContract.Registry, REGISTRY_CONTRACT_ADDRESS) + this.registry = newRegistry(kit.web3, REGISTRY_CONTRACT_ADDRESS) + } + + async addressFor(contract: CeloContract): Promise
{ + if (!this.cache.has(contract)) { + const address = await this.registry.methods.getAddressFor(contract).call() + + if (!address || address === NULL_ADDRESS) { + throw new Error(`Failed to get address for ${contract} from the Registry`) + } + this.cache.set(contract, address) + } + return this.cache.get(contract)! + } + + async allAddresses(): Promise> { + const res: Partial> = {} + for (const contract of AllContracts) { + res[contract] = await this.addressFor(contract) + } + return res as Record + } +} diff --git a/packages/contractkit/src/base.ts b/packages/contractkit/src/base.ts new file mode 100644 index 00000000000..d843e0b6818 --- /dev/null +++ b/packages/contractkit/src/base.ts @@ -0,0 +1,27 @@ +export type Address = string + +export enum CeloContract { + Attestations = 'Attestations', + BondedDeposits = 'BondedDeposits', + Escrow = 'Escrow', + Exchange = 'Exchange', + GasCurrencyWhitelist = 'GasCurrencyWhitelist', + GasPriceMinimum = 'GasPriceMinimum', + GoldToken = 'GoldToken', + Governance = 'Governance', + MultiSig = 'MultiSig', + Random = 'Random', + Registry = 'Registry', + Reserve = 'Reserve', + SortedOracles = 'SortedOracles', + StableToken = 'StableToken', + Validators = 'Validators', +} + +export type CeloToken = CeloContract.GoldToken | CeloContract.StableToken + +export const AllContracts = Object.keys(CeloContract).map( + (k) => CeloContract[k as any] +) as CeloContract[] + +export const NULL_ADDRESS = '0x0000000000000000000000000000000000000000' as Address diff --git a/packages/contractkit/src/contract-cache.ts b/packages/contractkit/src/contract-cache.ts new file mode 100644 index 00000000000..d02267155a9 --- /dev/null +++ b/packages/contractkit/src/contract-cache.ts @@ -0,0 +1,104 @@ +import { CeloContract } from './base' +import { ContractKit } from './kit' +import { BondedDepositsWrapper } from './wrappers/BondedDeposits' +import { ExchangeWrapper } from './wrappers/Exchange' +import { GoldTokenWrapper } from './wrappers/GoldTokenWrapper' +import { StableTokenWrapper } from './wrappers/StableTokenWrapper' +import { ValidatorsWrapper } from './wrappers/Validators' + +const WrapperFactories = { + // [CeloContract.Attestations]: AttestationsWrapper, + [CeloContract.BondedDeposits]: BondedDepositsWrapper, + // [CeloContract.Escrow]: EscrowWrapper, + [CeloContract.Exchange]: ExchangeWrapper, + // [CeloContract.GasCurrencyWhitelist]: GasCurrencyWhitelistWrapper, + // [CeloContract.GasPriceMinimum]: GasPriceMinimumWrapper, + [CeloContract.GoldToken]: GoldTokenWrapper, + // [CeloContract.Governance]: GovernanceWrapper, + // [CeloContract.MultiSig]: MultiSigWrapper, + // [CeloContract.Random]: RandomWrapper, + // [CeloContract.Registry]: RegistryWrapper, + // [CeloContract.Reserve]: ReserveWrapper, + // [CeloContract.SortedOracles]: SortedOraclesWrapper, + [CeloContract.StableToken]: StableTokenWrapper, + [CeloContract.Validators]: ValidatorsWrapper, +} + +type CFType = typeof WrapperFactories + +interface WrapperCacheMap { + // [CeloContract.Attestations]?: AttestationsWrapper, + [CeloContract.BondedDeposits]?: BondedDepositsWrapper + // [CeloContract.Escrow]?: EscrowWrapper, + [CeloContract.Exchange]?: ExchangeWrapper + // [CeloContract.GasCurrencyWhitelist]?: GasCurrencyWhitelistWrapper, + // [CeloContract.GasPriceMinimum]?: GasPriceMinimumWrapper, + [CeloContract.GoldToken]?: GoldTokenWrapper + // [CeloContract.Governance]?: GovernanceWrapper, + // [CeloContract.MultiSig]?: MultiSigWrapper, + // [CeloContract.Random]?: RandomWrapper, + // [CeloContract.Registry]?: RegistryWrapper, + // [CeloContract.Reserve]?: ReserveWrapper, + // [CeloContract.SortedOracles]?: SortedOraclesWrapper, + [CeloContract.StableToken]?: StableTokenWrapper + [CeloContract.Validators]?: ValidatorsWrapper +} + +export class WrapperCache { + // private wrapperCache: Map = new Map() + private wrapperCache: WrapperCacheMap = {} + + constructor(readonly kit: ContractKit) {} + + // getAttestations() { + // return this.getWrapper(CeloContract.Attestations, newAttestations) + // } + getBondedDeposits() { + return this.getContract(CeloContract.BondedDeposits) + } + // getEscrow() { + // return this.getWrapper(CeloContract.Escrow, newEscrow) + // } + getExchange() { + return this.getContract(CeloContract.Exchange) + } + // getGasCurrencyWhitelist() { + // return this.getWrapper(CeloContract.GasCurrencyWhitelist, newGasCurrencyWhitelist) + // } + // getGasPriceMinimum() { + // return this.getWrapper(CeloContract.GasPriceMinimum, newGasPriceMinimum) + // } + getGoldToken() { + return this.getContract(CeloContract.GoldToken) + } + // getGovernance() { + // return this.getWrapper(CeloContract.Governance, newGovernance) + // } + // getMultiSig() { + // return this.getWrapper(CeloContract.MultiSig, newMultiSig) + // } + // getRegistry() { + // return this.getWrapper(CeloContract.Registry, newRegistry) + // } + // getReserve() { + // return this.getWrapper(CeloContract.Reserve, newReserve) + // } + // getSortedOracles() { + // return this.getWrapper(CeloContract.SortedOracles, newSortedOracles) + // } + getStableToken() { + return this.getContract(CeloContract.StableToken) + } + getValidators() { + return this.getContract(CeloContract.Validators) + } + + public async getContract(contract: C) { + if (this.wrapperCache[contract] == null) { + const instance = await this.kit._web3Contracts.getContract(contract) + const Klass: CFType[C] = WrapperFactories[contract] + this.wrapperCache[contract] = new Klass(this.kit, instance as any) as any + } + return this.wrapperCache[contract]! + } +} diff --git a/packages/contractkit/src/index.ts b/packages/contractkit/src/index.ts new file mode 100644 index 00000000000..27008311655 --- /dev/null +++ b/packages/contractkit/src/index.ts @@ -0,0 +1,8 @@ +import Web3 from 'web3' + +export { Address, CeloContract, CeloToken, NULL_ADDRESS } from './base' +export * from './kit' + +export function newWeb3(url: string) { + return new Web3(url) +} diff --git a/packages/contractkit/src/kit.ts b/packages/contractkit/src/kit.ts new file mode 100644 index 00000000000..b23b43b6124 --- /dev/null +++ b/packages/contractkit/src/kit.ts @@ -0,0 +1,74 @@ +import Web3 from 'web3' +import { TransactionObject, Tx } from 'web3/eth/types' +import { AddressRegistry } from './address-registry' +import { Address, CeloContract, CeloToken } from './base' +import { WrapperCache } from './contract-cache' +import { sendTransaction, TxOptions } from './utils/send-tx' +import { toTxResult, TransactionResult } from './utils/tx-result' +import { Web3ContractCache } from './web3-contract-cache' + +export function newKit(url: string) { + return newKitFromWeb3(new Web3(url)) +} + +export function newKitFromWeb3(web3: Web3) { + return new ContractKit(web3) +} + +export class ContractKit { + readonly registry: AddressRegistry + readonly _web3Contracts: Web3ContractCache + readonly contracts: WrapperCache + + defaultOptions: TxOptions + constructor(readonly web3: Web3) { + this.defaultOptions = { + gasInflationFactor: 1.3, + } + + this.registry = new AddressRegistry(this) + this._web3Contracts = new Web3ContractCache(this) + this.contracts = new WrapperCache(this) + } + + async setGasCurrency(token: CeloToken) { + this.defaultOptions.gasCurrency = + token === CeloContract.GoldToken ? undefined : await this.registry.addressFor(token) + } + + set defaultAccount(address: Address) { + this.web3.eth.defaultAccount = address + } + + get defaultAccount(): Address { + return this.web3.eth.defaultAccount + } + + setGasCurrencyAddress(address: Address) { + this.defaultOptions.gasCurrency = address + } + + sendTransaction(tx: Tx): TransactionResult { + const promiEvent = this.web3.eth.sendTransaction({ + from: this.defaultOptions.from, + // TODO this won't work for locally signed TX + gasPrice: '0', + // @ts-ignore + gasCurrency: this.defaultOptions.gasCurrency, + // TODO needed for locally signed tx, ignored by now (celo-blockchain with set it) + // gasFeeRecipient: this.defaultOptions.gasFeeRecipient, + ...tx, + }) + return toTxResult(promiEvent) + } + + sendTransactionObject( + txObj: TransactionObject, + options?: TxOptions + ): Promise { + return sendTransaction(txObj, { + ...this.defaultOptions, + ...options, + }) + } +} diff --git a/packages/contractkit/src/utils/external-promise.ts b/packages/contractkit/src/utils/external-promise.ts new file mode 100644 index 00000000000..a02c8329174 --- /dev/null +++ b/packages/contractkit/src/utils/external-promise.ts @@ -0,0 +1,11 @@ +export class ExternalPromise extends Promise { + public resolve!: (value: T) => void + public reject!: (err: any) => void + + constructor() { + super((resolve, reject) => { + this.resolve = resolve + this.reject = reject + }) + } +} diff --git a/packages/contractkit/src/utils/send-tx.ts b/packages/contractkit/src/utils/send-tx.ts new file mode 100644 index 00000000000..05cccc43185 --- /dev/null +++ b/packages/contractkit/src/utils/send-tx.ts @@ -0,0 +1,51 @@ +import debugFactory from 'debug' +import { TransactionObject } from 'web3/eth/types' +import { Address } from '../base' +import { toTxResult, TransactionResult } from './tx-result' + +const debug = debugFactory('contractkit:sendtx') + +export interface TxOptions { + gasInflationFactor?: number + gasFeeRecipient?: Address + gasCurrency?: Address | undefined + from?: Address + estimatedGas?: number | undefined +} + +/** + * sendTransaction mainly abstracts the sending of a transaction in a promise like + * interface. + */ +export async function sendTransaction( + tx: TransactionObject, + txOptions: TxOptions = {} +): Promise { + const txParams: any = { + from: txOptions.from, + gasCurrency: txOptions.gasCurrency, + gasPrice: '0', + } + + let gas = txOptions.estimatedGas + if (gas === undefined) { + const inflactionFactor = txOptions.gasInflationFactor || 1 + gas = Math.round((await tx.estimateGas(txParams)) * inflactionFactor) + debug('estimatedGas: %s', gas) + // logger(EstimatedGas(estimatedGas)) + } + + const promiEvent = tx.send({ + from: txOptions.from, + // @ts-ignore + gasCurrency: txOptions.gasCurrency, + // TODO needed for locally signed tx, ignored by now (celo-blockchain with set it) + // gasFeeRecipient: txOptions.gasFeeRecipient, + gas, + // Hack to prevent web3 from adding the suggested gold gas price, allowing geth to add + // the suggested price in the selected gasCurrency. + // TODO this won't work for locally signed TX + gasPrice: '0', + }) + return toTxResult(promiEvent) +} diff --git a/packages/contractkit/src/utils/tx-result.ts b/packages/contractkit/src/utils/tx-result.ts new file mode 100644 index 00000000000..f4736c5e04b --- /dev/null +++ b/packages/contractkit/src/utils/tx-result.ts @@ -0,0 +1,44 @@ +import debugFactory from 'debug' +import PromiEvent from 'web3/promiEvent' +import { TransactionReceipt } from 'web3/types' +import { ExternalPromise } from './external-promise' + +const debug = debugFactory('contractkit:txresult') + +export function toTxResult(pe: PromiEvent) { + return new TransactionResult(pe) +} + +export class TransactionResult { + private hashFuture = new ExternalPromise() + private receiptFuture = new ExternalPromise() + + constructor(pe: PromiEvent) { + pe.on('transactionHash', (hash: string) => { + debug('hash: %s', hash) + this.hashFuture.resolve(hash) + }) + .on('receipt', (receipt: TransactionReceipt) => { + debug('receipt: %O', receipt) + this.receiptFuture.resolve(receipt) + }) + + .on('error', ((error: any, receipt: TransactionReceipt | false) => { + if (!receipt) { + debug('send-error: %o', error) + this.hashFuture.reject(error) + } else { + debug('mining-error: %o, %O', error, receipt) + } + this.receiptFuture.reject(error) + }) as any) + } + + getHash() { + return this.hashFuture + } + + waitReceipt() { + return this.receiptFuture + } +} diff --git a/packages/contractkit/src/web3-contract-cache.ts b/packages/contractkit/src/web3-contract-cache.ts new file mode 100644 index 00000000000..8c23e43551c --- /dev/null +++ b/packages/contractkit/src/web3-contract-cache.ts @@ -0,0 +1,102 @@ +import { CeloContract } from './base' +import { newAttestations } from './generated/Attestations' +import { newBondedDeposits } from './generated/BondedDeposits' +import { newEscrow } from './generated/Escrow' +import { newExchange } from './generated/Exchange' +import { newGasCurrencyWhitelist } from './generated/GasCurrencyWhitelist' +import { newGasPriceMinimum } from './generated/GasPriceMinimum' +import { newGoldToken } from './generated/GoldToken' +import { newGovernance } from './generated/Governance' +import { newMultiSig } from './generated/MultiSig' +import { newRandom } from './generated/Random' +import { newRegistry } from './generated/Registry' +import { newReserve } from './generated/Reserve' +import { newSortedOracles } from './generated/SortedOracles' +import { newStableToken } from './generated/StableToken' +import { newValidators } from './generated/Validators' +import { ContractKit } from './kit' + +const ContractFactories = { + [CeloContract.Attestations]: newAttestations, + [CeloContract.BondedDeposits]: newBondedDeposits, + [CeloContract.Escrow]: newEscrow, + [CeloContract.Exchange]: newExchange, + [CeloContract.GasCurrencyWhitelist]: newGasCurrencyWhitelist, + [CeloContract.GasPriceMinimum]: newGasPriceMinimum, + [CeloContract.GoldToken]: newGoldToken, + [CeloContract.Governance]: newGovernance, + [CeloContract.MultiSig]: newMultiSig, + [CeloContract.Random]: newRandom, + [CeloContract.Registry]: newRegistry, + [CeloContract.Reserve]: newReserve, + [CeloContract.SortedOracles]: newSortedOracles, + [CeloContract.StableToken]: newStableToken, + [CeloContract.Validators]: newValidators, +} + +type CFType = typeof ContractFactories +type ContractCacheMap = { [K in keyof CFType]?: ReturnType } + +export class Web3ContractCache { + private cacheMap: ContractCacheMap = {} + + constructor(readonly kit: ContractKit) {} + + getAttestations() { + return this.getContract(CeloContract.Attestations) + } + getBondedDeposits() { + return this.getContract(CeloContract.BondedDeposits) + } + getEscrow() { + return this.getContract(CeloContract.Escrow) + } + getExchange() { + return this.getContract(CeloContract.Exchange) + } + getGasCurrencyWhitelist() { + return this.getContract(CeloContract.GasCurrencyWhitelist) + } + getGasPriceMinimum() { + return this.getContract(CeloContract.GasPriceMinimum) + } + getGoldToken() { + return this.getContract(CeloContract.GoldToken) + } + getGovernance() { + return this.getContract(CeloContract.Governance) + } + getMultiSig() { + return this.getContract(CeloContract.MultiSig) + } + getRandom() { + return this.getContract(CeloContract.Random) + } + getRegistry() { + return this.getContract(CeloContract.Registry) + } + getReserve() { + return this.getContract(CeloContract.Reserve) + } + getSortedOracles() { + return this.getContract(CeloContract.SortedOracles) + } + getStableToken() { + return this.getContract(CeloContract.StableToken) + } + getValidators() { + return this.getContract(CeloContract.Validators) + } + + async getContract(contract: C) { + if (this.cacheMap[contract] == null) { + const createFn = ContractFactories[contract] as CFType[C] + this.cacheMap[contract] = createFn( + this.kit.web3, + await this.kit.registry.addressFor(contract) + ) as NonNullable + } + // we know it's defined (thus the !) + return this.cacheMap[contract]! + } +} diff --git a/packages/contractkit/src/wrappers/BaseWrapper.ts b/packages/contractkit/src/wrappers/BaseWrapper.ts new file mode 100644 index 00000000000..7327539d4b5 --- /dev/null +++ b/packages/contractkit/src/wrappers/BaseWrapper.ts @@ -0,0 +1,39 @@ +import { TransactionObject } from 'web3/eth/types' +import { ContractKit } from '../kit' +import { TxOptions } from '../utils/send-tx' +import { TransactionResult } from '../utils/tx-result' + +type Method = (...args: I) => TransactionObject + +export abstract class BaseWrapper { + constructor(protected readonly kit: ContractKit, protected readonly contract: T) {} + + protected proxySend(methodFn: Method) { + return (...args: I) => this.wrapSend(methodFn(...args)) + } + protected proxyCall(methodFn: Method) { + return (...args: I) => methodFn(...args).call() + } + + protected proxyCallAndTransform( + methodFn: Method, + post: (input: O) => F + ) { + return (...args: I) => + methodFn(...args) + .call() + .then(post) + } + + protected wrapSend(txo: TransactionObject): CeloTransactionObject { + return { + send: (options?: TxOptions) => this.kit.sendTransactionObject(txo, options), + txo, + } + } +} + +export interface CeloTransactionObject { + txo: TransactionObject + send(options?: TxOptions): Promise +} diff --git a/packages/contractkit/src/wrappers/BondedDeposits.ts b/packages/contractkit/src/wrappers/BondedDeposits.ts new file mode 100644 index 00000000000..1f711de8b48 --- /dev/null +++ b/packages/contractkit/src/wrappers/BondedDeposits.ts @@ -0,0 +1,130 @@ +import { zip } from '@celo/utils/lib/src/collections' +import BN from 'bn.js' +import Web3 from 'web3' +import { TransactionObject } from 'web3/eth/types' +import { Address } from '../base' +import { BondedDeposits } from '../generated/types/BondedDeposits' +import { BaseWrapper } from '../wrappers/BaseWrapper' + +export interface VotingDetails { + accountAddress: Address + voterAddress: Address + weight: BN +} + +interface Deposit { + time: BN + value: BN +} + +export interface Deposits { + bonded: Deposit[] + notified: Deposit[] + total: { + gold: BN + weight: BN + } +} + +enum Roles { + validating, + voting, + rewards, +} + +export class BondedDepositsWrapper extends BaseWrapper { + async getAccountWeight(account: Address): Promise { + const accountWeight = await this.contract.methods.getAccountWeight(account).call() + return Web3.utils.toBN(accountWeight) + } + + async getVotingDetails(accountOrVoterAddress: Address): Promise { + const accountAddress = await this.contract.methods + .getAccountFromDelegateAndRole(accountOrVoterAddress, Roles.voting) + .call() + + return { + accountAddress, + voterAddress: accountOrVoterAddress, + weight: await this.getAccountWeight(accountAddress), + } + } + + async getBondedDepositValue(account: string, noticePeriod: string): Promise { + const deposit = await this.contract.methods.getBondedDeposit(account, noticePeriod).call() + return this.getValueFromDeposit(deposit) + } + + async getBondedDeposits(account: string): Promise { + return this.zipAccountTimesAndValuesToDeposits( + account, + this.contract.methods.getNoticePeriods, + this.getBondedDepositValue.bind(this) + ) + } + + async getNotifiedDepositValue(account: string, availTime: string): Promise { + const deposit = await this.contract.methods.getNotifiedDeposit(account, availTime).call() + return this.getValueFromDeposit(deposit) + } + + async getNotifiedDeposits(account: string): Promise { + return this.zipAccountTimesAndValuesToDeposits( + account, + this.contract.methods.getAvailabilityTimes, + this.getNotifiedDepositValue.bind(this) + ) + } + + async getDeposits(account: string): Promise { + const bonded = await this.getBondedDeposits(account) + const notified = await this.getNotifiedDeposits(account) + const weight = await this.getAccountWeight(account) + + let gold = new BN(0) + bonded.forEach((bond) => (gold = gold.add(bond.value))) + notified.forEach((bond) => (gold = gold.add(bond.value))) + + return { + bonded, + notified, + total: { weight, gold }, + } + } + + // FIXME this.contract.methods.delegateRewards does not exist + async delegateRewardsTx(account: string, delegate: string): Promise> { + const sig = await this.getParsedSignatureOfAddress(account, delegate) + + return this.contract.methods.delegateRole(Roles.rewards, delegate, sig.v, sig.r, sig.s) + } + + private getValueFromDeposit(deposit: { 0: string; 1: string }) { + return Web3.utils.toBN(deposit[0]) + } + + private async getParsedSignatureOfAddress(address: string, signer: string) { + const hash = Web3.utils.soliditySha3({ type: 'address', value: address }) + const signature = (await this.kit.web3.eth.sign(hash, signer)).slice(2) + return { + r: `0x${signature.slice(0, 64)}`, + s: `0x${signature.slice(64, 128)}`, + v: Web3.utils.hexToNumber(signature.slice(128, 130)) + 27, + } + } + + private async zipAccountTimesAndValuesToDeposits( + account: string, + timesFunc: (account: string) => TransactionObject, + valueFunc: (account: string, time: string) => Promise + ) { + const accountTimes = await timesFunc(account).call() + const accountValues = await Promise.all(accountTimes.map((time) => valueFunc(account, time))) + return zip( + // tslint:disable-next-line: no-object-literal-type-assertion + (time, value) => ({ time, value } as Deposit), + accountTimes.map((time) => Web3.utils.toBN(time)), + accountValues + ) + } +} diff --git a/packages/contractkit/src/wrappers/Exchange.ts b/packages/contractkit/src/wrappers/Exchange.ts new file mode 100644 index 00000000000..1e4218b64c8 --- /dev/null +++ b/packages/contractkit/src/wrappers/Exchange.ts @@ -0,0 +1,15 @@ +import { Exchange } from '../generated/types/Exchange' +import { BaseWrapper } from './BaseWrapper' + +export class ExchangeWrapper extends BaseWrapper { + getBuyTokenAmount = this.proxyCall(this.contract.methods.getBuyTokenAmount) + + getSellTokenAmount = this.proxyCall(this.contract.methods.getSellTokenAmount) + + getBuyAndSellBuckets = this.proxyCallAndTransform( + this.contract.methods.getBuyAndSellBuckets, + (callRes) => [callRes[0], callRes[1]] as [string, string] + ) + + exchange = this.proxySend(this.contract.methods.exchange) +} diff --git a/packages/contractkit/src/wrappers/GoldTokenWrapper.ts b/packages/contractkit/src/wrappers/GoldTokenWrapper.ts new file mode 100644 index 00000000000..3e16a9750c1 --- /dev/null +++ b/packages/contractkit/src/wrappers/GoldTokenWrapper.ts @@ -0,0 +1,16 @@ +import { Address } from '../base' +import { GoldToken } from '../generated/types/GoldToken' +import { BaseWrapper } from './BaseWrapper' + +export class GoldTokenWrapper extends BaseWrapper { + allowance = this.proxyCall(this.contract.methods.allowance) + name = this.proxyCall(this.contract.methods.name) + symbol = this.proxyCall(this.contract.methods.symbol) + decimals = this.proxyCall(this.contract.methods.decimals) + totalSupply = this.proxyCall(this.contract.methods.totalSupply) + approve = this.proxySend(this.contract.methods.approve) + transferWithComment = this.proxySend(this.contract.methods.transferWithComment) + transfer = this.proxySend(this.contract.methods.transfer) + transferFrom = this.proxySend(this.contract.methods.transferFrom) + balanceOf = (account: Address) => this.kit.web3.eth.getBalance(account) +} diff --git a/packages/contractkit/src/wrappers/StableTokenWrapper.ts b/packages/contractkit/src/wrappers/StableTokenWrapper.ts new file mode 100644 index 00000000000..3cf2446aba7 --- /dev/null +++ b/packages/contractkit/src/wrappers/StableTokenWrapper.ts @@ -0,0 +1,23 @@ +import { StableToken } from '../generated/types/StableToken' +import { BaseWrapper } from './BaseWrapper' + +export class StableTokenWrapper extends BaseWrapper { + allowance = this.proxyCall(this.contract.methods.allowance) + balanceOf = this.proxyCall(this.contract.methods.balanceOf) + minter = this.proxyCall(this.contract.methods.minter) + name = this.proxyCall(this.contract.methods.name) + symbol = this.proxyCall(this.contract.methods.symbol) + decimals = this.proxyCall(this.contract.methods.decimals) + owner = this.proxyCall(this.contract.methods.owner) + totalSupply = this.proxyCall(this.contract.methods.totalSupply) + getInflationParameters = this.proxyCall(this.contract.methods.getInflationParameters) + valueToUnits = this.proxyCall(this.contract.methods.valueToUnits) + unitsToValue = this.proxyCall(this.contract.methods.unitsToValue) + approve = this.proxySend(this.contract.methods.approve) + mint = this.proxySend(this.contract.methods.mint) + burn = this.proxySend(this.contract.methods.burn) + transferWithComment = this.proxySend(this.contract.methods.transferWithComment) + transfer = this.proxySend(this.contract.methods.transfer) + transferFrom = this.proxySend(this.contract.methods.transferFrom) + setInflationParameters = this.proxySend(this.contract.methods.setInflationParameters) +} diff --git a/packages/contractkit/src/wrappers/Validators.ts b/packages/contractkit/src/wrappers/Validators.ts new file mode 100644 index 00000000000..e8ea338ee46 --- /dev/null +++ b/packages/contractkit/src/wrappers/Validators.ts @@ -0,0 +1,145 @@ +import { eqAddress } from '@celo/utils/lib/src/address' +import { compareBN } from '@celo/utils/lib/src/bn' +import { zip } from '@celo/utils/lib/src/collections' +import Web3 from 'web3' +import { TransactionObject } from 'web3/eth/types' +import { Address, NULL_ADDRESS } from '../base' +import { Validators } from '../generated/types/Validators' +import { BaseWrapper } from './BaseWrapper' + +import BN = require('bn.js') + +export interface Validator { + address: Address + id: string + name: string + url: string + publicKey: string + affiliation: string | null +} + +export interface ValidatorGroup { + address: Address + id: string + name: string + url: string + members: Address[] +} + +export interface ValidatorGroupVote { + address: Address + votes: BN +} + +export class ValidatorsWrapper extends BaseWrapper { + async getRegisteredValidators(): Promise { + const vgAddresses = await this.contract.methods.getRegisteredValidators().call() + + return Promise.all(vgAddresses.map((addr) => this.getValidator(addr))) + } + + async getValidator(address: Address): Promise { + const res = await this.contract.methods.getValidator(address).call() + return { + address, + id: res[0], + name: res[1], + url: res[2], + publicKey: res[3] as any, + affiliation: res[4], + } + } + + async getRegisteredValidatorGroups(): Promise { + const vgAddresses = await this.contract.methods.getRegisteredValidatorGroups().call() + return Promise.all(vgAddresses.map((addr) => this.getValidatorGroup(addr))) + } + + async getValidatorGroup(address: Address): Promise { + const res = await this.contract.methods.getValidatorGroup(address).call() + return { address, id: res[0], name: res[1], url: res[2], members: res[3] } + } + + async getValidatorGroupsVotes(): Promise { + const vgAddresses = await this.contract.methods.getRegisteredValidatorGroups().call() + const res = await this.contract.methods.getValidatorGroupVotes().call() + const r = zip((a, b) => ({ address: a, votes: Web3.utils.toBN(b) }), res[0], res[1]) + for (const vgAddress of vgAddresses) { + if (!res[0].includes(vgAddress)) { + r.push({ address: vgAddress, votes: Web3.utils.toBN(0) }) + } + } + return r + } + + async getVoteFrom(validatorAddress: Address): Promise
{ + return this.contract.methods.voters(validatorAddress).call() + } + + async revokeVote(): Promise> { + if (this.kit.defaultAccount == null) { + throw new Error(`missing from at new ValdidatorUtils()`) + } + + const bondedDeposits = await this.kit.contracts.getBondedDeposits() + const votingDetails = await bondedDeposits.getVotingDetails(this.kit.defaultAccount) + const votedGroup = await this.getVoteFrom(votingDetails.accountAddress) + + if (votedGroup == null) { + throw new Error(`Not current vote for ${this.kit.defaultAccount}`) + } + + const { lesser, greater } = await this.findLesserAndGreaterAfterVote( + votedGroup, + votingDetails.weight.neg() + ) + + return this.contract.methods.revokeVote(lesser, greater) + } + + async vote(validatorGroup: Address): Promise> { + if (this.kit.defaultAccount == null) { + throw new Error(`missing from at new ValdidatorUtils()`) + } + + const bondedDeposits = await this.kit.contracts.getBondedDeposits() + const votingDetails = await bondedDeposits.getVotingDetails(this.kit.defaultAccount) + + const { lesser, greater } = await this.findLesserAndGreaterAfterVote( + validatorGroup, + votingDetails.weight + ) + + return this.contract.methods.vote(validatorGroup, lesser, greater) + } + + private async findLesserAndGreaterAfterVote( + votedGroup: Address, + voteWeight: BN + ): Promise<{ lesser: Address; greater: Address }> { + const currentVotes = await this.getValidatorGroupsVotes() + + const selectedGroup = currentVotes.find((cv) => eqAddress(cv.address, votedGroup)) + + // modify the list + if (selectedGroup) { + selectedGroup.votes = selectedGroup.votes.add(voteWeight) + } else { + currentVotes.push({ + address: votedGroup, + votes: voteWeight, + }) + } + + // re-sort + currentVotes.sort((a, b) => compareBN(a.votes, b.votes)) + + // find new index + const newIdx = currentVotes.findIndex((cv) => eqAddress(cv.address, votedGroup)) + + return { + lesser: newIdx === 0 ? NULL_ADDRESS : currentVotes[newIdx - 1].address, + greater: newIdx === currentVotes.length - 1 ? NULL_ADDRESS : currentVotes[newIdx + 1].address, + } + } +} diff --git a/packages/contractkit/test/tsconfig.json b/packages/contractkit/test/tsconfig.json new file mode 100644 index 00000000000..0a9aebb2d29 --- /dev/null +++ b/packages/contractkit/test/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../typescript/tsconfig.library.json", + "compilerOptions": { + "rootDir": ".", + "noEmit": true, + "baseUrl": "." + }, + "include": ["."], + "references": [{ "path": ".." }] +} diff --git a/packages/contractkit/tsconfig.json b/packages/contractkit/tsconfig.json new file mode 100644 index 00000000000..c163b866107 --- /dev/null +++ b/packages/contractkit/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../typescript/tsconfig.library.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "lib" + }, + "include": ["src", "types/"] +} diff --git a/packages/contractkit/tslint.json b/packages/contractkit/tslint.json new file mode 100644 index 00000000000..dfc1be41d87 --- /dev/null +++ b/packages/contractkit/tslint.json @@ -0,0 +1,7 @@ +{ + "extends": ["@celo/typescript/tslint.json"], + "rules": { + "no-global-arrow-functions": false, + "no-console": false + } +} diff --git a/packages/contractkit/types/web3.d.ts b/packages/contractkit/types/web3.d.ts new file mode 100644 index 00000000000..ff242361673 --- /dev/null +++ b/packages/contractkit/types/web3.d.ts @@ -0,0 +1,8 @@ +import 'web3/eth/types' + +declare module 'web3/eth/types' { + export interface Tx { + // gasFeeRecipient?: string + gasCurrency?: string + } +} diff --git a/packages/dappkit/package.json b/packages/dappkit/package.json index 60a88209aeb..71649db95d1 100644 --- a/packages/dappkit/package.json +++ b/packages/dappkit/package.json @@ -6,7 +6,7 @@ }, "dependencies": { "@celo/walletkit": "0.0.4", - "@celo/utils": "0.0.5", + "@celo/utils": "0.0.6-beta3", "expo": "^34.0.1" }, "devDependencies": { diff --git a/packages/mobile/package.json b/packages/mobile/package.json index 595f61e39fe..cd5ada2934b 100644 --- a/packages/mobile/package.json +++ b/packages/mobile/package.json @@ -47,7 +47,7 @@ "@celo/client": "f7095b7", "@celo/walletkit": "^0.0.4", "@celo/react-native-sms-retriever": "git+https://github.com/celo-org/react-native-sms-retriever#d3a2fdb", - "@celo/utils": "^0.0.5", + "@celo/utils": "^0.0.6-beta3", "@react-native-community/netinfo": "^2.0.4", "@segment/analytics-react-native": "^0.1.0-beta.0", "@segment/analytics-react-native-firebase": "^0.1.0-beta.0", @@ -181,7 +181,6 @@ "redux-saga-test-plan": "^4.0.0-beta.2", "remote-redux-devtools": "^0.5.12", "ts-jest": "^24.0.0", - "ts-node": "^7.0.1", "typescript": "^3.3.3" }, "detox": { diff --git a/packages/protocol/lib/concrete-contracts.ts b/packages/protocol/lib/concrete-contracts.ts deleted file mode 100644 index 9879bccf8a0..00000000000 --- a/packages/protocol/lib/concrete-contracts.ts +++ /dev/null @@ -1,38 +0,0 @@ -export const concreteContracts = [ - 'Migrations', - - // common - 'GasCurrencyWhitelist', - 'GasCurrencyWhitelistProxy', - 'Initializable', - 'MultiSig', - 'MultiSigProxy', - 'Proxy', - 'Registry', - 'RegistryProxy', - 'UsingRegistry', - 'Validators', - - // governance - 'BondedDeposits', - 'BondedDepositsProxy', - - // identity - 'Attestations', - 'AttestationsProxy', - 'Escrow', - 'EscrowProxy', - 'Random', - - // stability - 'Exchange', - 'ExchangeProxy', - 'GoldToken', - 'GoldTokenProxy', - 'Reserve', - 'ReserveProxy', - 'StableToken', - 'StableTokenProxy', - 'SortedOracles', - 'SortedOraclesProxy', -] diff --git a/packages/protocol/package.json b/packages/protocol/package.json index c83adeeaaab..9e0ddf266e0 100644 --- a/packages/protocol/package.json +++ b/packages/protocol/package.json @@ -14,10 +14,8 @@ "test": "node runTests.js", "test:local": "yarn run test --local", "gas": "yarn run test:local --gas", - "truffle-compile": "./scripts/bash/compile.sh", "build:ts": "rm -f migrations/*.js* && tsc -b", - "build:gen": "yarn run typechain --target=truffle --outDir \"./types/typechain\" \"./build/tmp/contracts/*.json\" ", - "build": "yarn run truffle-compile -n tmp && yarn run build:gen && yarn build:ts", + "build": "ts-node ./scripts/build.ts && yarn build:ts", "postinstall": "rm -f node_modules/web3/index.d.ts", "test-coverage": "yarn run pretest && node runCoverage.js", "migrate": "./scripts/bash/migrate.sh", @@ -70,7 +68,7 @@ "devDependencies": { "@celo/ganache-cli": "git+https://github.com/celo-org/ganache-cli.git#2ebdf9f", "@celo/typescript": "0.0.1", - "@celo/utils": "^0.0.5", + "@celo/utils": "^0.0.6-beta3", "@types/bignumber.js": "^5.0.0", "@types/bn.js": "^4.11.0", "@types/chai": "^4.1.3", @@ -83,7 +81,6 @@ "eth-gas-reporter": "^0.1.2", "nodemailer": "^4.6.8", "truffle-typings": "^1.0.6", - "ts-node": "^7.0.1", "typescript": "^3.3.3" } } diff --git a/packages/protocol/scripts/build.ts b/packages/protocol/scripts/build.ts new file mode 100644 index 00000000000..d4d93609786 --- /dev/null +++ b/packages/protocol/scripts/build.ts @@ -0,0 +1,143 @@ +/* tslint:disable no-console */ +import { execSync } from 'child_process' +import * as fs from 'fs' +import * as path from 'path' + +const ROOT_DIR = path.normalize(path.join(__dirname, '../')) +const BUILD_DIR = path.join(ROOT_DIR, 'build') +const CONTRACTKIT_GEN_DIR = path.normalize(path.join(ROOT_DIR, '../contractkit/src/generated')) + +export const ProxyContracts = [ + 'GasCurrencyWhitelistProxy', + 'GasPriceMinimumProxy', + 'MultiSigProxy', + 'BondedDepositsProxy', + 'AttestationsProxy', + 'EscrowProxy', + 'ExchangeProxy', + 'GoldTokenProxy', + 'ReserveProxy', + 'StableTokenProxy', + 'SortedOraclesProxy', + 'GovernanceProxy', + 'RegistryProxy', +] +export const CoreContracts = [ + // common + + 'GasPriceMinimum', + 'GasCurrencyWhitelist', + 'MultiSig', + 'Registry', + 'Validators', + + // governance + 'BondedDeposits', + 'Governance', + + // identity + 'Attestations', + 'Escrow', + 'Random', + + // stability + 'Exchange', + 'GoldToken', + 'Reserve', + 'StableToken', + 'SortedOracles', +] + +const OtherContracts = [ + 'Proxy', + 'Migrations', + // abstract + 'Initializable', + 'UsingRegistry', +] +export const ImplContracts = OtherContracts.concat(ProxyContracts).concat(CoreContracts) + +// const TruffleTestContracts = ['Ownable'].concat(OtherContracts).concat(CoreContracts) + +function getArtifact(contractName: string) { + const file = fs.readFileSync(`${BUILD_DIR}/contracts/${contractName}.json`).toString() + return JSON.parse(file) +} + +function exec(cmd: string) { + return execSync(cmd, { cwd: ROOT_DIR, stdio: 'inherit' }) +} + +function hasEmptyBytecode(contract: any) { + return contract.bytecode === '0x' +} + +function compile() { + console.log('Compiling') + + exec(`yarn run --silent truffle compile --build_directory=${BUILD_DIR}`) + + for (const contractName of ImplContracts) { + const fileStr = getArtifact(contractName) + if (hasEmptyBytecode(fileStr)) { + console.error( + `${contractName} has empty bytecode. Maybe you forgot to fully implement an interface?` + ) + process.exit(1) + } + } +} + +function generateFilesForTruffle() { + console.log('protocol: Generating Truffle Types') + exec(`rm -rf "${ROOT_DIR}/typechain"`) + + // const globPattern = `${BUILD_DIR}/contracts/@(${TruffleTestContracts.join('|')}).json` + const globPattern = `${BUILD_DIR}/contracts/*.json` + exec( + `yarn run --silent typechain --target=truffle --outDir "./types/typechain" "${globPattern}" ` + ) +} + +function generateFilesForContractKit() { + console.log('contractkit: Generating Types') + exec(`rm -rf ${CONTRACTKIT_GEN_DIR}`) + const relativePath = path.relative(ROOT_DIR, CONTRACTKIT_GEN_DIR) + + const globPattern = `${BUILD_DIR}/contracts/@(${CoreContracts.join('|')}).json` + exec( + `yarn run --silent typechain --target="web3-1.0.0" --outDir "${relativePath}/types" "${globPattern}" ` + ) + + console.log('contractkit: Generating Contract Factories') + for (const contractName of CoreContracts) { + const contract = getArtifact(contractName) + writeContractFactoryFile(relativePath, contractName, contract.abi) + } + + exec(`yarn --cwd "${ROOT_DIR}/../.." prettier --write "${CONTRACTKIT_GEN_DIR}/**/*.ts"`) +} + +function writeContractFactoryFile(outputDir: string, contractName: string, abi: any[]) { + const contents = [ + "import Web3 from 'web3'", + `import { ${contractName} } from './types/${contractName}'`, + `export const ABI = ${JSON.stringify(abi)}`, + ``, + `export function new${contractName}(web3: Web3, address: string): ${contractName} {`, + ' return new web3.eth.Contract(ABI, address) as any', + '}', + ].join('\n') + fs.writeFileSync(path.join(outputDir, `${contractName}.ts`), contents) +} + +async function main() { + compile() + generateFilesForTruffle() + generateFilesForContractKit() +} + +main().catch((err) => { + console.error(err) + process.exit(1) +}) diff --git a/packages/protocol/scripts/typescript/check-bytecode.ts b/packages/protocol/scripts/typescript/check-bytecode.ts deleted file mode 100644 index 697d1b77f12..00000000000 --- a/packages/protocol/scripts/typescript/check-bytecode.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* tslint:disable:no-console */ -import * as fs from 'fs' -import { concreteContracts } from '../../lib/concrete-contracts' - -console.log('CONCRETE CONTRACTS') -console.log('====================') -console.log(concreteContracts) -console.log('====================') - -const { build_directory } = require('minimist')(process.argv.slice(2)) - -console.log(`Using build directory ${build_directory}`) - -function getArtifact(contractName: string) { - const file = fs.readFileSync(`${build_directory}/contracts/${contractName}.json`).toString() - return JSON.parse(file) -} - -function hasEmptyBytecode(contract: any) { - return contract.bytecode === '0x' -} - -const contractsWithEmptyBytecode = concreteContracts.map(getArtifact).filter(hasEmptyBytecode) - -if (contractsWithEmptyBytecode.length > 0) { - contractsWithEmptyBytecode.forEach((contract) => { - console.log( - `ERROR: ${ - contract.contractName - } has empty bytecode. Maybe you forgot to fully implement an interface?` - ) - }) - - process.exit(1) -} diff --git a/packages/react-components/package.json b/packages/react-components/package.json index de560a14115..4105d1b13f5 100644 --- a/packages/react-components/package.json +++ b/packages/react-components/package.json @@ -14,7 +14,7 @@ "test:watch": "export TZ=UTC && jest --watch" }, "dependencies": { - "@celo/utils": "^0.0.5", + "@celo/utils": "^0.0.6-beta3", "lodash": "^4.17.14", "react-native-autocomplete-input": "^3.6.0", "react-native-platform-touchable": "^1.1.1", diff --git a/packages/typescript/tsconfig.library.json b/packages/typescript/tsconfig.library.json new file mode 100644 index 00000000000..45376c841f8 --- /dev/null +++ b/packages/typescript/tsconfig.library.json @@ -0,0 +1,20 @@ +{ + "compileOnSave": false, + "compilerOptions": { + "lib": ["dom", "es2015", "es2016"], + "target": "es5", + "module": "commonjs", + "moduleResolution": "node", + "jsx": "preserve", + "composite": true, + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + "strict": true, + "declaration": true, + "sourceMap": true, + "skipLibCheck": true, + "noImplicitAny": true, + "noUnusedLocals": true, + "noUnusedParameters": true + } +} diff --git a/packages/utils/.npmignore b/packages/utils/.npmignore new file mode 100644 index 00000000000..aac0461e28c --- /dev/null +++ b/packages/utils/.npmignore @@ -0,0 +1,6 @@ +/node_modules +/coverage +/tslint.json +/tsconfig.json +/test +/src \ No newline at end of file diff --git a/packages/utils/package.json b/packages/utils/package.json index 676e85b8a4a..30fd083486f 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,12 +1,13 @@ { "name": "@celo/utils", - "version": "0.0.5", + "version": "0.0.6-beta3", "description": "Celo common utils", "author": "Celo", "license": "Apache-2.0", "main": "./lib/index.js", "types": "./lib/index.d.ts", "scripts": { + "prepublishOnly": "yarn build", "build": "tsc", "lint": "tslint --project .", "test": "yarn build && jest --ci --silent --coverage --runInBand", @@ -23,7 +24,6 @@ "futoin-hkdf": "^1.0.3", "google-libphonenumber": "^3.2.1", "lodash": "^4.17.14", - "typescript": "^3.3.3", "web3-utils": "1.0.0-beta.37" }, "devDependencies": { diff --git a/packages/utils/src/address.ts b/packages/utils/src/address.ts new file mode 100644 index 00000000000..1dd8e4f219f --- /dev/null +++ b/packages/utils/src/address.ts @@ -0,0 +1,5 @@ +export type Address = string + +export function eqAddress(a: Address, b: Address) { + return a.replace('0x', '').toLowerCase() === b.replace('0x', '').toLowerCase() +} diff --git a/packages/utils/src/bn.ts b/packages/utils/src/bn.ts new file mode 100644 index 00000000000..da5e647903a --- /dev/null +++ b/packages/utils/src/bn.ts @@ -0,0 +1,11 @@ +import BN from 'bn.js' + +export function compareBN(a: BN, b: BN) { + if (a.eq(b)) { + return 0 + } else if (a.lt(b)) { + return -1 + } else { + return 1 + } +} diff --git a/packages/utils/src/collections.ts b/packages/utils/src/collections.ts new file mode 100644 index 00000000000..0c9ef5522d9 --- /dev/null +++ b/packages/utils/src/collections.ts @@ -0,0 +1,9 @@ +export function zip(fn: (a: A, b: B) => C, as: A[], bs: B[]) { + const len = Math.min(as.length, bs.length) + const res: C[] = [] + + for (let i = 0; i < len; i++) { + res.push(fn(as[i], bs[i])) + } + return res +} diff --git a/packages/verification-pool-api/package.json b/packages/verification-pool-api/package.json index 919a0ed0c7a..798e840aeab 100644 --- a/packages/verification-pool-api/package.json +++ b/packages/verification-pool-api/package.json @@ -50,7 +50,6 @@ "minimist": "^1.2.0", "supertest": "^3.4.2", "ts-jest": "^24.0.0", - "ts-node": "^7.0.1", "typescript": "^3.3.3" }, "engines": { diff --git a/packages/verifier/package.json b/packages/verifier/package.json index 353a4dbc0ce..652752440ba 100644 --- a/packages/verifier/package.json +++ b/packages/verifier/package.json @@ -26,7 +26,7 @@ }, "dependencies": { "@celo/react-components": "1.0.0", - "@celo/utils": "^0.0.5", + "@celo/utils": "^0.0.6-beta3", "@react-native-community/netinfo": "^2.0.4", "@segment/analytics-react-native": "^0.1.0-beta.0", "@segment/analytics-react-native-firebase": "^0.1.0-beta.0", diff --git a/packages/walletkit/package.json b/packages/walletkit/package.json index 4c21f04d02e..d275c93c5c6 100644 --- a/packages/walletkit/package.json +++ b/packages/walletkit/package.json @@ -22,7 +22,7 @@ }, "dependencies": { "@0x/subproviders": "^4.1.0", - "@celo/utils": "^0.0.5", + "@celo/utils": "^0.0.6-beta3", "@google-cloud/storage": "^2.3.3", "@types/jest": "^24.0.13", "babel-jest": "^24.8.0", diff --git a/packages/web/package.json b/packages/web/package.json index 4bbfb47fb0a..b59df3bf9f4 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -90,7 +90,6 @@ "postcss-scss": "^1.0.5", "react-native-svg": "^9.3.6", "ts-jest": "24.0.0", - "ts-node": "^7.0.1", "typescript": "^3.3.3", "webpack": "4.20.2" }, diff --git a/yarn.lock b/yarn.lock index 2ca6ff22057..def99e67552 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4193,6 +4193,11 @@ resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.4.tgz#56eec47706f0fd0b7c694eae2f3172e6b0b769da" integrity sha512-D9MyoQFI7iP5VdpEyPZyjjqIJ8Y8EDNQFIFVLOmeg1rI1xiHOChyUPMPRUVfqFCerxfE+yS3vMyj37F6IdtOoQ== +"@types/debug@^4.1.5": + version "4.1.5" + resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.5.tgz#b14efa8852b7768d898906613c23f688713e02cd" + integrity sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ== + "@types/dotenv@^4.0.3": version "4.0.3" resolved "https://registry.yarnpkg.com/@types/dotenv/-/dotenv-4.0.3.tgz#ebcfc40da7bc0728b705945b7db48485ec5b4b67" @@ -29068,6 +29073,17 @@ tsconfig-paths@3.6.0: minimist "^1.2.0" strip-bom "^3.0.0" +tsconfig-paths@^3.8.0: + version "3.8.0" + resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.8.0.tgz#4e34202d5b41958f269cf56b01ed95b853d59f72" + integrity sha512-zZEYFo4sjORK8W58ENkRn9s+HmQFkkwydDG7My5s/fnfr2YYCaiyXe/HBUcIgU8epEKOXwiahOO+KZYjiXlWyQ== + dependencies: + "@types/json5" "^0.0.29" + deepmerge "^2.0.1" + json5 "^1.0.1" + minimist "^1.2.0" + strip-bom "^3.0.0" + tslib@1.9.0, tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0: version "1.9.0" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8" From ee7e8f7223bcb422d65110298ebe143c49ffa5e6 Mon Sep 17 00:00:00 2001 From: sallyjyl Date: Fri, 16 Aug 2019 14:16:10 +0200 Subject: [PATCH 04/21] check PROMOTE_REWARDS_APP before counting earn rewards notif (#569) --- packages/mobile/src/home/selectors.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/mobile/src/home/selectors.ts b/packages/mobile/src/home/selectors.ts index ea7d7580ae0..93be7985b2a 100644 --- a/packages/mobile/src/home/selectors.ts +++ b/packages/mobile/src/home/selectors.ts @@ -1,5 +1,6 @@ import { createSelector } from 'reselect' import { getPaymentRequests } from 'src/account/selectors' +import { PROMOTE_REWARDS_APP } from 'src/config' import { RootState } from 'src/redux/reducers' import { isBackupTooLate } from 'src/redux/selectors' @@ -16,7 +17,7 @@ export const callToActNotificationSelector = (state: RootState) => { return ( !state.account.backupCompleted || !state.goldToken.educationCompleted || - !state.account.dismissedEarnRewards || + (!state.account.dismissedEarnRewards && PROMOTE_REWARDS_APP) || !state.account.dismissedInviteFriends ) } From 81472a38dbe6a844887747fa0cddc546239c8642 Mon Sep 17 00:00:00 2001 From: J M Rossy Date: Fri, 16 Aug 2019 15:26:35 +0200 Subject: [PATCH 05/21] [Wallet] Fix navigation to QR code scanner from send flow (#582) --- packages/mobile/locales/en-US/sendFlow7.json | 2 +- packages/mobile/locales/es-AR/sendFlow7.json | 2 +- packages/mobile/src/qrcode/QRScanner.tsx | 14 +++++--------- packages/mobile/src/recipients/RecipientPicker.tsx | 2 +- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/packages/mobile/locales/en-US/sendFlow7.json b/packages/mobile/locales/en-US/sendFlow7.json index 21e8a3e552d..97b262f7b3c 100644 --- a/packages/mobile/locales/en-US/sendFlow7.json +++ b/packages/mobile/locales/en-US/sendFlow7.json @@ -54,7 +54,7 @@ "Storage write permission is needed for downloading the QR code", "ScanCodeByPlacingItInTheBox": "Scan code by placing it in the box", "needCameraPermissionToScan": "App needs camera permission to scan QR codes", - "backToYourQRCode": "Back to your QR Code", + "showYourQRCode": "Show your QR code", "toSentOrRequestPayment": "to send or request payment", "requestSent": "Request Sent", "reclaimPayment": "Reclaim Payment", diff --git a/packages/mobile/locales/es-AR/sendFlow7.json b/packages/mobile/locales/es-AR/sendFlow7.json index bc3f4ee0b68..290f117fa73 100755 --- a/packages/mobile/locales/es-AR/sendFlow7.json +++ b/packages/mobile/locales/es-AR/sendFlow7.json @@ -55,7 +55,7 @@ "ScanCodeByPlacingItInTheBox": "Escanee el código colocándolo en la caja", "needCameraPermissionToScan": "La aplicación necesita permiso de la cámara para escanear códigos QR", - "backToYourQRCode": "Volver a su código QR", + "showYourQRCode": "Muestra su código QR", "toSentOrRequestPayment": "enviar o solicitar pago", "requestSent": "Solicitud Enviada", "reclaimPayment": "Reclamar el Pago", diff --git a/packages/mobile/src/qrcode/QRScanner.tsx b/packages/mobile/src/qrcode/QRScanner.tsx index 2bb8ea29a07..7db2c648130 100644 --- a/packages/mobile/src/qrcode/QRScanner.tsx +++ b/packages/mobile/src/qrcode/QRScanner.tsx @@ -13,7 +13,7 @@ import { headerWithBackButton } from 'src/navigator/Headers' import { navigate } from 'src/navigator/NavigationService' import { Screens } from 'src/navigator/Screens' import { handleBarcodeDetected } from 'src/send/actions' -import { checkCameraPermission, requestCameraPermission } from 'src/utils/androidPermissions' +import { requestCameraPermission } from 'src/utils/androidPermissions' import Logger from 'src/utils/Logger' interface DispatchProps { @@ -27,10 +27,10 @@ const goToQrCodeScreen = () => { } class QRScanner extends React.Component { - static navigationOptions = { + static navigationOptions = () => ({ ...headerWithBackButton, headerTitle: i18n.t('sendFlow7:scanCode'), - } + }) camera: RNCamera | null = null @@ -40,10 +40,7 @@ class QRScanner extends React.Component { async componentDidMount() { const { t } = this.props - let cameraPermission = await checkCameraPermission() - if (!cameraPermission) { - cameraPermission = await requestCameraPermission() - } + const cameraPermission = await requestCameraPermission() if (!cameraPermission) { Logger.showMessage(t('needCameraPermissionToScan')) @@ -88,7 +85,7 @@ class QRScanner extends React.Component { - {t('backToYourQRCode')} + {t('showYourQRCode')} @@ -101,7 +98,6 @@ class QRScanner extends React.Component { const styles = StyleSheet.create({ container: { flex: 1, - flexDirection: 'column', }, preview: { flex: 1, diff --git a/packages/mobile/src/recipients/RecipientPicker.tsx b/packages/mobile/src/recipients/RecipientPicker.tsx index f3e668d178a..d5cc8dd2b82 100644 --- a/packages/mobile/src/recipients/RecipientPicker.tsx +++ b/packages/mobile/src/recipients/RecipientPicker.tsx @@ -42,7 +42,7 @@ import Logger from 'src/utils/Logger' import { assertUnreachable } from 'src/utils/typescript' const goToQrCodeScreen = () => { - navigate(Screens.QRCode) + navigate(Screens.QRScanner) } const QRCodeCTA = ({ t }: { t: TranslationFunction }) => ( From c2cd8e0c2a72dce60041d505563bfcf2c0f09d35 Mon Sep 17 00:00:00 2001 From: Anna K Date: Fri, 16 Aug 2019 12:05:32 -0700 Subject: [PATCH 06/21] Update spanish translations (#592) --- .../mobile/locales/es-AR/nuxNamePin1.json | 20 +++++++++---------- .../locales/es-AR/nuxRestoreWallet3.json | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/mobile/locales/es-AR/nuxNamePin1.json b/packages/mobile/locales/es-AR/nuxNamePin1.json index ce3cc1af68b..01cb5293136 100755 --- a/packages/mobile/locales/es-AR/nuxNamePin1.json +++ b/packages/mobile/locales/es-AR/nuxNamePin1.json @@ -9,26 +9,26 @@ "verifyNumber": "Verifique su número de teléfono para conectarse con otros usuarios y recibir dinero", "syncNetwork": "Sincronizando con la red", - "welcomeCelo": "Le damos la bienvenida a Celo", + "welcomeCelo": "Te damos la bienvenida a Celo", "chooseCountryCode": "Código de país", "joinText": { "0": - "Bienvenido a Celo Wallet, un monedero digital que le permite enviar, recibir y guardar valor fácilmente.", + "Bienvenido a Celo Wallet, una billetera digital que te permite enviar, recibir y guardar valor fácilmente.", "1": - "Al unirte a esta red, nos das permiso para recopilar información anónima sobre cómo utilizas la aplicación. Además, si verificas tu número de teléfono, se almacenará una copia ofuscada en la Red de Celo. Más información en", + "Al unirte a esta red, nos das permiso para recopilar información anónima sobre cómo utilizas la aplicación. Adrmás, si verificas tu número de teléfono, se almacenará una copia ofuscada en la Red de Celo. Más información en ", "2": "celo.org/terms" }, "phoneNumber": "000 000 0000", "inviteCodeText": { - "title": "Ingrese el código de invitación", + "title": "Ingresa el código de invitación", "copyInvite": { - "0": "Copia de invitación ", + "0": "Copia el código de invitación ", "1": "desde la aplicación de mensajes y vuelve." }, "openMessages": { "message": "Abrir mensajes", "hint": { - "0": "Insinuación ", + "0": "Pista ", "1": "Copia el mensaje SMS completo" } }, @@ -42,9 +42,9 @@ }, "inviteAccepted": "🎉 Invitación aceptada!", "askForInvite": { - "0": "¿No tiene un código? ", + "0": "¿No tienes un código? ", "1": - "Solicite una invitación a alguien con un Monedero Celo o regístrese para obtener una cuenta de testnet en", + "Solicita una invitación a alguien con la Celo Wallet o regístrate para obtener una cuenta de testnet en", "2": "celo.org/build/wallet" } }, @@ -53,8 +53,8 @@ "InvitationCode": "Código de invitación", "optIn": "Inscribirse", "submitting": "Enviando ...", - "haveWallet": "¿Ya tiene un Monedero Celo? ", - "importIt": "Importar", + "haveWallet": "¿Ya tienes una billetera de Celo? ", + "importIt": "Impórtala", "cancel": "Cancelar", "important": "Importante", "createPin": { diff --git a/packages/mobile/locales/es-AR/nuxRestoreWallet3.json b/packages/mobile/locales/es-AR/nuxRestoreWallet3.json index 100cd0f810a..f3bbdb5250c 100755 --- a/packages/mobile/locales/es-AR/nuxRestoreWallet3.json +++ b/packages/mobile/locales/es-AR/nuxRestoreWallet3.json @@ -1,5 +1,5 @@ { - "welcomeCelo": "Le damos la bienvenida a Celo", + "welcomeCelo": "Te damos la bienvenida a Celo", "enterInvite": "Ingrese su código de invitación. Si no tiene uno, pídale a alguien de la comunidad de Celo que lo invite.\n\nAl unirse a esta aplicación, acuerda compartir su nombre y número telefónico con nosotros. Obtenga más información en celo.org", "fullName": "Nombre completo", From 6d54e16618f6cbab13d93fb44303e0e28508c040 Mon Sep 17 00:00:00 2001 From: Derrick Lee Date: Fri, 16 Aug 2019 21:02:43 +0000 Subject: [PATCH 07/21] Add testnet label to faucet transactions and update faucet address (#560) Updates the faucet address to point to the correct address on alfajores (0xcea3ef8e187490a9d85a1849d98412e5d27d1bb3). Also uses Celo (TESTNET) Faucet as the transaction name instead of just Received. --- packages/blockchain-api/app.alfajores.yaml | 2 +- packages/mobile/src/transactions/TransferFeedItem.tsx | 3 ++- .../transactions/__snapshots__/TransferFeedItem.test.tsx.snap | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/blockchain-api/app.alfajores.yaml b/packages/blockchain-api/app.alfajores.yaml index a5be2269de1..0d51a834d78 100644 --- a/packages/blockchain-api/app.alfajores.yaml +++ b/packages/blockchain-api/app.alfajores.yaml @@ -7,6 +7,6 @@ env_variables: # Pull addresses from the build artifacts of the network in protocol/build CELO_GOLD_ADDRESS: '0x11CD75C45638Ec9f41C0e8Df78fc756201E48ff2' CELO_DOLLAR_ADDRESS: '0xd4b4fcaCAc9e23225680e89308E0a4C41Dd9C6B4' - FAUCET_ADDRESS: '0x456f41406B32c45D59E539e4BBA3D7898c3584dA' + FAUCET_ADDRESS: '0xCEa3eF8e187490A9d85A1849D98412E5D27D1Bb3' VERIFICATION_REWARDS_ADDRESS: '0xb4fdaf5f3cd313654aa357299ada901b1d2dd3b5' ABE_ADDRESS: '0x714f2879A4aa985508537f851FeBCfB26D7aF40D' \ No newline at end of file diff --git a/packages/mobile/src/transactions/TransferFeedItem.tsx b/packages/mobile/src/transactions/TransferFeedItem.tsx index 64b9f8f752d..b13ea2184e2 100644 --- a/packages/mobile/src/transactions/TransferFeedItem.tsx +++ b/packages/mobile/src/transactions/TransferFeedItem.tsx @@ -10,6 +10,7 @@ import * as React from 'react' import { withNamespaces, WithNamespaces } from 'react-i18next' import { Image, StyleSheet, Text, View } from 'react-native' import { HomeTransferFragment } from 'src/apollo/types' +import { DEFAULT_TESTNET } from 'src/config' import { features } from 'src/flags' import { CURRENCY_ENUM, resolveCurrency } from 'src/geth/consts' import { Namespaces } from 'src/i18n' @@ -169,7 +170,7 @@ export class TransferFeedItem extends React.PureComponent { comment = null } else if (type === TransactionTypes.FAUCET) { contactImage = - fullName = 'Celo' + fullName = DEFAULT_TESTNET ? `Celo ${_.startCase(DEFAULT_TESTNET)} Faucet` : 'Celo Faucet' comment = null } else if (type === TransactionTypes.INVITE_SENT) { contactImage = diff --git a/packages/mobile/src/transactions/__snapshots__/TransferFeedItem.test.tsx.snap b/packages/mobile/src/transactions/__snapshots__/TransferFeedItem.test.tsx.snap index 6af0a4e3a22..565f1254244 100644 --- a/packages/mobile/src/transactions/__snapshots__/TransferFeedItem.test.tsx.snap +++ b/packages/mobile/src/transactions/__snapshots__/TransferFeedItem.test.tsx.snap @@ -94,7 +94,7 @@ exports[`transfer feed item renders correctly for faucet 1`] = ` } } > - Celo + Celo Faucet From a15b6d7133f5b3503a38b8c816d3defdb00f26e2 Mon Sep 17 00:00:00 2001 From: Mariano Cortesi Date: Fri, 16 Aug 2019 18:48:18 -0300 Subject: [PATCH 08/21] Update dev dependencies (#599) --- package.json | 8 +-- packages/blockchain-api/package.json | 2 +- packages/celotool/package.json | 3 +- packages/contractkit/package.json | 3 +- packages/mobile/package.json | 2 +- packages/notification-service/package.json | 2 +- packages/react-components/package.json | 2 +- .../transaction-metrics-exporter/package.json | 4 +- packages/utils/package.json | 2 +- packages/verification-pool-api/package.json | 2 +- packages/verifier/package.json | 2 +- packages/walletkit/package.json | 4 +- packages/web/package.json | 2 +- yarn.lock | 52 ++++++++++--------- 14 files changed, 46 insertions(+), 44 deletions(-) diff --git a/package.json b/package.json index 29254db28ed..fc47fd667bd 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ ] }, "devDependencies": { - "@types/jest": "^24.0.13", + "@types/jest": "^24.0.17", "husky": "^3.0.0", "lerna": "^3.16.0", "patch-package": "^5.1.1", @@ -54,10 +54,10 @@ "tslint": "^5.12.1", "typescript": "^3.3.3", "jest": "^24.8.0", - "ts-jest": "^24.0.0", - "typescript-tslint-plugin": "^0.5.0", + "ts-jest": "^24.0.2", + "typescript-tslint-plugin": "^0.5.4", "tsconfig-paths": "^3.8.0", - "ts-node": "^8" + "ts-node": "^8.3.0" }, "dependencies": { "codecov": "^3.1.0" diff --git a/packages/blockchain-api/package.json b/packages/blockchain-api/package.json index a954913ca3e..de79f607e56 100644 --- a/packages/blockchain-api/package.json +++ b/packages/blockchain-api/package.json @@ -32,7 +32,7 @@ "@google-cloud/nodejs-repo-tools": "^2.3.3", "@types/dotenv": "^4.0.3", "@types/express": "^4.16.1", - "@types/jest": "^24.0.13", + "@types/jest": "^24.0.17", "@types/utf8": "^2.1.6", "@types/web3": "^1.0.18", "jest": "^24.8.0", diff --git a/packages/celotool/package.json b/packages/celotool/package.json index 60b144b709f..49c6f7f3364 100644 --- a/packages/celotool/package.json +++ b/packages/celotool/package.json @@ -25,14 +25,13 @@ "node-fetch": "^2.2.0", "prompts": "1.2.0", "sleep-promise": "^8.0.1", - "tsconfig-paths": "3.6.0", "web3": "1.0.0-beta.37", "web3-eth-admin": "1.0.0-beta.55", "yargs": "12.0.2" }, "devDependencies": { "@types/dotenv": "^4.0.3", - "@types/jest": "^24.0.13", + "@types/jest": "^24.0.17", "@types/node-fetch": "^2.1.2", "@types/prompts": "^1.1.1", "@types/web3": "^1.0.18", diff --git a/packages/contractkit/package.json b/packages/contractkit/package.json index 05c596654ac..1c66ab6a7d7 100644 --- a/packages/contractkit/package.json +++ b/packages/contractkit/package.json @@ -26,7 +26,8 @@ }, "devDependencies": { "@celo/protocol": "1.0.0", - "@types/jest": "^24.0.13", + "@types/debug": "^4.1.5", + "@types/jest": "^24.0.17", "@types/web3": "^1.0.18" }, "engines": { diff --git a/packages/mobile/package.json b/packages/mobile/package.json index cd5ada2934b..4c5c12bb53f 100644 --- a/packages/mobile/package.json +++ b/packages/mobile/package.json @@ -143,7 +143,7 @@ "@types/graphql": "^14.0.7", "@types/hoist-non-react-statics": "^3.0.1", "@types/isomorphic-fetch": "^0.0.35", - "@types/jest": "^24.0.13", + "@types/jest": "^24.0.17", "@types/lodash": "^4.14.136", "@types/react": "^16.8.19", "@types/react-native": "^0.57.47", diff --git a/packages/notification-service/package.json b/packages/notification-service/package.json index 4b97225fd86..dd2e9370492 100644 --- a/packages/notification-service/package.json +++ b/packages/notification-service/package.json @@ -36,7 +36,7 @@ "@types/dotenv": "^4.0.3", "@types/express": "^4.16.1", "@types/i18next": "^11.9.3", - "@types/jest": "^24.0.13", + "@types/jest": "^24.0.17", "@types/node-fetch": "^2.1.2", "@types/utf8": "^2.1.6", "@types/web3": "^1.0.18", diff --git a/packages/react-components/package.json b/packages/react-components/package.json index 4105d1b13f5..4d9318d99aa 100644 --- a/packages/react-components/package.json +++ b/packages/react-components/package.json @@ -24,7 +24,7 @@ "devDependencies": { "@celo/typescript": "0.0.1", "@types/enzyme": "^3.9.1", - "@types/jest": "^24.0.13", + "@types/jest": "^24.0.17", "@types/react": "^16.8.19", "@types/react-native": "^0.57.47", "enzyme": "^3.9.0", diff --git a/packages/transaction-metrics-exporter/package.json b/packages/transaction-metrics-exporter/package.json index 0f048d1937d..65fe2c32f52 100644 --- a/packages/transaction-metrics-exporter/package.json +++ b/packages/transaction-metrics-exporter/package.json @@ -15,9 +15,7 @@ }, "devDependencies": { "@types/web3": "^1.0.18", - "@types/express": "4.17.0", - "tsconfig-paths": "3.6.0", - "ts-node": "7.0.1" + "@types/express": "4.17.0" }, "scripts": { "start": "ts-node -r tsconfig-paths/register src/index.ts", diff --git a/packages/utils/package.json b/packages/utils/package.json index 30fd083486f..b47c38cc735 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -32,7 +32,7 @@ "@types/elliptic": "^6.4.9", "@types/ethereumjs-util": "^5.2.0", "@types/google-libphonenumber": "^7.4.17", - "@types/jest": "^24.0.13", + "@types/jest": "^24.0.17", "@types/lodash": "^4.14.136", "@types/node": "^10.12.18", "@types/web3": "^1.0.18", diff --git a/packages/verification-pool-api/package.json b/packages/verification-pool-api/package.json index 798e840aeab..d876c6b63c8 100644 --- a/packages/verification-pool-api/package.json +++ b/packages/verification-pool-api/package.json @@ -39,7 +39,7 @@ "devDependencies": { "@types/express": "^4.16.1", "@types/google-libphonenumber": "^7.4.17", - "@types/jest": "^24.0.13", + "@types/jest": "^24.0.17", "@types/minimist": "^1.2.0", "@types/supertest": "^2.0.7", "@types/web3": "^1.0.18", diff --git a/packages/verifier/package.json b/packages/verifier/package.json index 652752440ba..419f9af7474 100644 --- a/packages/verifier/package.json +++ b/packages/verifier/package.json @@ -63,7 +63,7 @@ "@types/enzyme": "^3.1.15", "@types/enzyme-adapter-react-16": "^1.0.3", "@types/graphql": "^14.0.7", - "@types/jest": "^24.0.13", + "@types/jest": "^24.0.17", "@types/react": "^16.8.19", "@types/react-native": "^0.57.47", "@types/react-native-autocomplete-input": "^3.5.1", diff --git a/packages/walletkit/package.json b/packages/walletkit/package.json index d275c93c5c6..7a554828053 100644 --- a/packages/walletkit/package.json +++ b/packages/walletkit/package.json @@ -24,7 +24,7 @@ "@0x/subproviders": "^4.1.0", "@celo/utils": "^0.0.6-beta3", "@google-cloud/storage": "^2.3.3", - "@types/jest": "^24.0.13", + "@types/jest": "^24.0.17", "babel-jest": "^24.8.0", "bignumber.js": "^7.2.0", "chalk": "^2.4.2", @@ -44,7 +44,7 @@ "@types/bignumber.js": "^5.0.0", "@types/bip32": "^1.0.1", "@types/bip39": "^2.4.2", - "@types/jest": "^24.0.13", + "@types/jest": "^24.0.17", "@types/lodash": "^4.14.136", "@types/web3": "^1.0.18", "babel-jest": "^24.8.0", diff --git a/packages/web/package.json b/packages/web/package.json index b59df3bf9f4..66b84fe17bc 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -72,7 +72,7 @@ "@firebase/app-types": "^0.3.7", "@types/airtable": "^0.5.0", "@types/i18next": "^12.1.0", - "@types/jest": "^24.0.13", + "@types/jest": "^24.0.17", "@types/mailgun-js": "^0.16.3", "@types/next": "^8.0.3", "@types/node": "^10.12.18", diff --git a/yarn.lock b/yarn.lock index def99e67552..1a37ce74933 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4441,13 +4441,6 @@ resolved "https://registry.yarnpkg.com/@types/jest-diff/-/jest-diff-20.0.1.tgz#35cc15b9c4f30a18ef21852e255fdb02f6d59b89" integrity sha512-yALhelO3i0hqZwhjtcr6dYyaLoCHbAMshwtj6cGxTvHZAKXHsYGdff6E8EPw3xLKY0ELUTQ69Q1rQiJENnccMA== -"@types/jest@^24.0.13": - version "24.0.13" - resolved "https://registry.yarnpkg.com/@types/jest/-/jest-24.0.13.tgz#10f50b64cb05fb02411fbba49e9042a3a11da3f9" - integrity sha512-3m6RPnO35r7Dg+uMLj1+xfZaOgIHHHut61djNjzwExXN4/Pm9has9C6I1KMYSfz7mahDhWUOVg4HW/nZdv5Pww== - dependencies: - "@types/jest-diff" "*" - "@types/jest@^24.0.15": version "24.0.15" resolved "https://registry.yarnpkg.com/@types/jest/-/jest-24.0.15.tgz#6c42d5af7fe3b44ffff7cc65de7bf741e8fa427f" @@ -4455,6 +4448,13 @@ dependencies: "@types/jest-diff" "*" +"@types/jest@^24.0.17": + version "24.0.17" + resolved "https://registry.yarnpkg.com/@types/jest/-/jest-24.0.17.tgz#b66ea026efb746eb5db1356ee28518aaff7af416" + integrity sha512-1cy3xkOAfSYn78dsBWy4M3h/QF/HeWPchNFDjysVtp3GHeTdSmtluNnELfCmfNRRHo0OWEcpf+NsEJQvwQfdqQ== + dependencies: + "@types/jest-diff" "*" + "@types/json5@^0.0.29": version "0.0.29" resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee" @@ -29020,12 +29020,27 @@ ts-jest@24.0.0, ts-jest@^24.0.0: semver "^5.5" yargs-parser "10.x" +ts-jest@^24.0.2: + version "24.0.2" + resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-24.0.2.tgz#8dde6cece97c31c03e80e474c749753ffd27194d" + integrity sha512-h6ZCZiA1EQgjczxq+uGLXQlNgeg02WWJBbeT8j6nyIBRQdglqbvzDoHahTEIiS6Eor6x8mK6PfZ7brQ9Q6tzHw== + dependencies: + bs-logger "0.x" + buffer-from "1.x" + fast-json-stable-stringify "2.x" + json5 "2.x" + make-error "1.x" + mkdirp "0.x" + resolve "1.x" + semver "^5.5" + yargs-parser "10.x" + ts-log@2.1.4: version "2.1.4" resolved "https://registry.yarnpkg.com/ts-log/-/ts-log-2.1.4.tgz#063c5ad1cbab5d49d258d18015963489fb6fb59a" integrity sha512-P1EJSoyV+N3bR/IWFeAqXzKPZwHpnLY6j7j58mAvewHRipo+BQM2Y1f9Y9BjEQznKwgqqZm7H8iuixmssU7tYQ== -ts-node@7.0.1, ts-node@^7.0.1: +ts-node@^7.0.1: version "7.0.1" resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-7.0.1.tgz#9562dc2d1e6d248d24bc55f773e3f614337d9baf" integrity sha512-BVwVbPJRspzNh2yfslyT1PSbl5uIk03EZlb493RKHN4qej/D06n1cEhjlOJG69oFsE7OT8XjpTUcYf6pKTLMhw== @@ -29039,7 +29054,7 @@ ts-node@7.0.1, ts-node@^7.0.1: source-map-support "^0.5.6" yn "^2.0.0" -ts-node@^8: +ts-node@^8.3.0: version "8.3.0" resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.3.0.tgz#e4059618411371924a1fb5f3b125915f324efb57" integrity sha512-dyNS/RqyVTDcmNM4NIBAeDMpsAdaQ+ojdf0GOLqE6nwJOgzEkdRNzJywhDfwnuvB10oa6NLVG1rUJQCpRN7qoQ== @@ -29062,17 +29077,6 @@ tsc-watch@^1.0.31: string-argv "^0.1.1" strip-ansi "^4.0.0" -tsconfig-paths@3.6.0: - version "3.6.0" - resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.6.0.tgz#f14078630d9d6e8b1dc690c1fc0cfb9cd0663891" - integrity sha512-mrqQIP2F4e03aMTCiPdedCIT300//+q0ET53o5WqqtQjmEICxP9yfz/sHTpPqXpssuJEzODsEzJaLRaf5J2X1g== - dependencies: - "@types/json5" "^0.0.29" - deepmerge "^2.0.1" - json5 "^1.0.1" - minimist "^1.2.0" - strip-bom "^3.0.0" - tsconfig-paths@^3.8.0: version "3.8.0" resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.8.0.tgz#4e34202d5b41958f269cf56b01ed95b853d59f72" @@ -29353,10 +29357,10 @@ typescript-logic@^0.0.0: resolved "https://registry.yarnpkg.com/typescript-logic/-/typescript-logic-0.0.0.tgz#66ebd82a2548f2b444a43667bec120b496890196" integrity sha512-zXFars5LUkI3zP492ls0VskH3TtdeHCqu0i7/duGt60i5IGPIpAHE/DWo5FqJ6EjQ15YKXrt+AETjv60Dat34Q== -typescript-tslint-plugin@^0.5.0: - version "0.5.0" - resolved "https://registry.yarnpkg.com/typescript-tslint-plugin/-/typescript-tslint-plugin-0.5.0.tgz#4cefc7f2583d5e663c5e60dc95667f5a93ce7dd0" - integrity sha512-qVejs4wVu6RmiNOTekPJIlztt6lN+QC+lArqbcP3CaBuABDsJ0BXYofZX1H2ZywAblOnx403FSrhQcgnRBUGQA== +typescript-tslint-plugin@^0.5.4: + version "0.5.4" + resolved "https://registry.yarnpkg.com/typescript-tslint-plugin/-/typescript-tslint-plugin-0.5.4.tgz#febe0cca1fe65133f4f688841eba68262a1d55a5" + integrity sha512-CQEfGC+p0SoBARI4N2LrGsWJsp4/OE+uKZ68xsWYKHWqMFq4DFQHqOVlK0deEricSN01NmDTqjap63Pw/DHieg== dependencies: minimatch "^3.0.4" mock-require "^3.0.2" From 0301a83366313fc997a6fd818f91b35586c29f3d Mon Sep 17 00:00:00 2001 From: Anna K Date: Fri, 16 Aug 2019 16:06:59 -0700 Subject: [PATCH 09/21] Fix Connecting to Celo Network banner regression (#606) --- packages/mobile/src/navigator/Headers.tsx | 4 ++-- packages/mobile/src/verify/Education.tsx | 2 +- packages/mobile/src/verify/Input.tsx | 2 +- packages/mobile/src/verify/Verifying.tsx | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/mobile/src/navigator/Headers.tsx b/packages/mobile/src/navigator/Headers.tsx index cb6bbc732cc..db3f0c47a9c 100644 --- a/packages/mobile/src/navigator/Headers.tsx +++ b/packages/mobile/src/navigator/Headers.tsx @@ -13,8 +13,8 @@ export const nuxNavigationOptions = { headerLeftContainerStyle: { paddingHorizontal: 20 }, headerLeft: , headerRightContainerStyle: { paddingRight: 15 }, - headerRight: ( - + header: ( + ), diff --git a/packages/mobile/src/verify/Education.tsx b/packages/mobile/src/verify/Education.tsx index 07ca903f829..02dee1d28f7 100644 --- a/packages/mobile/src/verify/Education.tsx +++ b/packages/mobile/src/verify/Education.tsx @@ -26,8 +26,8 @@ export class Education extends React.Component { return ( + - {t('verifyPhone')} diff --git a/packages/mobile/src/verify/Input.tsx b/packages/mobile/src/verify/Input.tsx index c31504b345e..ab68e233c06 100644 --- a/packages/mobile/src/verify/Input.tsx +++ b/packages/mobile/src/verify/Input.tsx @@ -114,8 +114,8 @@ export class Input extends React.Component { return ( + - {t('enterPhoneToVerify')} { )} + - From 3401e2307a5bafb1966faeff3933c25adfdafe9b Mon Sep 17 00:00:00 2001 From: Anna K Date: Fri, 16 Aug 2019 17:43:56 -0700 Subject: [PATCH 10/21] Remove currency symbol hardcoding (#556) --- .../mobile/locales/en-US/exchangeFlow9.json | 2 - .../locales/en-US/nuxCurrencyPhoto4.json | 3 - .../mobile/locales/en-US/walletFlow5.json | 3 - packages/mobile/locales/en.json | 2 - .../mobile/locales/es-AR/exchangeFlow9.json | 2 - .../locales/es-AR/nuxCurrencyPhoto4.json | 3 - .../mobile/locales/es-AR/walletFlow5.json | 3 - .../mobile/src/account/DollarEducation.tsx | 2 +- .../mobile/src/components/AccountOverview.tsx | 4 +- .../mobile/src/components/CurrencyDisplay.tsx | 13 +- .../AccountOverview.test.tsx.snap | 130 ++++++++++++++++-- .../escrow/ReclaimPaymentConfirmationCard.tsx | 9 +- .../src/exchange/ExchangeConfirmationCard.tsx | 4 +- .../src/exchange/ExchangeTradeScreen.tsx | 21 +-- .../ExchangeConfirmationCard.test.tsx.snap | 52 ++++++- .../ExchangeTradeScreen.test.tsx.snap | 4 +- packages/mobile/src/home/NotificationBox.tsx | 2 +- .../NotificationBox.test.tsx.snap | 2 +- .../src/paymentRequest/NotificationAmount.tsx | 3 +- .../paymentRequest/PaymentRequestBalance.tsx | 4 +- .../PaymentRequestListScreen.test.tsx.snap | 15 +- .../PaymentRequestNotification.test.tsx.snap | 3 +- packages/mobile/src/send/SendAmount.tsx | 3 +- .../src/send/TransferConfirmationCard.tsx | 14 +- .../src/transactions/ExchangeFeedItem.tsx | 6 +- .../mobile/src/transactions/NoActivity.tsx | 2 +- .../src/transactions/TransferFeedItem.tsx | 12 +- .../ExchangeFeedItem.test.tsx.snap | 1 + .../__snapshots__/NoActivity.test.tsx.snap | 2 +- .../TransactionFeed.test.tsx.snap | 6 + 30 files changed, 241 insertions(+), 91 deletions(-) diff --git a/packages/mobile/locales/en-US/exchangeFlow9.json b/packages/mobile/locales/en-US/exchangeFlow9.json index cbec2f11e06..3710a2418b3 100644 --- a/packages/mobile/locales/en-US/exchangeFlow9.json +++ b/packages/mobile/locales/en-US/exchangeFlow9.json @@ -1,7 +1,5 @@ { "learnMore": "Learn More", - "celoDollars": "Celo Dollars", - "celoGold": "Celo Gold", "whatIsGold": "Gold is where you can choose to store Celo dollars you have", "manageCelo": "Manage Celo Dollars", "activity": "Activity", diff --git a/packages/mobile/locales/en-US/nuxCurrencyPhoto4.json b/packages/mobile/locales/en-US/nuxCurrencyPhoto4.json index 5cd990a4361..a4cd716239c 100644 --- a/packages/mobile/locales/en-US/nuxCurrencyPhoto4.json +++ b/packages/mobile/locales/en-US/nuxCurrencyPhoto4.json @@ -1,6 +1,4 @@ { - "celoDollars": "Celo Dollars", - "celoGold": "Celo Gold", "getStarted": "Get Started", "getBackupKey": "Get Backup Key", "setYourBackupKey": @@ -10,7 +8,6 @@ "stableDollar": "Celo Dollar is a stable digital asset that tracks to the value of the US Dollar", "feeTransaction": "Sending transactions cost a small fee", "sendCelo": "Send Celo Dollars to anyone with a mobile phone", - "sendCeloDollars": "Send Celo Dollars", "backToWallet": "Back to Wallet", "celoLikeGold": "Celo Gold is like real gold", "goldFluctuates": "There’s a limited amount of Celo Gold and the value can go up and down", diff --git a/packages/mobile/locales/en-US/walletFlow5.json b/packages/mobile/locales/en-US/walletFlow5.json index 26ccffd98b1..8d8b8d0cfb2 100644 --- a/packages/mobile/locales/en-US/walletFlow5.json +++ b/packages/mobile/locales/en-US/walletFlow5.json @@ -1,6 +1,4 @@ { - "celoDollars": "Celo Dollars", - "celoGold": "Celo Gold", "getStarted": "Get Started", "paymentRequest": "Payment Request", "paymentRequestWithCount_plural": "{{count}} Payment Requests", @@ -47,7 +45,6 @@ "0": "Unable to load your feed", "1": "Please try again later" }, - "sendCeloDollars": "Send Celo Dollars", "noTransactionActivity": "You will see your sent and received payments here", "noExchangeActivity": "You will see completed exchanges here", "maybeLater": "Maybe Later", diff --git a/packages/mobile/locales/en.json b/packages/mobile/locales/en.json index 88b8269c829..8565d5fdd28 100644 --- a/packages/mobile/locales/en.json +++ b/packages/mobile/locales/en.json @@ -92,8 +92,6 @@ "fee": "Fee" }, "faq_terms_footer": "<0>Test FAQ is <1>here<2> Terms of service are <3>here", - "celoDollars": "Celo Dollars", - "celoGold": "Celo Gold", "invalidInvitation": "Invalid Invitation Code ", "incorrectPin": "Incorrect PIN", "photosNUX": { diff --git a/packages/mobile/locales/es-AR/exchangeFlow9.json b/packages/mobile/locales/es-AR/exchangeFlow9.json index 72385eb07f3..6f1832f98d0 100755 --- a/packages/mobile/locales/es-AR/exchangeFlow9.json +++ b/packages/mobile/locales/es-AR/exchangeFlow9.json @@ -1,7 +1,5 @@ { "learnMore": "Saber más", - "celoDollars": "Celo Dólares", - "celoGold": "Celo Oro", "whatIsGold": "Puede elegir guardar sus Celo Dólares en Celo Oro", "manageCelo": "Administrar Celo Dólares", "activity": "Actividad", diff --git a/packages/mobile/locales/es-AR/nuxCurrencyPhoto4.json b/packages/mobile/locales/es-AR/nuxCurrencyPhoto4.json index 4c8e541df89..31dfb98e5b5 100755 --- a/packages/mobile/locales/es-AR/nuxCurrencyPhoto4.json +++ b/packages/mobile/locales/es-AR/nuxCurrencyPhoto4.json @@ -1,6 +1,4 @@ { - "celoDollars": "Celo Dólares", - "celoGold": "Celo Oro", "getStarted": "Primeros pasos", "getBackupKey": "Obtener clave de respaldo", "setYourBackupKey": @@ -11,7 +9,6 @@ "El Celo Dólar constituye un activo digital estable que está alineado con el valor del dólar estadounidense", "feeTransaction": "El envío de transacciones tiene una pequeña comisión", "sendCelo": "Enviar Celo Dólares a cualquier persona con un celular", - "sendCeloDollars": "Enviar Celo Dólares", "backToWallet": "Volver a el Monedero", "celoLikeGold": "Celo Oro es como el oro real", "goldFluctuates": "Hay una cantidad limitada de Celo Oro, y su valor puede aumentar o disminuir", diff --git a/packages/mobile/locales/es-AR/walletFlow5.json b/packages/mobile/locales/es-AR/walletFlow5.json index 8e8ffb67544..0276b38476e 100755 --- a/packages/mobile/locales/es-AR/walletFlow5.json +++ b/packages/mobile/locales/es-AR/walletFlow5.json @@ -1,6 +1,4 @@ { - "celoDollars": "Celo Dólares", - "celoGold": "Celo Oro", "getStarted": "Primeros pasos", "paymentRequest": "Solicitud de pago", "paymentRequestWithCount_plural": "{{count}} solicitudes de pago", @@ -48,7 +46,6 @@ "0": "No se puede cargar tu actividad", "1": "Por favor inténtalo de nuevo más tarde" }, - "sendCeloDollars": "Enviar Celo Dólares", "noTransactionActivity": "Verá sus pagos enviados y recibidos aquí", "noExchangeActivity": "Verá intercambios completados aquí", "maybeLater": "quizas mas tarde", diff --git a/packages/mobile/src/account/DollarEducation.tsx b/packages/mobile/src/account/DollarEducation.tsx index 067ba67b3f9..bd5b0b66848 100644 --- a/packages/mobile/src/account/DollarEducation.tsx +++ b/packages/mobile/src/account/DollarEducation.tsx @@ -56,7 +56,7 @@ export class DollarEducation extends React.Component { stepInfo={stepInfo} onFinish={this.goToSend} onFinishAlternate={this.goToWalletHome} - buttonText={'sendCeloDollars'} + buttonText={'global:sendCeloDollars'} linkText={'backToWallet'} /> ) diff --git a/packages/mobile/src/components/AccountOverview.tsx b/packages/mobile/src/components/AccountOverview.tsx index 443658bef0f..a11604f0f94 100644 --- a/packages/mobile/src/components/AccountOverview.tsx +++ b/packages/mobile/src/components/AccountOverview.tsx @@ -81,7 +81,7 @@ export class AccountOverview extends React.Component { - {t('celoDollars') + ' ' + CURRENCIES[Tokens.DOLLAR].code} + {t('global:celoDollars') + ' ' + CURRENCIES[Tokens.DOLLAR].code} { - {t('celoGold') + ' ' + CURRENCIES[Tokens.GOLD].code} + {t('global:celoGold') + ' ' + CURRENCIES[Tokens.GOLD].code} { } render() { - const { size } = this.props + const { size, type } = this.props const fontSize = size const dollarStyle = { fontSize, lineHeight: Math.round(fontSize * 1.3), color: this.color() } + const currencySymbol = CURRENCIES[type].symbol return ( - {this.props.type === CURRENCY_ENUM.DOLLAR ? ( - - $ - - ) : null} + + {currencySymbol} + {this.amount()} diff --git a/packages/mobile/src/components/__snapshots__/AccountOverview.test.tsx.snap b/packages/mobile/src/components/__snapshots__/AccountOverview.test.tsx.snap index d0efce52b6c..5b3edfbf978 100644 --- a/packages/mobile/src/components/__snapshots__/AccountOverview.test.tsx.snap +++ b/packages/mobile/src/components/__snapshots__/AccountOverview.test.tsx.snap @@ -47,7 +47,7 @@ exports[`renders correctly when Dollar education NUX flow hasn't been completed ] } > - celoDollars cUSD + global:celoDollars cUSD - celoGold cGLD + global:celoGold cGLD + + + - celoDollars cUSD + global:celoDollars cUSD - celoGold cGLD + global:celoGold cGLD + + + - celoDollars cUSD + global:celoDollars cUSD - celoGold cGLD + global:celoGold cGLD + + + - celoDollars cUSD + global:celoDollars cUSD - celoGold cGLD + global:celoGold cGLD + + + - celoDollars cUSD + global:celoDollars cUSD - celoGold cGLD + global:celoGold cGLD + + + { ) => { const { t } = this.props const amountWithFees = total.minus(fee || 0) + const dollarSymbol = CURRENCIES[Tokens.DOLLAR].symbol return ( - + { hasError={!!feeError} /> { {t('newBalance')} - {t('celoDollars')} + {t('global:celoDollars')} ${newDollarBalance} - {t('celoGold')} + {t('global:celoGold')} {newGoldBalance} diff --git a/packages/mobile/src/exchange/ExchangeTradeScreen.tsx b/packages/mobile/src/exchange/ExchangeTradeScreen.tsx index 78be941441d..e2c1e59d708 100644 --- a/packages/mobile/src/exchange/ExchangeTradeScreen.tsx +++ b/packages/mobile/src/exchange/ExchangeTradeScreen.tsx @@ -21,7 +21,7 @@ import { ALERT_BANNER_DURATION } from 'src/config' import { fetchExchangeRate } from 'src/exchange/actions' import ExchangeRate from 'src/exchange/ExchangeRate' import { ExchangeRatePair } from 'src/exchange/reducer' -import { CURRENCY_ENUM as Token } from 'src/geth/consts' +import { CURRENCIES, CURRENCY_ENUM as Token } from 'src/geth/consts' import i18n, { Namespaces } from 'src/i18n' import { headerWithCancelButton } from 'src/navigator/Headers' import { navigate, navigateBack } from 'src/navigator/NavigationService' @@ -90,7 +90,8 @@ export class ExchangeTradeScreen extends React.Component { setExchangeAmount = (amount: string) => { // remove $ we inserted for display purposes - amount = amount.replace(/\$/g, '') + const currencySymbol = new RegExp('\\' + CURRENCIES[Token.DOLLAR].symbol, 'g') + amount = amount.replace(currencySymbol, '') this.setState({ makerTokenAmount: amount }, () => { this.updateError(amount) @@ -141,7 +142,7 @@ export class ExchangeTradeScreen extends React.Component { const { dollarBalance, goldBalance } = this.props return isDollar ? getNewTakerBalance(goldBalance, takerTokenAmount) - : `$${getNewTakerBalance(dollarBalance, takerTokenAmount)}` + : CURRENCIES[Token.DOLLAR].symbol + getNewTakerBalance(dollarBalance, takerTokenAmount) } hasError = () => { @@ -174,7 +175,7 @@ export class ExchangeTradeScreen extends React.Component { inputValue = () => { if (this.state.makerTokenAmount) { - return `${this.isDollar() ? '$' : ''}${this.state.makerTokenAmount}` + return CURRENCIES[this.state.makerToken].symbol + this.state.makerTokenAmount } else { return '' } @@ -183,8 +184,8 @@ export class ExchangeTradeScreen extends React.Component { render() { const { t } = this.props - const dollarText = t('celoDollars') + ' (cUSD)' - const goldText = t('celoGold') + ' (cGLD)' + const dollarText = t('global:celoDollars') + ' (cUSD)' + const goldText = t('global:celoGold') + ' (cGLD)' const makerTokenText = this.isDollar() ? dollarText : goldText const takerTokenText = this.isDollar() ? goldText : dollarText @@ -201,7 +202,7 @@ export class ExchangeTradeScreen extends React.Component { const borderStyle = { borderColor: this.hasError() ? colors.errorRed : colors.dark } - const takerDisplay = `${this.isDollar() ? '' : '$'}${getMoneyDisplayValue(takerTokenAmount)}` + const makerSymbol = CURRENCIES[this.state.makerToken].symbol return ( @@ -222,7 +223,7 @@ export class ExchangeTradeScreen extends React.Component { onFocus={this.recordFocus} value={this.inputValue()} placeholderTextColor={placeholderColor} - placeholder={this.isDollar() ? '$0' : '0'} + placeholder={makerSymbol + '0'} underlineColorAndroid={'transparent'} style={[ styles.input, @@ -236,7 +237,7 @@ export class ExchangeTradeScreen extends React.Component { {t('available')} - {(this.isDollar() ? '$' : '') + this.getFormattedMakerBalance()} + {makerSymbol + this.getFormattedMakerBalance()} @@ -253,7 +254,7 @@ export class ExchangeTradeScreen extends React.Component { - {takerDisplay} + {getMoneyDisplayValue(takerTokenAmount)} * diff --git a/packages/mobile/src/exchange/__snapshots__/ExchangeConfirmationCard.test.tsx.snap b/packages/mobile/src/exchange/__snapshots__/ExchangeConfirmationCard.test.tsx.snap index bc586d27654..ff201cc1615 100644 --- a/packages/mobile/src/exchange/__snapshots__/ExchangeConfirmationCard.test.tsx.snap +++ b/packages/mobile/src/exchange/__snapshots__/ExchangeConfirmationCard.test.tsx.snap @@ -109,6 +109,28 @@ exports[`renders correctly with giant numbers 1`] = ` } } > + + + - celoDollars + global:celoDollars - celoGold + global:celoGold + + + - celoDollars + global:celoDollars - celoGold + global:celoGold - celoDollars (cUSD) + global:celoDollars (cUSD) - celoGold (cGLD) + global:celoGold (cGLD) { if (!goldEducationCompleted) { actions.push({ - title: t('celoGold'), + title: t('global:celoGold'), text: i18n.t('exchangeFlow9:whatIsGold'), image: homeIcon, ctaList: [ diff --git a/packages/mobile/src/home/__snapshots__/NotificationBox.test.tsx.snap b/packages/mobile/src/home/__snapshots__/NotificationBox.test.tsx.snap index ee44b6f88d6..b81681abe00 100644 --- a/packages/mobile/src/home/__snapshots__/NotificationBox.test.tsx.snap +++ b/packages/mobile/src/home/__snapshots__/NotificationBox.test.tsx.snap @@ -481,7 +481,7 @@ exports[`NotificationBox Educations not completed yet 1`] = ` } } > - celoGold + global:celoGold { return ( - ${getCentAwareMoneyDisplay(this.props.amount)} + {CURRENCIES[Tokens.DOLLAR].symbol + getCentAwareMoneyDisplay(this.props.amount)} ) diff --git a/packages/mobile/src/paymentRequest/PaymentRequestBalance.tsx b/packages/mobile/src/paymentRequest/PaymentRequestBalance.tsx index 78da12864a3..6d49d075f57 100644 --- a/packages/mobile/src/paymentRequest/PaymentRequestBalance.tsx +++ b/packages/mobile/src/paymentRequest/PaymentRequestBalance.tsx @@ -5,6 +5,7 @@ import BigNumber from 'bignumber.js' import * as React from 'react' import { WithNamespaces, withNamespaces } from 'react-i18next' import { StyleSheet, Text, View } from 'react-native' +import { CURRENCIES, CURRENCY_ENUM as Tokens } from 'src/geth/consts' import { Namespaces } from 'src/i18n' import CeloAccountIcon from 'src/icons/CeloAccountIcon' import { getCentAwareMoneyDisplay } from 'src/utils/formatting' @@ -23,7 +24,8 @@ class PaymentRequestBalance extends React.PureComponent {this.props.t('celoDollarBalance')} - ${getCentAwareMoneyDisplay(this.props.dollarBalance || 0)} + {CURRENCIES[Tokens.DOLLAR].symbol + + getCentAwareMoneyDisplay(this.props.dollarBalance || 0)} diff --git a/packages/mobile/src/paymentRequest/__snapshots__/PaymentRequestListScreen.test.tsx.snap b/packages/mobile/src/paymentRequest/__snapshots__/PaymentRequestListScreen.test.tsx.snap index 6762df558f2..8733168e5f2 100644 --- a/packages/mobile/src/paymentRequest/__snapshots__/PaymentRequestListScreen.test.tsx.snap +++ b/packages/mobile/src/paymentRequest/__snapshots__/PaymentRequestListScreen.test.tsx.snap @@ -70,8 +70,7 @@ exports[`PaymentRequestListScreen renders correctly with no requests 1`] = ` ] } > - $ - 120 + $120 @@ -191,8 +190,7 @@ exports[`PaymentRequestListScreen renders correctly with requests 1`] = ` ] } > - $ - 120 + $120 @@ -500,8 +498,7 @@ exports[`PaymentRequestListScreen renders correctly with requests 1`] = ` ] } > - $ - 20 + $20 @@ -780,8 +777,7 @@ exports[`PaymentRequestListScreen renders correctly with requests 1`] = ` ] } > - $ - 102 + $102 @@ -1060,8 +1056,7 @@ exports[`PaymentRequestListScreen renders correctly with requests 1`] = ` ] } > - $ - 1 + $1 diff --git a/packages/mobile/src/paymentRequest/__snapshots__/PaymentRequestNotification.test.tsx.snap b/packages/mobile/src/paymentRequest/__snapshots__/PaymentRequestNotification.test.tsx.snap index 7408059a391..63bb99e4116 100644 --- a/packages/mobile/src/paymentRequest/__snapshots__/PaymentRequestNotification.test.tsx.snap +++ b/packages/mobile/src/paymentRequest/__snapshots__/PaymentRequestNotification.test.tsx.snap @@ -248,8 +248,7 @@ exports[`PaymentRequestNotification renders correctly 1`] = ` ] } > - $ - 24 + $24 diff --git a/packages/mobile/src/send/SendAmount.tsx b/packages/mobile/src/send/SendAmount.tsx index ff9d1223eac..aadbab4ff55 100644 --- a/packages/mobile/src/send/SendAmount.tsx +++ b/packages/mobile/src/send/SendAmount.tsx @@ -28,6 +28,7 @@ import { ALERT_BANNER_DURATION } from 'src/config' import { FeeType } from 'src/fees/actions' import EstimateFee from 'src/fees/EstimateFee' import { getFeeEstimateDollars } from 'src/fees/selectors' +import { CURRENCIES, CURRENCY_ENUM as Tokens } from 'src/geth/consts' import i18n, { Namespaces } from 'src/i18n' import { fetchPhoneAddresses } from 'src/identity/actions' import { VerificationStatus } from 'src/identity/contactMapping' @@ -360,7 +361,7 @@ export class SendAmount extends React.Component { )} {this.props.type === TransactionTypes.PAY_REQUEST && ( - + )} - + )} diff --git a/packages/mobile/src/transactions/ExchangeFeedItem.tsx b/packages/mobile/src/transactions/ExchangeFeedItem.tsx index 911105d448d..bc0430bc361 100644 --- a/packages/mobile/src/transactions/ExchangeFeedItem.tsx +++ b/packages/mobile/src/transactions/ExchangeFeedItem.tsx @@ -7,7 +7,7 @@ import * as React from 'react' import { WithNamespaces, withNamespaces } from 'react-i18next' import { Image, StyleSheet, Text, View } from 'react-native' import { HomeExchangeFragment } from 'src/apollo/types' -import { CURRENCY_ENUM, resolveCurrency } from 'src/geth/consts' +import { CURRENCIES, CURRENCY_ENUM, resolveCurrency } from 'src/geth/consts' import { Namespaces } from 'src/i18n' import { navigateToExchangeReview } from 'src/transactions/actions' import { ExchangeStandby, TransactionStatus } from 'src/transactions/reducer' @@ -115,14 +115,14 @@ export class ExchangeFeedItem extends React.PureComponent { - {inCurrency === CURRENCY_ENUM.DOLLAR && '$'} + {CURRENCIES[inCurrency].symbol} {getMoneyDisplayValue(inValue)} - {outCurrency === CURRENCY_ENUM.DOLLAR && '$'} + {CURRENCIES[outCurrency].symbol} {getMoneyDisplayValue(outValue)} diff --git a/packages/mobile/src/transactions/NoActivity.tsx b/packages/mobile/src/transactions/NoActivity.tsx index 269f775fa68..0d05a00ece9 100644 --- a/packages/mobile/src/transactions/NoActivity.tsx +++ b/packages/mobile/src/transactions/NoActivity.tsx @@ -56,7 +56,7 @@ export class NoActivity extends React.PureComponent { {kind === FeedType.HOME && ( diff --git a/packages/mobile/src/transactions/TransferFeedItem.tsx b/packages/mobile/src/transactions/TransferFeedItem.tsx index b13ea2184e2..f0a05883a47 100644 --- a/packages/mobile/src/transactions/TransferFeedItem.tsx +++ b/packages/mobile/src/transactions/TransferFeedItem.tsx @@ -12,7 +12,7 @@ import { Image, StyleSheet, Text, View } from 'react-native' import { HomeTransferFragment } from 'src/apollo/types' import { DEFAULT_TESTNET } from 'src/config' import { features } from 'src/flags' -import { CURRENCY_ENUM, resolveCurrency } from 'src/geth/consts' +import { CURRENCIES, CURRENCY_ENUM, resolveCurrency } from 'src/geth/consts' import { Namespaces } from 'src/i18n' import { AddressToE164NumberType } from 'src/identity/reducer' import { faucetIcon, inviteVerifyFee } from 'src/images/Images' @@ -43,7 +43,7 @@ interface CurrencySymbolProps { direction: string } -export function getCurrencyStyles(currency: string, type: string): CurrencySymbolProps { +export function getCurrencyStyles(currency: CURRENCY_ENUM, type: string): CurrencySymbolProps { if ( type === TransactionTypes.SENT || type === TransactionTypes.VERIFICATION_FEE || @@ -51,7 +51,7 @@ export function getCurrencyStyles(currency: string, type: string): CurrencySymbo ) { return { color: colors.darkSecondary, - symbol: currency === CURRENCY_ENUM.DOLLAR ? '$' : '', + symbol: CURRENCIES[currency].symbol, direction: '', } } @@ -64,14 +64,14 @@ export function getCurrencyStyles(currency: string, type: string): CurrencySymbo if (currency === CURRENCY_ENUM.DOLLAR) { return { color: colors.celoGreen, - symbol: '$', + symbol: CURRENCIES[CURRENCY_ENUM.DOLLAR].symbol, direction: '+', } } if (currency === CURRENCY_ENUM.GOLD) { return { color: colors.celoGold, - symbol: '', + symbol: CURRENCIES[CURRENCY_ENUM.GOLD].symbol, direction: '+', } } @@ -153,7 +153,7 @@ export class TransferFeedItem extends React.PureComponent { let comment: string | null = this.decryptComment(type) const timeFormatted = formatFeedTime(timestamp, i18n) const dateTimeFormatted = getDatetimeDisplayString(timestamp, t, i18n) - const currencyStyle = getCurrencyStyles(symbol, type) + const currencyStyle = getCurrencyStyles(resolveCurrency(symbol), type) const isPending = status === TransactionStatus.Pending const opacityStyle = { opacity: isPending ? 0.3 : 1 } diff --git a/packages/mobile/src/transactions/__snapshots__/ExchangeFeedItem.test.tsx.snap b/packages/mobile/src/transactions/__snapshots__/ExchangeFeedItem.test.tsx.snap index 92060faefd7..77a1527aa16 100644 --- a/packages/mobile/src/transactions/__snapshots__/ExchangeFeedItem.test.tsx.snap +++ b/packages/mobile/src/transactions/__snapshots__/ExchangeFeedItem.test.tsx.snap @@ -162,6 +162,7 @@ exports[`ExchangeFeedItem renders correctly 1`] = ` ] } > + 10.00 diff --git a/packages/mobile/src/transactions/__snapshots__/NoActivity.test.tsx.snap b/packages/mobile/src/transactions/__snapshots__/NoActivity.test.tsx.snap index b20c4cdab0e..09e3ca7f523 100644 --- a/packages/mobile/src/transactions/__snapshots__/NoActivity.test.tsx.snap +++ b/packages/mobile/src/transactions/__snapshots__/NoActivity.test.tsx.snap @@ -142,7 +142,7 @@ exports[`renders home 1`] = ` ] } > - sendCeloDollars + global:sendCeloDollars diff --git a/packages/mobile/src/transactions/__snapshots__/TransactionFeed.test.tsx.snap b/packages/mobile/src/transactions/__snapshots__/TransactionFeed.test.tsx.snap index e37dcd311a2..c0f1c0033f8 100644 --- a/packages/mobile/src/transactions/__snapshots__/TransactionFeed.test.tsx.snap +++ b/packages/mobile/src/transactions/__snapshots__/TransactionFeed.test.tsx.snap @@ -504,6 +504,7 @@ exports[`renders for error 1`] = ` ] } > + 30.00 @@ -1014,6 +1015,7 @@ exports[`renders for gold to dollar exchange properly 1`] = ` ] } > + 30.00 @@ -1216,6 +1218,7 @@ exports[`renders for gold to dollar exchange properly 1`] = ` ] } > + 200.00 @@ -1716,6 +1719,7 @@ exports[`renders for loading 1`] = ` ] } > + 30.00 @@ -2216,6 +2220,7 @@ exports[`renders for no transactions 1`] = ` ] } > + 30.00 @@ -2716,6 +2721,7 @@ exports[`renders for standbyTransactions 1`] = ` ] } > + 30.00 From 39895d36d596997eb284d4f48e18917e73f2b9ac Mon Sep 17 00:00:00 2001 From: Ashish Bhatia Date: Fri, 16 Aug 2019 18:37:22 -0700 Subject: [PATCH 11/21] [npm]Publish updated npm packages for @celo/walletkit and @celo/celocli (#446) Publish updated npm packages for @celo/walletkit and @celo/celocli ``` $ docker run -v $PWD/packages/walletkit:/tmp/npm_package -it --entrypoint bash node:8 $ npm install /tmp/npm_package # Inside docker ``` ``` $ docker run -v $PWD/packages/cli:/tmp/npm_package -it --entrypoint bash node:8 $ npm install /tmp/npm_package # Inside docker ``` --- packages/celotool/package.json | 2 +- packages/cli/package.json | 7 ++++--- packages/dappkit/package.json | 2 +- packages/docs/command-line-interface/account.md | 10 +++++----- packages/docs/command-line-interface/bonds.md | 14 +++++++------- packages/docs/command-line-interface/config.md | 4 ++-- packages/docs/command-line-interface/exchange.md | 6 +++--- packages/docs/command-line-interface/node.md | 2 +- packages/docs/command-line-interface/validator.md | 8 ++++---- .../docs/command-line-interface/validatorgroup.md | 10 +++++----- packages/mobile/package.json | 2 +- packages/transaction-metrics-exporter/package.json | 2 +- packages/walletkit/package.json | 6 ++++-- 13 files changed, 39 insertions(+), 36 deletions(-) diff --git a/packages/celotool/package.json b/packages/celotool/package.json index 49c6f7f3364..a5861b1723b 100644 --- a/packages/celotool/package.json +++ b/packages/celotool/package.json @@ -6,7 +6,7 @@ "author": "Celo", "license": "Apache-2.0", "dependencies": { - "@celo/walletkit": "^0.0.4", + "@celo/walletkit": "^0.0.10", "@google-cloud/monitoring": "0.7.1", "@google-cloud/pubsub": "^0.28.1", "@google-cloud/storage": "^2.4.3", diff --git a/packages/cli/package.json b/packages/cli/package.json index 8d2bbaf9488..d1360bc26db 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,7 +1,7 @@ { "name": "@celo/celocli", "description": "CLI Tool for transacting with the Celo protocol", - "version": "0.0.6", + "version": "0.0.15", "author": "Celo", "license": "Apache-2.0", "repository": "celo-org/celo-monorepo", @@ -24,10 +24,11 @@ "build": "rm -rf lib && tsc -b", "docs": "yarn oclif-dev readme --multi --dir=../docs/command-line-interface && yarn prettier ../docs/command-line-interface/*.md --write", "lint": "tslint -c tslint.json --project tsconfig.json", + "prepublishOnly": "yarn run build && oclif-dev manifest && oclif-dev readme", "test": "export TZ=UTC && jest --ci --silent" }, "dependencies": { - "@celo/walletkit": "^0.0.4", + "@celo/walletkit": "^0.0.10", "@oclif/command": "^1", "@oclif/config": "^1", "@oclif/plugin-help": "^2", @@ -71,7 +72,7 @@ "/oclif.manifest.json" ], "oclif": { - "commands": "./lib/commands", + "commands": "./lib/src/commands", "topics": { "account": { "description": "Manage your account, send and receive Celo Gold and Celo Dollars" diff --git a/packages/dappkit/package.json b/packages/dappkit/package.json index 71649db95d1..e64da20a893 100644 --- a/packages/dappkit/package.json +++ b/packages/dappkit/package.json @@ -5,8 +5,8 @@ "build": "tsc" }, "dependencies": { - "@celo/walletkit": "0.0.4", "@celo/utils": "0.0.6-beta3", + "@celo/walletkit": "0.0.10", "expo": "^34.0.1" }, "devDependencies": { diff --git a/packages/docs/command-line-interface/account.md b/packages/docs/command-line-interface/account.md index 7ecfc883e14..eb14ca99d32 100644 --- a/packages/docs/command-line-interface/account.md +++ b/packages/docs/command-line-interface/account.md @@ -16,7 +16,7 @@ EXAMPLE balance 0x5409ed021d9299bf6814279a6a1411a7e866a631 ``` -_See code: [packages/cli/src/commands/account/balance.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/account/balance.ts)_ +_See code: [packages/cli/src/src/commands/account/balance.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/account/balance.ts)_ ### New @@ -30,7 +30,7 @@ EXAMPLE new ``` -_See code: [packages/cli/src/commands/account/new.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/account/new.ts)_ +_See code: [packages/cli/src/src/commands/account/new.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/account/new.ts)_ ### Transferdollar @@ -50,7 +50,7 @@ EXAMPLE --amountInWei 1 ``` -_See code: [packages/cli/src/commands/account/transferdollar.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/account/transferdollar.ts)_ +_See code: [packages/cli/src/src/commands/account/transferdollar.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/account/transferdollar.ts)_ ### Transfergold @@ -70,7 +70,7 @@ EXAMPLE --amountInWei 1 ``` -_See code: [packages/cli/src/commands/account/transfergold.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/account/transfergold.ts)_ +_See code: [packages/cli/src/src/commands/account/transfergold.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/account/transfergold.ts)_ ### Unlock @@ -88,4 +88,4 @@ EXAMPLE unlock --account 0x5409ed021d9299bf6814279a6a1411a7e866a631 --password 1234 ``` -_See code: [packages/cli/src/commands/account/unlock.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/account/unlock.ts)_ +_See code: [packages/cli/src/src/commands/account/unlock.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/account/unlock.ts)_ diff --git a/packages/docs/command-line-interface/bonds.md b/packages/docs/command-line-interface/bonds.md index 29dd3c0f708..3f4fc3b57c3 100644 --- a/packages/docs/command-line-interface/bonds.md +++ b/packages/docs/command-line-interface/bonds.md @@ -23,7 +23,7 @@ EXAMPLE deposit --from 0x47e172F6CfB6c7D01C1574fa3E2Be7CC73269D95 --noticePeriod 8640 --goldAmount 1000000000000000000 ``` -_See code: [packages/cli/src/commands/bonds/deposit.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/bonds/deposit.ts)_ +_See code: [packages/cli/src/src/commands/bonds/deposit.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/bonds/deposit.ts)_ ### List @@ -37,7 +37,7 @@ EXAMPLE list 0x5409ed021d9299bf6814279a6a1411a7e866a631 ``` -_See code: [packages/cli/src/commands/bonds/list.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/bonds/list.ts)_ +_See code: [packages/cli/src/src/commands/bonds/list.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/bonds/list.ts)_ ### Notify @@ -58,7 +58,7 @@ EXAMPLE notify --noticePeriod=3600 --goldAmount=500 ``` -_See code: [packages/cli/src/commands/bonds/notify.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/bonds/notify.ts)_ +_See code: [packages/cli/src/src/commands/bonds/notify.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/bonds/notify.ts)_ ### Register @@ -75,7 +75,7 @@ EXAMPLE register ``` -_See code: [packages/cli/src/commands/bonds/register.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/bonds/register.ts)_ +_See code: [packages/cli/src/src/commands/bonds/register.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/bonds/register.ts)_ ### Rewards @@ -95,7 +95,7 @@ EXAMPLES rewards --delegate=0x56e172F6CfB6c7D01C1574fa3E2Be7CC73269D95 ``` -_See code: [packages/cli/src/commands/bonds/rewards.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/bonds/rewards.ts)_ +_See code: [packages/cli/src/src/commands/bonds/rewards.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/bonds/rewards.ts)_ ### Show @@ -116,7 +116,7 @@ EXAMPLES show 0x5409ed021d9299bf6814279a6a1411a7e866a631 --availabilityTime=1562206887 ``` -_See code: [packages/cli/src/commands/bonds/show.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/bonds/show.ts)_ +_See code: [packages/cli/src/src/commands/bonds/show.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/bonds/show.ts)_ ### Withdraw @@ -136,4 +136,4 @@ EXAMPLE withdraw 3600 ``` -_See code: [packages/cli/src/commands/bonds/withdraw.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/bonds/withdraw.ts)_ +_See code: [packages/cli/src/src/commands/bonds/withdraw.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/bonds/withdraw.ts)_ diff --git a/packages/docs/command-line-interface/config.md b/packages/docs/command-line-interface/config.md index f313c741e4e..2c67580e498 100644 --- a/packages/docs/command-line-interface/config.md +++ b/packages/docs/command-line-interface/config.md @@ -13,7 +13,7 @@ USAGE $ celocli config:get ``` -_See code: [packages/cli/src/commands/config/get.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/config/get.ts)_ +_See code: [packages/cli/src/src/commands/config/get.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/config/get.ts)_ ### Set @@ -27,4 +27,4 @@ OPTIONS --node=node (required) [default: ws://localhost:8546] Node URL ``` -_See code: [packages/cli/src/commands/config/set.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/config/set.ts)_ +_See code: [packages/cli/src/src/commands/config/set.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/config/set.ts)_ diff --git a/packages/docs/command-line-interface/exchange.md b/packages/docs/command-line-interface/exchange.md index 16fc35f9776..4d4f9619427 100644 --- a/packages/docs/command-line-interface/exchange.md +++ b/packages/docs/command-line-interface/exchange.md @@ -19,7 +19,7 @@ EXAMPLE list ``` -_See code: [packages/cli/src/commands/exchange/list.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/exchange/list.ts)_ +_See code: [packages/cli/src/src/commands/exchange/list.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/exchange/list.ts)_ ### Selldollar @@ -38,7 +38,7 @@ EXAMPLE selldollar 100 300 0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d ``` -_See code: [packages/cli/src/commands/exchange/selldollar.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/exchange/selldollar.ts)_ +_See code: [packages/cli/src/src/commands/exchange/selldollar.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/exchange/selldollar.ts)_ ### Sellgold @@ -57,4 +57,4 @@ EXAMPLE sellgold 100 300 0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d ``` -_See code: [packages/cli/src/commands/exchange/sellgold.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/exchange/sellgold.ts)_ +_See code: [packages/cli/src/src/commands/exchange/sellgold.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/exchange/sellgold.ts)_ diff --git a/packages/docs/command-line-interface/node.md b/packages/docs/command-line-interface/node.md index f4c73dc394b..33cbd42f6f8 100644 --- a/packages/docs/command-line-interface/node.md +++ b/packages/docs/command-line-interface/node.md @@ -13,4 +13,4 @@ USAGE $ celocli node:accounts ``` -_See code: [packages/cli/src/commands/node/accounts.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/node/accounts.ts)_ +_See code: [packages/cli/src/src/commands/node/accounts.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/node/accounts.ts)_ diff --git a/packages/docs/command-line-interface/validator.md b/packages/docs/command-line-interface/validator.md index d42c4d4e561..e039dad8cd0 100644 --- a/packages/docs/command-line-interface/validator.md +++ b/packages/docs/command-line-interface/validator.md @@ -22,7 +22,7 @@ EXAMPLES affiliation --unset --from 0x47e172f6cfb6c7d01c1574fa3e2be7cc73269d95 ``` -_See code: [packages/cli/src/commands/validator/affiliation.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/validator/affiliation.ts)_ +_See code: [packages/cli/src/src/commands/validator/affiliation.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/validator/affiliation.ts)_ ### List @@ -36,7 +36,7 @@ EXAMPLE list ``` -_See code: [packages/cli/src/commands/validator/list.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/validator/list.ts)_ +_See code: [packages/cli/src/src/commands/validator/list.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/validator/list.ts)_ ### Register @@ -63,7 +63,7 @@ EXAMPLE 96bad27bb1c0fd6080a75b0ec9f75b50298a2a8e04b02b2688c8104fca61fb00 ``` -_See code: [packages/cli/src/commands/validator/register.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/validator/register.ts)_ +_See code: [packages/cli/src/src/commands/validator/register.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/validator/register.ts)_ ### Show @@ -80,4 +80,4 @@ EXAMPLE show 0x97f7333c51897469E8D98E7af8653aAb468050a3 ``` -_See code: [packages/cli/src/commands/validator/show.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/validator/show.ts)_ +_See code: [packages/cli/src/src/commands/validator/show.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/validator/show.ts)_ diff --git a/packages/docs/command-line-interface/validatorgroup.md b/packages/docs/command-line-interface/validatorgroup.md index 47670a39cbb..8c51463e3ec 100644 --- a/packages/docs/command-line-interface/validatorgroup.md +++ b/packages/docs/command-line-interface/validatorgroup.md @@ -16,7 +16,7 @@ EXAMPLE list ``` -_See code: [packages/cli/src/commands/validatorgroup/list.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/validatorgroup/list.ts)_ +_See code: [packages/cli/src/src/commands/validatorgroup/list.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/validatorgroup/list.ts)_ ### Member @@ -39,7 +39,7 @@ EXAMPLES member --remove 0x47e172f6cfb6c7d01c1574fa3e2be7cc73269d95 ``` -_See code: [packages/cli/src/commands/validatorgroup/member.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/validatorgroup/member.ts)_ +_See code: [packages/cli/src/src/commands/validatorgroup/member.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/validatorgroup/member.ts)_ ### Register @@ -61,7 +61,7 @@ EXAMPLE "http://vgroup.com" ``` -_See code: [packages/cli/src/commands/validatorgroup/register.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/validatorgroup/register.ts)_ +_See code: [packages/cli/src/src/commands/validatorgroup/register.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/validatorgroup/register.ts)_ ### Show @@ -78,7 +78,7 @@ EXAMPLE show 0x97f7333c51897469E8D98E7af8653aAb468050a3 ``` -_See code: [packages/cli/src/commands/validatorgroup/show.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/validatorgroup/show.ts)_ +_See code: [packages/cli/src/src/commands/validatorgroup/show.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/validatorgroup/show.ts)_ ### Vote @@ -100,4 +100,4 @@ EXAMPLES vote --from 0x4443d0349e8b3075cba511a0a87796597602a0f1 --current ``` -_See code: [packages/cli/src/commands/validatorgroup/vote.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/validatorgroup/vote.ts)_ +_See code: [packages/cli/src/src/commands/validatorgroup/vote.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/src/commands/validatorgroup/vote.ts)_ diff --git a/packages/mobile/package.json b/packages/mobile/package.json index 4c5c12bb53f..0d73170ee01 100644 --- a/packages/mobile/package.json +++ b/packages/mobile/package.json @@ -45,7 +45,7 @@ }, "dependencies": { "@celo/client": "f7095b7", - "@celo/walletkit": "^0.0.4", + "@celo/walletkit": "^0.0.10", "@celo/react-native-sms-retriever": "git+https://github.com/celo-org/react-native-sms-retriever#d3a2fdb", "@celo/utils": "^0.0.6-beta3", "@react-native-community/netinfo": "^2.0.4", diff --git a/packages/transaction-metrics-exporter/package.json b/packages/transaction-metrics-exporter/package.json index 65fe2c32f52..57323d0f029 100644 --- a/packages/transaction-metrics-exporter/package.json +++ b/packages/transaction-metrics-exporter/package.json @@ -7,7 +7,7 @@ "license": "Apache-2.0", "private": true, "dependencies": { - "@celo/walletkit": "^0.0.4", + "@celo/walletkit": "^0.0.10", "express": "4.16.4", "lodash": "^4.17.14", "prom-client": "11.2.0", diff --git a/packages/walletkit/package.json b/packages/walletkit/package.json index 7a554828053..9cab185b294 100644 --- a/packages/walletkit/package.json +++ b/packages/walletkit/package.json @@ -1,6 +1,6 @@ { "name": "@celo/walletkit", - "version": "0.0.4", + "version": "0.0.10", "description": "Celo's WalletKit to interact with Celo network", "main": "./lib/index.js", "types": "./lib/index.d.ts", @@ -13,6 +13,7 @@ "lint": "tslint -c tslint.json --project tsconfig.json", "prebuild": "yarn clean", "build": "yarn run build:for-env alfajores", + "prepublishOnly": "yarn run build", "test": "export TZ=UTC && jest --ci --silent --coverage --runInBand test/attestations.test.ts test/erc20-utils.test.ts test/google-storage-utils.test.ts test/start_geth.sh test/transaction-utils.test.ts", "test:verbose": "export TZ=UTC && jest --ci --verbose --runInBand test/attestations.test.ts test/erc20-utils.test.ts test/google-storage-utils.test.ts test/start_geth.sh test/transaction-utils.test.ts", "test-licenses": "yarn licenses list --prod | grep '\\(─ GPL\\|─ (GPL-[1-9]\\.[0-9]\\+ OR GPL-[1-9]\\.[0-9]\\+)\\)' && echo 'Found GPL license(s). Use 'yarn licenses list --prod' to look up the offending package' || echo 'No GPL licenses found'" @@ -59,6 +60,7 @@ }, "files": [ "index.ts", - "lib/**/*" + "lib/**/*", + "bin/build-sdk.js" ] } From f19da688c19ca127390d71273b0a27e298f78ea1 Mon Sep 17 00:00:00 2001 From: Ashish Bhatia Date: Fri, 16 Aug 2019 19:23:48 -0700 Subject: [PATCH 12/21] Remove references to CeloLatestSyncMode (#597) --- packages/celotool/README.md | 2 +- packages/celotool/src/cmds/geth/run.ts | 2 +- packages/helm-charts/load-test/templates/statefulset.yaml | 2 +- packages/helm-charts/tracer-tool/scripts/run.sh | 2 +- packages/mobile/src/geth/consts.ts | 2 +- packages/mobile/src/geth/geth.ts | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/celotool/README.md b/packages/celotool/README.md index 728f9d45f02..cf710d2a016 100644 --- a/packages/celotool/README.md +++ b/packages/celotool/README.md @@ -78,4 +78,4 @@ a few useful commands to make running a node really easy. - Clone [Celo Blockchain repo](https://github.com/celo-org/celo-blockchain) - Build `celotooljs geth build --geth-dir -c` - Init `celotooljs geth init --geth-dir --data-dir -e ` -- Run `celotooljs geth run --geth-dir --data-dir --sync-mode ` +- Run `celotooljs geth run --geth-dir --data-dir --sync-mode ` diff --git a/packages/celotool/src/cmds/geth/run.ts b/packages/celotool/src/cmds/geth/run.ts index 9eb3cedd6ee..ef484d3af47 100644 --- a/packages/celotool/src/cmds/geth/run.ts +++ b/packages/celotool/src/cmds/geth/run.ts @@ -32,7 +32,7 @@ export const builder = (argv: yargs.Argv) => { default: '1101', }) .option('sync-mode', { - choices: ['full', 'fast', 'light', 'celolatest', 'ultralight'], + choices: ['full', 'fast', 'light', 'ultralight'], demandOption: true, }) .option('mining', { diff --git a/packages/helm-charts/load-test/templates/statefulset.yaml b/packages/helm-charts/load-test/templates/statefulset.yaml index 5274c9fcdc9..654fad995ca 100644 --- a/packages/helm-charts/load-test/templates/statefulset.yaml +++ b/packages/helm-charts/load-test/templates/statefulset.yaml @@ -76,7 +76,7 @@ spec: --wsorigins=* \ --wsapi=eth,net,web3,debug \ --networkid={{ .Values.networkID }} \ - --syncmode=celolatest \ + --syncmode=ultralight \ --consoleformat=json \ --consoleoutput=stdout \ --verbosity={{ .Values.geth.verbosity }}" diff --git a/packages/helm-charts/tracer-tool/scripts/run.sh b/packages/helm-charts/tracer-tool/scripts/run.sh index 9f24e59e4c8..acda36c5a6c 100644 --- a/packages/helm-charts/tracer-tool/scripts/run.sh +++ b/packages/helm-charts/tracer-tool/scripts/run.sh @@ -22,7 +22,7 @@ cat /root/staticnodes >> $DATA_DIR/static-nodes.json; echo "Running geth..."; -$CELOTOOL geth run --geth-dir $GETH_DIR --data-dir $DATA_DIR --sync-mode celolatest --verbosity 1 & +$CELOTOOL geth run --geth-dir $GETH_DIR --data-dir $DATA_DIR --sync-mode ultralight --verbosity 1 & sleep 15; diff --git a/packages/mobile/src/geth/consts.ts b/packages/mobile/src/geth/consts.ts index a8776db5d3c..cbee8723e8d 100644 --- a/packages/mobile/src/geth/consts.ts +++ b/packages/mobile/src/geth/consts.ts @@ -9,7 +9,7 @@ export const INVITE_REDEMPTION_GAS = 100000000000000000 // Valid sync mode values can be seen at https://github.com/celo-org/celo-blockchain/blob/8be27f7c044e35dbf63a42500a79805f1bddcfb8/mobile/geth.go#L43-L47 // Anything invalid will cause Geth to panic and app to crash. export const SYNC_MODE_LIGHT = 3 -export const SYNC_MODE_CELOLATEST = 4 +// Value of 4 corresponds to a deprecated sync mode. export const SYNC_MODE_ULTRALIGHT = 5 // Re-export from utils for convinience since we use these often diff --git a/packages/mobile/src/geth/geth.ts b/packages/mobile/src/geth/geth.ts index 987ac733c6d..2d80f16daae 100644 --- a/packages/mobile/src/geth/geth.ts +++ b/packages/mobile/src/geth/geth.ts @@ -22,8 +22,8 @@ export const FailedToFetchGenesisBlockError = new Error( // We are never going to run mobile node in full or fast mode. enum SyncMode { - CELO_LATEST = 'celolatest', LIGHT = 'light', + ULTRA_LIGHT = 'ultralight', } // Log levels correpond to the values defined in @@ -248,7 +248,7 @@ async function attemptGethCorruptionFix(geth: any) { export async function deleteChainData() { Logger.debug('Geth@deleteChainData', 'Deleting chain data') // Delete data for both the possible modes a mobile node could be running in. - const result1 = await deleteSingleChainData(SyncMode.CELO_LATEST) + const result1 = await deleteSingleChainData(SyncMode.ULTRA_LIGHT) const result2 = await deleteSingleChainData(SyncMode.LIGHT) return result1 || result2 } From c5d075852df540f71cdd9d602fdc60ea3540a535 Mon Sep 17 00:00:00 2001 From: Ashish Bhatia Date: Fri, 16 Aug 2019 21:40:34 -0700 Subject: [PATCH 13/21] [npm]Publish new @celo/walletkit and @celo/celocli for alfajores (#614) --- packages/celotool/package.json | 2 +- packages/cli/package.json | 6 +++--- packages/dappkit/package.json | 2 +- packages/mobile/package.json | 2 +- packages/transaction-metrics-exporter/package.json | 2 +- packages/walletkit/package.json | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/celotool/package.json b/packages/celotool/package.json index a5861b1723b..13a3fdb76a8 100644 --- a/packages/celotool/package.json +++ b/packages/celotool/package.json @@ -6,7 +6,7 @@ "author": "Celo", "license": "Apache-2.0", "dependencies": { - "@celo/walletkit": "^0.0.10", + "@celo/walletkit": "^0.0.13", "@google-cloud/monitoring": "0.7.1", "@google-cloud/pubsub": "^0.28.1", "@google-cloud/storage": "^2.4.3", diff --git a/packages/cli/package.json b/packages/cli/package.json index d1360bc26db..34d7c0ea410 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,7 +1,7 @@ { "name": "@celo/celocli", "description": "CLI Tool for transacting with the Celo protocol", - "version": "0.0.15", + "version": "0.0.17", "author": "Celo", "license": "Apache-2.0", "repository": "celo-org/celo-monorepo", @@ -24,11 +24,11 @@ "build": "rm -rf lib && tsc -b", "docs": "yarn oclif-dev readme --multi --dir=../docs/command-line-interface && yarn prettier ../docs/command-line-interface/*.md --write", "lint": "tslint -c tslint.json --project tsconfig.json", - "prepublishOnly": "yarn run build && oclif-dev manifest && oclif-dev readme", + "prepublishOnly": "yarn --cwd=../walletkit build && yarn run build && oclif-dev manifest && oclif-dev readme", "test": "export TZ=UTC && jest --ci --silent" }, "dependencies": { - "@celo/walletkit": "^0.0.10", + "@celo/walletkit": "^0.0.13", "@oclif/command": "^1", "@oclif/config": "^1", "@oclif/plugin-help": "^2", diff --git a/packages/dappkit/package.json b/packages/dappkit/package.json index e64da20a893..a91def2504f 100644 --- a/packages/dappkit/package.json +++ b/packages/dappkit/package.json @@ -6,7 +6,7 @@ }, "dependencies": { "@celo/utils": "0.0.6-beta3", - "@celo/walletkit": "0.0.10", + "@celo/walletkit": "0.0.13", "expo": "^34.0.1" }, "devDependencies": { diff --git a/packages/mobile/package.json b/packages/mobile/package.json index 0d73170ee01..5d18b94f6be 100644 --- a/packages/mobile/package.json +++ b/packages/mobile/package.json @@ -45,7 +45,7 @@ }, "dependencies": { "@celo/client": "f7095b7", - "@celo/walletkit": "^0.0.10", + "@celo/walletkit": "^0.0.13", "@celo/react-native-sms-retriever": "git+https://github.com/celo-org/react-native-sms-retriever#d3a2fdb", "@celo/utils": "^0.0.6-beta3", "@react-native-community/netinfo": "^2.0.4", diff --git a/packages/transaction-metrics-exporter/package.json b/packages/transaction-metrics-exporter/package.json index 57323d0f029..898e13bd710 100644 --- a/packages/transaction-metrics-exporter/package.json +++ b/packages/transaction-metrics-exporter/package.json @@ -7,7 +7,7 @@ "license": "Apache-2.0", "private": true, "dependencies": { - "@celo/walletkit": "^0.0.10", + "@celo/walletkit": "^0.0.13", "express": "4.16.4", "lodash": "^4.17.14", "prom-client": "11.2.0", diff --git a/packages/walletkit/package.json b/packages/walletkit/package.json index 9cab185b294..d6f6c3492e3 100644 --- a/packages/walletkit/package.json +++ b/packages/walletkit/package.json @@ -1,6 +1,6 @@ { "name": "@celo/walletkit", - "version": "0.0.10", + "version": "0.0.13", "description": "Celo's WalletKit to interact with Celo network", "main": "./lib/index.js", "types": "./lib/index.d.ts", From 6592d01992cc016c60b35fd69123cc178f27c608 Mon Sep 17 00:00:00 2001 From: J M Rossy Date: Sat, 17 Aug 2019 21:54:33 +0200 Subject: [PATCH 14/21] Fix fees for accounts with low balances (#584) --- packages/mobile/src/fees/saga.ts | 77 ++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/packages/mobile/src/fees/saga.ts b/packages/mobile/src/fees/saga.ts index ac0e681dad4..9bff7c3b434 100644 --- a/packages/mobile/src/fees/saga.ts +++ b/packages/mobile/src/fees/saga.ts @@ -1,51 +1,60 @@ import { getStableTokenContract } from '@celo/walletkit' import { call, put, select, spawn, takeLeading } from 'redux-saga/effects' +import { showError } from 'src/alert/actions' +import { ErrorMessages } from 'src/app/ErrorMessages' +import { ALERT_BANNER_DURATION } from 'src/config' import { getReclaimEscrowFee } from 'src/escrow/saga' import { Actions, EstimateFeeAction, feeEstimated, FeeType } from 'src/fees/actions' import { getInvitationVerificationFee } from 'src/invite/saga' import { getSendFee } from 'src/send/saga' import { CeloDefaultRecipient } from 'src/send/Send' import Logger from 'src/utils/Logger' +import { web3 } from 'src/web3/contracts' import { currentAccountSelector } from 'src/web3/selectors' const TAG = 'fees/saga' +// TODO: skip fee update if it was calculated recently export function* estimateFeeSaga({ feeType }: EstimateFeeAction) { - Logger.debug(TAG + '@estimateFeeSaga', `updating for ${feeType}`) - - // TODO: skip fee update if it was calculated recently - const account = yield select(currentAccountSelector) - - let feeInWei - - switch (feeType) { - case FeeType.INVITE: - feeInWei = yield call(getInvitationVerificationFee) - break - case FeeType.SEND: - // Just use default values here since it doesn't matter for fee estimation - feeInWei = yield call(getSendFee, account, getStableTokenContract, { - recipientAddress: CeloDefaultRecipient.address, - amount: '1', - comment: 'Coffee or Tea?', - }) - break - case FeeType.EXCHANGE: - // TODO - break - case FeeType.RECLAIM_ESCROW: - // Just use default values here since it doesn't matter for fee estimation - feeInWei = yield call( - getReclaimEscrowFee, - CeloDefaultRecipient.address, - CeloDefaultRecipient.address - ) - break - } + Logger.debug(`${TAG}/estimateFeeSaga`, `updating for ${feeType}`) + + try { + const account = yield select(currentAccountSelector) + + let feeInWei + + switch (feeType) { + case FeeType.INVITE: + feeInWei = yield call(getInvitationVerificationFee) + break + case FeeType.SEND: + // Just use default values here since it doesn't matter for fee estimation + feeInWei = yield call(getSendFee, account, getStableTokenContract, { + recipientAddress: CeloDefaultRecipient.address, + amount: web3.utils.fromWei('1'), + comment: 'Coffee or Tea?', + }) + break + case FeeType.EXCHANGE: + // TODO + break + case FeeType.RECLAIM_ESCROW: + // Just use default values here since it doesn't matter for fee estimation + feeInWei = yield call( + getReclaimEscrowFee, + CeloDefaultRecipient.address, + CeloDefaultRecipient.address + ) + break + } - if (feeInWei) { - Logger.debug(`${TAG}/estimateFeeSaga`, `New fee is: ${feeInWei}`) - yield put(feeEstimated(feeType, feeInWei)) + if (feeInWei) { + Logger.debug(`${TAG}/estimateFeeSaga`, `New fee is: ${feeInWei}`) + yield put(feeEstimated(feeType, feeInWei)) + } + } catch (error) { + Logger.error(`${TAG}/estimateFeeSaga`, 'Error estimating fee', error) + yield put(showError(ErrorMessages.CALCULATE_FEE_FAILED, ALERT_BANNER_DURATION)) } } From d4349cb8a53588b10b82576337cd2caf8db4233d Mon Sep 17 00:00:00 2001 From: sallyjyl Date: Sat, 17 Aug 2019 23:01:20 +0200 Subject: [PATCH 15/21] [Dappkit] Auth screens WIP (#589) --- packages/mobile/locales/en-US/dappkit.json | 15 ++ packages/mobile/locales/en-US/index.ts | 2 + packages/mobile/locales/es-AR/dappkit.json | 15 ++ .../src/dappkit/DappKitAccountScreen.tsx | 109 +++++++++-- .../src/dappkit/DappKitSignTxScreen.tsx | 178 ++++++++++++++++++ .../src/dappkit/DappKitTxDataScreen.tsx | 53 ++++++ .../src/dappkit/DappKitTxSignScreen.tsx | 67 ------- packages/mobile/src/dappkit/dappkit.ts | 2 +- packages/mobile/src/i18n.ts | 1 + packages/mobile/src/icons/DappkitExchange.tsx | 50 +++++ packages/mobile/src/navigator/Navigator.tsx | 6 +- packages/mobile/src/navigator/Screens.tsx | 1 + 12 files changed, 412 insertions(+), 87 deletions(-) create mode 100644 packages/mobile/locales/en-US/dappkit.json create mode 100644 packages/mobile/locales/es-AR/dappkit.json create mode 100644 packages/mobile/src/dappkit/DappKitSignTxScreen.tsx create mode 100644 packages/mobile/src/dappkit/DappKitTxDataScreen.tsx delete mode 100644 packages/mobile/src/dappkit/DappKitTxSignScreen.tsx create mode 100644 packages/mobile/src/icons/DappkitExchange.tsx diff --git a/packages/mobile/locales/en-US/dappkit.json b/packages/mobile/locales/en-US/dappkit.json new file mode 100644 index 00000000000..a8d803e27da --- /dev/null +++ b/packages/mobile/locales/en-US/dappkit.json @@ -0,0 +1,15 @@ +{ + "connectToWallet": "Savings Circle would like to connect to Celo Wallet", + "connect": "Connect", + "cancel": "Cancel", + "allow": "Allow", + "address": "Address", + "transaction": { + "operation": "Operation", + "data": "Data", + "signTX": "Sign TX", + "details": "Show details" + }, + "shareInfo": "Share the following info:", + "data": "Data" +} diff --git a/packages/mobile/locales/en-US/index.ts b/packages/mobile/locales/en-US/index.ts index b54e4dd32af..aef6a188502 100644 --- a/packages/mobile/locales/en-US/index.ts +++ b/packages/mobile/locales/en-US/index.ts @@ -1,5 +1,6 @@ import accountScreen10 from '@celo/mobile/locales/en-US/accountScreen10.json' import backupKeyFlow6 from '@celo/mobile/locales/en-US/backupKeyFlow6.json' +import dappkit from '@celo/mobile/locales/en-US/dappkit.json' import dev from '@celo/mobile/locales/en-US/dev.json' import exchangeFlow9 from '@celo/mobile/locales/en-US/exchangeFlow9.json' import global from '@celo/mobile/locales/en-US/global.json' @@ -28,4 +29,5 @@ export default { sendFlow7, walletFlow5, dev, + dappkit, } diff --git a/packages/mobile/locales/es-AR/dappkit.json b/packages/mobile/locales/es-AR/dappkit.json new file mode 100644 index 00000000000..106fb8340c6 --- /dev/null +++ b/packages/mobile/locales/es-AR/dappkit.json @@ -0,0 +1,15 @@ +{ + "connectToWallet": "Círculo de Ahorro le gustaría conectarse a Celo Monedero", + "connect": "Conectar", + "cancel": "Cancelar", + "allow": "Permitir", + "address": "Dirección", + "transaction": { + "operation": "Operación", + "data": "Datos", + "signTX": "Boleto TX", + "details": "Mostrar detalles" + }, + "shareInfo": "Comparte la siguiente información:", + "data": "Datos" +} diff --git a/packages/mobile/src/dappkit/DappKitAccountScreen.tsx b/packages/mobile/src/dappkit/DappKitAccountScreen.tsx index 3a568ebf44b..3e8537ec90d 100644 --- a/packages/mobile/src/dappkit/DappKitAccountScreen.tsx +++ b/packages/mobile/src/dappkit/DappKitAccountScreen.tsx @@ -1,15 +1,17 @@ -import FullscreenCTA from '@celo/react-components/components/FullscreenCTA' -import { componentStyles } from '@celo/react-components/styles/styles' +import Button, { BtnTypes } from '@celo/react-components/components/Button' +import colors from '@celo/react-components/styles/colors' +import fontStyles from '@celo/react-components/styles/fonts' import { AccountAuthRequest } from '@celo/utils/src/dappkit' import * as React from 'react' import { withNamespaces, WithNamespaces } from 'react-i18next' -import { Text, View } from 'react-native' +import { ScrollView, StyleSheet, Text, View } from 'react-native' import { NavigationParams, NavigationScreenProp } from 'react-navigation' import { connect } from 'react-redux' import { e164NumberSelector } from 'src/account/reducer' import { approveAccountAuth } from 'src/dappkit/dappkit' import { Namespaces } from 'src/i18n' -import { navigateHome } from 'src/navigator/NavigationService' +import DappkitExchangeIcon from 'src/icons/DappkitExchange' +import { navigateBack, navigateHome } from 'src/navigator/NavigationService' import { RootState } from 'src/redux/reducers' import Logger from 'src/utils/Logger' import { currentAccountSelector } from 'src/web3/selectors' @@ -70,24 +72,97 @@ class DappKitAccountAuthScreen extends React.Component { navigateHome({ dispatchAfterNavigate: approveAccountAuth(request) }) } + cancel = () => { + navigateBack() + } + render() { + const { t, account } = this.props return ( - - - - {this.props.account} - + + + + + + {t('connectToWallet')} + + {t('shareInfo')} + + + {t('address')} + {account} + + + + +