Skip to content
Permalink
Browse files

Updates

* Updated for more recently babel version
* Added another event to check on Simple Store
* UI improvements
* Updated loom-js and loom-truffle-provider
  • Loading branch information...
eduardonunesp committed Aug 9, 2018
1 parent aabbfc0 commit 1ef600716270872bca2dc4dcd9a48080579d4b31
Showing with 2,372 additions and 280 deletions.
  1. +2 −7 .babelrc
  2. +6 −0 contracts/SimpleStore.sol
  3. +16 −12 package.json
  4. +17 −0 src/contract.js
  5. +26 −7 src/index.js
  6. +14 −12 webpack.config.js
  7. +2,291 −242 yarn.lock
@@ -1,9 +1,4 @@
{
"presets": [
"es2015",
"react"
],
"plugins": [
"transform-async-to-generator"
]
"presets": ["@babel/react"],
"plugins": ["@babel/plugin-transform-runtime"]
}
@@ -4,12 +4,18 @@ contract SimpleStore {
uint256 value;

event NewValueSet(uint256 indexed _value, address _sender);
event NewValueSetAgain(uint256 indexed _value, address _sender);

function set(uint256 _value) public {
value = _value;
emit NewValueSet(value, msg.sender);
}

function setAgain(uint256 _value) public {
value = _value;
emit NewValueSetAgain(value, msg.sender);
}

function get() public view returns (uint256, address) {
return (value, msg.sender);
}
@@ -9,22 +9,26 @@
"serve": "webpack-dev-server --hot --content-base ./dist"
},
"dependencies": {
"loom-js": "^1.14.0",
"loom-truffle-provider": "^0.4.0",
"loom-js": "^1.17.0",
"loom-truffle-provider": "^0.5.0",
"truffle": "^4.1.13"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-plugin-transform-async-to-generator": "^6.24.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"regenerator-runtime": "^0.12.0",
"@babel/core": "^7.0.0-beta.46",
"@babel/plugin-transform-runtime": "^7.0.0-beta.46",
"@babel/preset-env": "^7.0.0-beta.46",
"@babel/preset-react": "^7.0.0-beta.55",
"@babel/runtime": "^7.0.0-beta.46",
"babel-cli": "^6.26.0",
"babel-loader": "^8.0.0-beta.2",
"react": "^16.3.2",
"react-dom": "^16.3.2",
"react-router-dom": "^4.3.1",
"regenerator-runtime": "^0.11.1",
"request-promise": "^4.2.2",
"web3": "^1.0.0-beta.34",
"webpack": "^4.14.0",
"webpack-cli": "^3.0.8",
"webpack": "^4.8.1",
"webpack-cli": "^2.1.3",
"webpack-dev-server": "^3.1.4"
}
}
@@ -58,6 +58,16 @@ export default class Contract {
}
}
})

this.simpleStoreInstance.events.NewValueSetAgain({ filter: { _value: 47 }}, (err, event) => {
if (err) console.error('Error on event', err)
else {
setTimeout(() => alert("Loooomy help me :)"))
if (this.onEvent) {
this.onEvent(event.returnValues)
}
}
})
}

addEventListener(fn) {
@@ -69,6 +79,13 @@ export default class Contract {
}

async setValue(value) {
// Just a small test with Loomy
if (value == 47) {
return await this.simpleStoreInstance.methods.setAgain(value).send({
from: this.currentUserAddress
})
}

return await this.simpleStoreInstance.methods.set(value).send({
from: this.currentUserAddress
})
@@ -6,13 +6,17 @@ const Index = class Index extends React.Component {
constructor(props) {
super(props)

this.textInput = React.createRef();

this.contract = new Contract()
this.value = 0

this.state = {
value: 0,
isValid: false,
tx: null
isSending: false,
tx: null,
tries: 0
}
}

@@ -30,24 +34,39 @@ const Index = class Index extends React.Component {
}

async confirmValue() {
const tx = await this.contract.setValue(this.value)
this.setState({ tx })
this.setState({isSending: true})
try {
const tx = await this.contract.setValue(this.value)
const tries = this.state.tries + 1
this.textInput.current.value = ''
this.setState({ tx, tries, isValid: false })
} catch (err) {
console.error('Ops, some error happen:', err)
}
this.setState({isSending: false})
}

render() {
const loomyAlert = (
<div className="alert alert-warning">
I dare you to type 47 and press Confirm !
</div>
)

return (
<div className="container" style={{ marginTop: 10 }}>
<form>
<form onSubmit={e => { e.preventDefault(); }}>
<div className="form-group">
<label>Value</label>
<input type="number" className="form-control" onChange={(event) => this.onChangeHandler(event)} />
<input type="number" className="form-control" onChange={(event) => this.onChangeHandler(event)} ref={this.textInput}/>
<small className="form-text text-muted">Set a number</small>
</div>
<button type="button" disabled={!this.state.isValid} className="btn btn-primary" onClick={() => this.confirmValue()}>Confirm</button>
<button type="button" disabled={!this.state.isValid || this.state.isSending} className="btn btn-primary" onClick={() => this.confirmValue()}>Confirm</button>
</form>
<div className="alert alert-success">
Value set is {this.state.value} (this value only updates if values is 10)
Value set is {this.state.value} (this value only updates if values is 10 or ...)
</div>
{ this.state.tries === 3 && loomyAlert }
<hr />
<pre>
{this.state.tx && JSON.stringify(this.state.tx, null, 2)}
@@ -1,21 +1,23 @@
const webpack = require('webpack')

module.exports = {
context: __dirname + "/src",
entry: [
"regenerator-runtime/runtime",
"./index"
],
context: __dirname + '/src',
entry: ['regenerator-runtime/runtime', './index'],
output: {
path: __dirname + "/dist",
filename: "bundle.js"
path: __dirname + '/dist',
filename: 'bundle.js'
},
devServer: {
historyApiFallback: true
},
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
}]
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
}
]
},
plugins: [
new webpack.DefinePlugin({

0 comments on commit 1ef6007

Please sign in to comment.
You can’t perform that action at this time.