-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup truffle suite with drizzle on the front end
- Loading branch information
Showing
19 changed files
with
3,266 additions
and
666 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,10 @@ node_modules/ | |
npm-debug.log | ||
yarn-error.log | ||
|
||
# Testing | ||
# | ||
coverage/ | ||
|
||
# BUCK | ||
buck-out/ | ||
\.buckd/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('web3-fake-provider'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('web3-fake-provider'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
contract StringStore { | ||
string public myString = "Hello World"; | ||
|
||
function set(string x) public { | ||
myString = x; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
resolver: { | ||
extraNodeModules: require('node-libs-react-native') | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<View style={styles.container}> | ||
<Text style={styles.welcome}>Welcome to React Native!</Text> | ||
<Text style={styles.instructions}>To get started, edit App.js</Text> | ||
<Text style={styles.instructions}>{instructions}</Text> | ||
<Button title={'Log in with uPort'} onPress={this.uPortLogin} /> | ||
</View> | ||
<DrizzleProvider> | ||
<Home /> | ||
</DrizzleProvider> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
backgroundColor: '#F5FCFF' | ||
}, | ||
welcome: { | ||
fontSize: 20, | ||
textAlign: 'center', | ||
margin: 10 | ||
}, | ||
instructions: { | ||
textAlign: 'center', | ||
color: '#333333', | ||
marginBottom: 5 | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { PureComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { DrizzleContext } from 'drizzle-react'; | ||
import { connect } from 'react-redux'; | ||
import { Drizzle, generateStore } from 'drizzle'; | ||
|
||
const drizzleOptions = { | ||
contracts: [] | ||
}; | ||
|
||
const drizzleStore = generateStore(drizzleOptions); | ||
const drizzle = new Drizzle(drizzleOptions, drizzleStore); | ||
|
||
// Drizzle init shim | ||
// https://github.com/trufflesuite/drizzle/pull/100 | ||
drizzleStore.dispatch({ | ||
type: 'DRIZZLE_INITIALIZING', | ||
drizzle: drizzle, | ||
options: drizzleOptions | ||
}); | ||
|
||
export default class DrizzleProvider extends PureComponent { | ||
static propTypes = { | ||
children: PropTypes.element.isRequired | ||
}; | ||
|
||
render() { | ||
return ( | ||
<DrizzleContext.Provider drizzle={drizzle} options={drizzleOptions}> | ||
{this.props.children} | ||
</DrizzleContext.Provider> | ||
); | ||
} | ||
} | ||
|
||
export const connectDrizzleState = (...connectArgs) => Component => props => { | ||
const ConnectedComponent = connect(...connectArgs)(Component); | ||
|
||
return ( | ||
<DrizzleContext.Consumer> | ||
{drizzleContext => ( | ||
<ConnectedComponent | ||
drizzleInitialized={drizzleContext.initialized} | ||
{...drizzleContext} | ||
{...props} | ||
store={drizzleContext.drizzle.store} | ||
/> | ||
)} | ||
</DrizzleContext.Consumer> | ||
); | ||
}; |
Oops, something went wrong.