Skip to content

Commit

Permalink
Conditionally use struct or a no-op based on NODE_ENV
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Hughes committed Feb 21, 2018
1 parent 623150d commit b58532e
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
# production
/build

# manually copied lib files for compilation
/src/lib/*
!/src/lib/.gitkeep

# misc
.DS_Store
.env
Expand Down
51 changes: 50 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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"]
}
23 changes: 12 additions & 11 deletions src/actions/structures.js
Original file line number Diff line number Diff line change
@@ -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',
});
Empty file added src/lib/.gitkeep
Empty file.

0 comments on commit b58532e

Please sign in to comment.