From b58532ec71d8633851268a1614b21d47c147f68f Mon Sep 17 00:00:00 2001 From: Dan Hughes Date: Wed, 21 Feb 2018 22:02:38 +0000 Subject: [PATCH] Conditionally use struct or a no-op based on NODE_ENV --- .gitignore | 4 +++ package-lock.json | 51 ++++++++++++++++++++++++++++++++++++++- package.json | 7 ++++-- src/actions/structures.js | 23 +++++++++--------- src/lib/.gitkeep | 0 5 files changed, 71 insertions(+), 14 deletions(-) create mode 100644 src/lib/.gitkeep diff --git a/.gitignore b/.gitignore index f53349d..b35c057 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,10 @@ # production /build +# manually copied lib files for compilation +/src/lib/* +!/src/lib/.gitkeep + # misc .DS_Store .env diff --git a/package-lock.json b/package-lock.json index 35420a5..cc9fd08 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3250,6 +3250,19 @@ "run-queue": "1.0.3" } }, + "copyfiles": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/copyfiles/-/copyfiles-1.2.0.tgz", + "integrity": "sha1-qNo6xBqiIgrim9PFi2mEKU8sWTw=", + "requires": { + "glob": "7.1.2", + "ltcdr": "2.2.1", + "minimatch": "3.0.4", + "mkdirp": "0.5.1", + "noms": "0.0.0", + "through2": "2.0.3" + } + }, "core-js": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/core-js/-/core-js-1.2.7.tgz", @@ -7777,6 +7790,11 @@ "yallist": "2.1.2" } }, + "ltcdr": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ltcdr/-/ltcdr-2.2.1.tgz", + "integrity": "sha1-Wrh60dTB2rjowIu/A37gwZAih88=" + }, "macaddress": { "version": "0.2.8", "resolved": "https://registry.npmjs.org/macaddress/-/macaddress-0.2.8.tgz", @@ -8205,6 +8223,38 @@ "resolved": "https://registry.npmjs.org/node-status-codes/-/node-status-codes-1.0.0.tgz", "integrity": "sha1-WuVUHQJGRdMqWPzdyc7s6nrjrC8=" }, + "noms": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/noms/-/noms-0.0.0.tgz", + "integrity": "sha1-2o69nzr51nYJGbJ9nNyAkqczKFk=", + "requires": { + "inherits": "2.0.3", + "readable-stream": "1.0.34" + }, + "dependencies": { + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" + }, + "readable-stream": { + "version": "1.0.34", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz", + "integrity": "sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw=", + "requires": { + "core-util-is": "1.0.2", + "inherits": "2.0.3", + "isarray": "0.0.1", + "string_decoder": "0.10.31" + } + }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=" + } + } + }, "normalize-package-data": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.4.0.tgz", @@ -11862,7 +11912,6 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.3.tgz", "integrity": "sha1-AARWmzfHx0ujnEPzzteNGtlBQL4=", - "dev": true, "requires": { "readable-stream": "2.3.3", "xtend": "4.0.1" diff --git a/package.json b/package.json index 10e463b..65a5a39 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.1.0", "private": true, "dependencies": { + "copyfiles": "^1.2.0", "flux-standard-action": "^2.0.1", "human-time": "0.0.1", "react": "^16.2.0", @@ -18,7 +19,8 @@ "build": "react-scripts build", "test": "eslint --ignore-path .gitignore .", "eject": "react-scripts eject", - "storybook": "start-storybook -p 3000 -c .storybook" + "storybook": "start-storybook -p 3000 -c .storybook", + "postinstall": "copyfiles -f node_modules/superstruct/lib/index.js src/lib/superstruct" }, "devDependencies": { "@storybook/addon-info": "^3.3.11", @@ -27,5 +29,6 @@ "redux-devtools": "^3.4.1", "redux-devtools-dock-monitor": "^1.1.3", "redux-devtools-log-monitor": "^1.4.0" - } + }, + "eslintIgnore": ["src/lib/superstruct/index.js"] } diff --git a/src/actions/structures.js b/src/actions/structures.js index 901fb6c..7940e41 100644 --- a/src/actions/structures.js +++ b/src/actions/structures.js @@ -1,17 +1,18 @@ // https://github.com/HeathWallace/ethereum-pos/issues/28 -// import { struct } from 'superstruct'; +import { struct as structLib } from '../lib/superstruct'; +import env from '../utils/environment'; -const struct = () => x => x; +const structFake = () => x => x; +structFake.union = () => {}; + +const struct = env.NODE_ENV === 'production' ? structFake : structLib; export const Transaction = struct({ - 'address': 'string', - 'topics': ['string'], - 'data': 'string', - 'blockNumber': 'string', - 'timeStamp': 'string', - 'gasPrice': 'string', - 'gasUsed': 'string', - 'logIndex': 'string', + 'from': 'string', + 'timestamp': 'number', + 'to': 'string', + 'tokenInfo': struct.union(['boolean', 'object']), // API is inconsistent with what it returns here. 'transactionHash': 'string', - 'transactionIndex': 'string', + 'type': 'string', + 'value': 'string', }); diff --git a/src/lib/.gitkeep b/src/lib/.gitkeep new file mode 100644 index 0000000..e69de29