diff --git a/js/src/modals/ExecuteContract/executeContract.css b/js/src/modals/ExecuteContract/executeContract.css index 55135a92e..a83b373ee 100644 --- a/js/src/modals/ExecuteContract/executeContract.css +++ b/js/src/modals/ExecuteContract/executeContract.css @@ -38,6 +38,7 @@ border-radius: 0.5em; background: #f80; color: white; + font-size: 0.75em; padding: 0.75em; text-align: center; } diff --git a/js/src/modals/ExecuteContract/executeContract.js b/js/src/modals/ExecuteContract/executeContract.js index 8022690f5..1354e8543 100644 --- a/js/src/modals/ExecuteContract/executeContract.js +++ b/js/src/modals/ExecuteContract/executeContract.js @@ -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 }; } diff --git a/js/src/modals/Transfer/errors.js b/js/src/modals/Transfer/errors.js index c35d82636..3a6bd63ae 100644 --- a/js/src/modals/Transfer/errors.js +++ b/js/src/modals/Transfer/errors.js @@ -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; diff --git a/js/src/modals/Transfer/transfer.css b/js/src/modals/Transfer/transfer.css index 76f83c62b..b7f478b4f 100644 --- a/js/src/modals/Transfer/transfer.css +++ b/js/src/modals/Transfer/transfer.css @@ -157,6 +157,7 @@ border-radius: 0.5em; background: #f80; color: white; + font-size: 0.75em; padding: 0.75em; text-align: center; } diff --git a/js/src/modals/Transfer/transfer.js b/js/src/modals/Transfer/transfer.js index 196307923..e906e45d7 100644 --- a/js/src/modals/Transfer/transfer.js +++ b/js/src/modals/Transfer/transfer.js @@ -681,7 +681,7 @@ class Transfer extends Component { } function mapStateToProps (state) { - const { gasLimit } = state.status; + const { gasLimit } = state.nodeStatus; return { gasLimit }; } diff --git a/js/src/util/constants.js b/js/src/util/constants.js index 87ca59668..d0664d25e 100644 --- a/js/src/util/constants.js +++ b/js/src/util/constants.js @@ -19,7 +19,7 @@ const DEFAULT_GASPRICE = '20000000000'; const MAX_GAS_ESTIMATION = '50000000'; -export default { +export { DEFAULT_GAS, DEFAULT_GASPRICE, MAX_GAS_ESTIMATION