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; border-radius: 0.5em;
background: #f80; background: #f80;
color: white; color: white;
font-size: 0.75em;
padding: 0.75em; padding: 0.75em;
text-align: center; text-align: center;
} }

View File

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

View File

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

View File

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

View File

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

View File

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