2018-05-13 04:31:01 +00:00
|
|
|
import EmbarkJS from 'Embark/EmbarkJS';
|
|
|
|
import TestToken from 'Embark/contracts/TestToken';
|
|
|
|
import React from 'react';
|
|
|
|
import { Form, FormGroup, FormControl, HelpBlock, Button } from 'react-bootstrap';
|
2018-05-31 23:38:21 +00:00
|
|
|
import ERC20TokenUI from './erc20token';
|
2018-06-05 17:19:21 +00:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { actions as accountActions } from '../reducers/accounts';
|
2018-05-31 23:38:21 +00:00
|
|
|
|
2018-05-13 04:31:01 +00:00
|
|
|
class TestTokenUI extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
amountToMint: 100,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleMintAmountChange(e){
|
|
|
|
this.setState({amountToMint: e.target.value});
|
|
|
|
}
|
|
|
|
|
2018-06-05 17:19:21 +00:00
|
|
|
mint(e){
|
|
|
|
const { addToBalance } = this.props;
|
2018-05-13 04:31:01 +00:00
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var value = parseInt(this.state.amountToMint, 10);
|
|
|
|
|
|
|
|
if (EmbarkJS.isNewWeb3()) {
|
2018-06-05 17:19:21 +00:00
|
|
|
TestToken.methods.mint(value).send({from: web3.eth.defaultAccount})
|
|
|
|
.then(r => { addToBalance(value) });
|
2018-05-13 04:31:01 +00:00
|
|
|
} else {
|
2018-06-05 17:19:21 +00:00
|
|
|
TestToken.mint(value).send({from: web3.eth.defaultAccount})
|
|
|
|
.then(r => { addToBalance(value) });
|
2018-05-13 04:31:01 +00:00
|
|
|
}
|
2018-06-05 14:45:35 +00:00
|
|
|
console.log(TestToken.options.address +".mint("+value+").send({from: " + web3.eth.defaultAccount + "})");
|
2018-05-13 04:31:01 +00:00
|
|
|
}
|
2018-05-31 23:38:21 +00:00
|
|
|
|
2018-05-13 04:31:01 +00:00
|
|
|
render(){
|
|
|
|
return (<React.Fragment>
|
2018-05-31 23:38:21 +00:00
|
|
|
<h3> Mint Test Token</h3>
|
2018-05-13 04:31:01 +00:00
|
|
|
<Form inline>
|
|
|
|
<FormGroup>
|
|
|
|
<FormControl
|
|
|
|
type="text"
|
|
|
|
defaultValue={this.state.amountToMint}
|
|
|
|
onChange={(e) => this.handleMintAmountChange(e)} />
|
|
|
|
<Button bsStyle="primary" onClick={(e) => this.mint(e)}>Mint</Button>
|
|
|
|
</FormGroup>
|
|
|
|
</Form>
|
|
|
|
|
2018-05-31 23:38:21 +00:00
|
|
|
<ERC20TokenUI address={ TestToken.options.address } />
|
|
|
|
|
2018-05-13 04:31:01 +00:00
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-05 17:19:21 +00:00
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
addToBalance(amount) {
|
|
|
|
dispatch(accountActions.addToErc20TokenBalance(amount));
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(null, mapDispatchToProps)(TestTokenUI);
|