Updated, contract execution in-place

This commit is contained in:
Jaco Greeff 2016-11-18 15:05:02 +01:00
parent bf58aab6a3
commit b433e7e9a0
6 changed files with 26 additions and 15 deletions

View File

@ -38,6 +38,7 @@
border-radius: 0.5em;
background: #f80;
color: white;
font-size: 0.75em;
padding: 0.75em;
text-align: center;
}

View File

@ -71,6 +71,12 @@ class ExecuteContract extends Component {
this.onFuncChange(null, functions[0]);
}
componentWillReceiveProps (newProps) {
if (newProps.fromAddress !== this.props.fromAddress) {
this.estimateGas(newProps.fromAddress);
}
}
render () {
const { sending } = this.state;
@ -164,8 +170,7 @@ class ExecuteContract extends Component {
}
onAmountChange = (amount) => {
this.estimateGas();
this.setState({ amount });
this.setState({ amount }, this.estimateGas);
}
onFuncChange = (event, func) => {
@ -188,11 +193,10 @@ class ExecuteContract extends Component {
}
});
this.estimateGas();
this.setState({
func,
values
});
}, this.estimateGas);
}
onValueChange = (event, index, _value) => {
@ -218,29 +222,34 @@ class ExecuteContract extends Component {
values[index] = value;
valuesError[index] = valueError;
if (!valueError) {
this.estimateGas();
}
this.setState({
values: [].concat(values),
valuesError: [].concat(valuesError)
}, () => {
if (!valueError) {
this.estimateGas();
}
});
}
estimateGas = () => {
estimateGas = (_fromAddress) => {
const { api } = this.context;
const { fromAddress, gasLimit } = this.props;
const { amount, func, values } = this.state;
const options = {
gas: MAX_GAS_ESTIMATION,
from: fromAddress,
from: _fromAddress || fromAddress,
value: api.util.toWei(amount || 0)
};
if (!func) {
return;
}
func
.estimateGas(options, values)
.then((gasEst) => {
console.log(gasEst.toFormat(0));
const gas = gasEst.mul(1.2);
let gasLimitError = null;
@ -304,7 +313,7 @@ class ExecuteContract extends Component {
}
function mapStateToProps (state) {
const { gasLimit } = state.status;
const { gasLimit } = state.nodeStatus;
return { gasLimit };
}

View File

@ -20,8 +20,8 @@ const ERRORS = {
invalidAmount: 'the supplied amount should be a valid positive number',
invalidDecimals: 'the supplied amount exceeds the allowed decimals',
largeAmount: 'the transaction total is higher than the available balance',
gasException: 'the transaction indicates a thrown exception',
gasBlockLimit: 'the transaction will exceed the block gas limit'
gasException: 'the transaction will throw an exception with the current values',
gasBlockLimit: 'the transaction execution will exceed the block gas limit'
};
export default ERRORS;

View File

@ -157,6 +157,7 @@
border-radius: 0.5em;
background: #f80;
color: white;
font-size: 0.75em;
padding: 0.75em;
text-align: center;
}

View File

@ -681,7 +681,7 @@ class Transfer extends Component {
}
function mapStateToProps (state) {
const { gasLimit } = state.status;
const { gasLimit } = state.nodeStatus;
return { gasLimit };
}

View File

@ -19,7 +19,7 @@ const DEFAULT_GASPRICE = '20000000000';
const MAX_GAS_ESTIMATION = '50000000';
export default {
export {
DEFAULT_GAS,
DEFAULT_GASPRICE,
MAX_GAS_ESTIMATION