fix indent and put submit on enter

This commit is contained in:
Jonathan Rainville 2018-08-15 13:00:46 -04:00 committed by Iuri Matias
parent 29a0d5c658
commit c8504b0024
1 changed files with 91 additions and 82 deletions

View File

@ -15,18 +15,26 @@ class Blockchain extends React.Component {
}
}
handleChange(e){
this.setState({valueSet: e.target.value});
handleChange(e) {
this.setState({ valueSet: e.target.value });
}
setValue(e){
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});
SimpleStorage.methods.set(value).send({ from: web3.eth.defaultAccount });
this._addToLog("SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount})");
} else {
SimpleStorage.set(value);
@ -34,36 +42,37 @@ class Blockchain extends React.Component {
}
}
getValue(e){
getValue(e) {
e.preventDefault();
if (EmbarkJS.isNewWeb3()) {
SimpleStorage.methods.get().call()
.then(_value => this.setState({valueGet: _value}))
.then(_value => this.setState({ valueGet: _value }))
this._addToLog("SimpleStorage.methods.get(console.log)");
} else {
SimpleStorage.get()
.then(_value => this.setState({valueGet: _value}));
.then(_value => this.setState({ valueGet: _value }));
this._addToLog("SimpleStorage.get()");
}
}
_addToLog(txt){
_addToLog(txt) {
this.state.logs.push(txt);
this.setState({logs: this.state.logs});
this.setState({ logs: this.state.logs });
}
render(){
render() {
return (<React.Fragment>
<h3> 1. Set the value in the blockchain</h3>
<Form inline>
<Form inline onKeyDown={(e) => this.checkEnter(e, this.setValue)}>
<FormGroup>
<FormControl
type="text"
defaultValue={this.state.valueSet}
onChange={(e) => this.handleChange(e)} />
onChange={(e) => this.handleChange(e)}/>
<Button bsStyle="primary" onClick={(e) => this.setValue(e)}>Set Value</Button>
<HelpBlock>Once you set the value, the transaction will need to be mined and then the value will be updated on the blockchain.</HelpBlock>
<HelpBlock>Once you set the value, the transaction will need to be mined and then the value will be updated
on the blockchain.</HelpBlock>
</FormGroup>
</Form>
@ -86,6 +95,6 @@ class Blockchain extends React.Component {
</React.Fragment>
);
}
}
}
export default Blockchain;
export default Blockchain;