diff --git a/.babelrc b/.babelrc deleted file mode 100644 index f2aae2d..0000000 --- a/.babelrc +++ /dev/null @@ -1,7 +0,0 @@ -{ - "presets": [ - "module:metro-react-native-babel-preset", - "module:react-native-dotenv", - "react-native-uport-connect/babel-preset.js" - ] -} diff --git a/.eslintrc.js b/.eslintrc.js index 6fc43ea..924e2f0 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -2,6 +2,7 @@ module.exports = { parser: 'babel-eslint', env: { es6: true, + node: true, browser: true, jest: true }, @@ -16,5 +17,8 @@ module.exports = { pragma: 'React', version: '16.5.0' } + }, + rules: { + 'react/display-name': 'off' } }; diff --git a/.gitignore b/.gitignore index 0711849..33debb8 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,10 @@ node_modules/ npm-debug.log yarn-error.log +# Testing +# +coverage/ + # BUCK buck-out/ \.buckd/ diff --git a/__mocks__/web3-providers-http.js b/__mocks__/web3-providers-http.js new file mode 100644 index 0000000..2884bfb --- /dev/null +++ b/__mocks__/web3-providers-http.js @@ -0,0 +1 @@ +module.exports = require('web3-fake-provider'); diff --git a/__mocks__/web3-providers-ws.js b/__mocks__/web3-providers-ws.js new file mode 100644 index 0000000..2884bfb --- /dev/null +++ b/__mocks__/web3-providers-ws.js @@ -0,0 +1 @@ +module.exports = require('web3-fake-provider'); diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 0000000..1912dac --- /dev/null +++ b/babel.config.js @@ -0,0 +1,16 @@ +module.exports = api => { + api.cache(true); + + return { + presets: [ + 'module:metro-react-native-babel-preset', + 'module:react-native-dotenv', + 'react-native-uport-connect/babel-preset.js' + ], + plugins: [ + '@babel/plugin-transform-flow-strip-types', + '@babel/plugin-transform-runtime', + '@babel/plugin-proposal-class-properties' + ].map(require.resolve) + }; +}; diff --git a/contracts/StringStore.sol b/contracts/StringStore.sol new file mode 100644 index 0000000..183b15b --- /dev/null +++ b/contracts/StringStore.sol @@ -0,0 +1,9 @@ +pragma solidity ^0.4.24; + +contract StringStore { + string public myString = "Hello World"; + + function set(string x) public { + myString = x; + } +} diff --git a/index.js b/index.js index fc17d11..14b4a6b 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ /** @format */ - +import './polyfill'; import { AppRegistry } from 'react-native'; import App from './src/App'; import { name as appName } from './app.json'; diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..5bcd4af --- /dev/null +++ b/jest.config.js @@ -0,0 +1,11 @@ +module.exports = { + preset: 'react-native', + transform: { + '^.+\\.js$': 'babel-jest' + }, + globals: { + window: true + }, + transformIgnorePatterns: ['node_modules/(?!react-|drizzle).+\\.js$'], + setupFiles: ['./test/setup.js'] +}; diff --git a/package.json b/package.json index e670f46..f91ce6e 100644 --- a/package.json +++ b/package.json @@ -3,45 +3,59 @@ "version": "0.0.1", "private": true, "scripts": { - "start": "react-native start", + "start": "concurrently -n w: npm:start:*", + "start:react-native": "react-native start", + "start:ganache": "yarn build:truffle && ganache-cli", + "build:truffle": "truffle compile", "ios": "react-native run-ios", "lint": "eslint .", - "jest": "jest", + "jest": "yarn build:truffle && jest", "test": "npm run lint && npm run jest", - "prettier": "prettier \"**/*.{js,json,css,md}\" --write" + "prettier": "prettier \"**/*.{js,json,css,md}\" --write", + "postinstall": "node ./scripts/post-install.js" }, "dependencies": { + "@babel/plugin-proposal-class-properties": "^7.1.0", + "Base64": "^1.0.1", + "drizzle": "git+https://github.com/trufflesuite/drizzle.git#1.2.3", + "drizzle-react": "^1.2.0", + "eth-block-tracker": "^4.0.3", + "node-libs-react-native": "^1.0.3", "react": "16.5.0", "react-native": "0.57.2", "react-native-dotenv": "^0.2.0", - "react-native-uport-connect": "git+https://github.com/barlock/react-native-uport-connect.git#support-babel-7" + "react-native-uport-connect": "^0.1.3", + "react-redux": "^5.0.7", + "redux": "^4.0.1", + "whatwg-url": "^7.0.0" }, "devDependencies": { + "@babel/core": "^7.1.2", "@babel/runtime": "^7.1.2", "babel-core": "7.0.0-bridge.0", "babel-eslint": "^10.0.1", "babel-jest": "^23.6.0", + "concurrently": "^4.0.1", "eslint": "^5.6.1", "eslint-config-prettier": "^3.1.0", "eslint-plugin-prettier": "^3.0.0", "eslint-plugin-react": "^7.11.1", "eslint-plugin-react-native": "^3.3.0", + "fs-extra": "^7.0.0", + "ganache-cli": "^6.1.8", "husky": "^1.1.1", "jest": "^23.6.0", "metro-react-native-babel-preset": "^0.48.0", "prettier": "^1.14.3", "pretty-quick": "^1.7.0", - "react-test-renderer": "16.5.0" + "prop-types": "^15.6.2", + "react-test-renderer": "16.5.0", + "truffle": "^5.0.0-next.12", + "web3-fake-provider": "^0.1.0" }, "resolutions": { "babel-core": "7.0.0-bridge.0" }, - "jest": { - "preset": "react-native", - "transform": { - "^.+\\.js$": "/node_modules/react-native/jest/preprocessor.js" - } - }, "husky": { "hooks": { "pre-commit": "pretty-quick --staged" diff --git a/polyfill.js b/polyfill.js new file mode 100644 index 0000000..818387f --- /dev/null +++ b/polyfill.js @@ -0,0 +1,9 @@ +// https://github.com/trufflesuite/drizzle/issues/130 + +import 'node-libs-react-native/globals'; +import { URL, URLSearchParams } from 'whatwg-url'; +import { btoa } from 'Base64'; + +global.URL = URL; +global.URLSearchParams = URLSearchParams; +global.btoa = btoa; diff --git a/rn-cli.config.js b/rn-cli.config.js new file mode 100644 index 0000000..94c2b4e --- /dev/null +++ b/rn-cli.config.js @@ -0,0 +1,5 @@ +module.exports = { + resolver: { + extraNodeModules: require('node-libs-react-native') + } +}; diff --git a/scripts/post-install.js b/scripts/post-install.js new file mode 100644 index 0000000..30ddc85 --- /dev/null +++ b/scripts/post-install.js @@ -0,0 +1,13 @@ +const fs = require('fs-extra'); +const drizzlePackage = require('../node_modules/drizzle/package.json'); + +(async () => { + // https://github.com/trufflesuite/drizzle/issues/130 + drizzlePackage['main'] = './src/index.js'; + + await fs.writeFile( + './node_modules/drizzle/package.json', + JSON.stringify(drizzlePackage, null, 2) + ); + // eslint-disable-next-line no-console +})().catch(console.log); diff --git a/src/App.js b/src/App.js index 1aff6c4..0dfac23 100644 --- a/src/App.js +++ b/src/App.js @@ -1,61 +1,13 @@ import React, { Component } from 'react'; -import { Platform, StyleSheet, Text, View, Button } from 'react-native'; -import configureUportConnect from 'react-native-uport-connect'; -import { - UPORT_APP_NAME, - UPORT_APP_ADDRESS, - UPORT_PRIVATE_KEY -} from 'react-native-dotenv'; - -const instructions = Platform.select({ - ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu', - android: - 'Double tap R on your keyboard to reload,\n' + - 'Shake or press menu button for dev menu' -}); +import DrizzleProvider from './components/DrizzleProvider'; +import Home from './screens/Home'; export default class App extends Component { - uPortLogin = async () => { - const { uport } = configureUportConnect({ - appName: UPORT_APP_NAME, - appAddress: UPORT_APP_ADDRESS, - privateKey: UPORT_PRIVATE_KEY - }); - - const result = await uport.requestCredentials({ - requested: ['name', 'avatar'] - }); - - alert(JSON.stringify(result)); - }; - render() { return ( - - Welcome to React Native! - To get started, edit App.js - {instructions} -