From c8504b0024fd2c718c505f498ff984fe3f8a562f Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 15 Aug 2018 13:00:46 -0400 Subject: [PATCH] fix indent and put submit on enter --- templates/demo/app/components/blockchain.js | 173 ++++++++++---------- 1 file changed, 91 insertions(+), 82 deletions(-) diff --git a/templates/demo/app/components/blockchain.js b/templates/demo/app/components/blockchain.js index b9e5e313..4dd177f0 100644 --- a/templates/demo/app/components/blockchain.js +++ b/templates/demo/app/components/blockchain.js @@ -2,90 +2,99 @@ import EmbarkJS from 'Embark/EmbarkJS'; import SimpleStorage from 'Embark/contracts/SimpleStorage'; import React from 'react'; import { Form, FormGroup, FormControl, HelpBlock, Button } from 'react-bootstrap'; - + class Blockchain extends React.Component { - constructor(props) { - super(props); - - this.state = { - valueSet: 10, - valueGet: "", - logs: [] - } - } - - handleChange(e){ - this.setState({valueSet: e.target.value}); - } - - setValue(e){ - e.preventDefault(); - - var value = parseInt(this.state.valueSet, 10); - - // If web3.js 1.0 is being used - if (EmbarkJS.isNewWeb3()) { - SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount}); - this._addToLog("SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount})"); - } else { - SimpleStorage.set(value); - this._addToLog("#blockchain", "SimpleStorage.set(" + value + ")"); - } - } - - getValue(e){ - e.preventDefault(); - - if (EmbarkJS.isNewWeb3()) { - SimpleStorage.methods.get().call() - .then(_value => this.setState({valueGet: _value})) - this._addToLog("SimpleStorage.methods.get(console.log)"); - } else { - SimpleStorage.get() - .then(_value => this.setState({valueGet: _value})); - this._addToLog("SimpleStorage.get()"); - } - } - - _addToLog(txt){ - this.state.logs.push(txt); - this.setState({logs: this.state.logs}); - } - - render(){ - return ( -

1. Set the value in the blockchain

-
- - this.handleChange(e)} /> - - Once you set the value, the transaction will need to be mined and then the value will be updated on the blockchain. - -
- -

2. Get the current value

-
- - current value is {this.state.valueGet} - - Click the button to get the current value. The initial value is 100. - -
- -

3. Contract Calls

-

Javascript calls being made:

-
- { - this.state.logs.map((item, i) =>

{item}

) - } -
-
- ); + constructor(props) { + super(props); + + this.state = { + valueSet: 10, + valueGet: "", + logs: [] } } - export default Blockchain; \ No newline at end of file + handleChange(e) { + this.setState({ valueSet: e.target.value }); + } + + checkEnter(e, func) { + if (e.key !== 'Enter') { + return; + } + e.preventDefault(); + func.apply(this, [e]); + } + + setValue(e) { + e.preventDefault(); + + var value = parseInt(this.state.valueSet, 10); + + // If web3.js 1.0 is being used + if (EmbarkJS.isNewWeb3()) { + SimpleStorage.methods.set(value).send({ from: web3.eth.defaultAccount }); + this._addToLog("SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount})"); + } else { + SimpleStorage.set(value); + this._addToLog("#blockchain", "SimpleStorage.set(" + value + ")"); + } + } + + getValue(e) { + e.preventDefault(); + + if (EmbarkJS.isNewWeb3()) { + SimpleStorage.methods.get().call() + .then(_value => this.setState({ valueGet: _value })) + this._addToLog("SimpleStorage.methods.get(console.log)"); + } else { + SimpleStorage.get() + .then(_value => this.setState({ valueGet: _value })); + this._addToLog("SimpleStorage.get()"); + } + } + + _addToLog(txt) { + this.state.logs.push(txt); + this.setState({ logs: this.state.logs }); + } + + render() { + return ( +

1. Set the value in the blockchain

+
this.checkEnter(e, this.setValue)}> + + this.handleChange(e)}/> + + Once you set the value, the transaction will need to be mined and then the value will be updated + on the blockchain. + +
+ +

2. Get the current value

+
+ + current value is {this.state.valueGet} + + Click the button to get the current value. The initial value is 100. + +
+ +

3. Contract Calls

+

Javascript calls being made:

+
+ { + this.state.logs.map((item, i) =>

{item}

) + } +
+
+ ); + } +} + +export default Blockchain;