From 5685c4bafed0458e350b401791e108b8162a88e0 Mon Sep 17 00:00:00 2001 From: Alexander Tseung Date: Fri, 15 Jun 2018 14:36:52 -0700 Subject: [PATCH] Estimate gas limit when the token amount changes. Fix amount input --- .../send-amount-row/send-amount-row.component.js | 16 +++++++++++++--- .../send_/send-content/send-content.component.js | 2 +- ui/app/components/send_/send.component.js | 4 ++-- ui/app/components/send_/send.utils.js | 12 ++---------- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/ui/app/components/send_/send-content/send-amount-row/send-amount-row.component.js b/ui/app/components/send_/send-content/send-amount-row/send-amount-row.component.js index 8aefeed4a..e6cb405e9 100644 --- a/ui/app/components/send_/send-content/send-amount-row/send-amount-row.component.js +++ b/ui/app/components/send_/send-content/send-amount-row/send-amount-row.component.js @@ -23,6 +23,7 @@ export default class SendAmountRow extends Component { tokenBalance: PropTypes.string, updateSendAmount: PropTypes.func, updateSendAmountError: PropTypes.func, + updateGas: PropTypes.func, } validateAmount (amount) { @@ -54,6 +55,15 @@ export default class SendAmountRow extends Component { setMaxModeTo(false) updateSendAmount(amount) + this.validateAmount(amount) + } + + updateGas (amount) { + const { selectedToken, updateGas } = this.props + + if (selectedToken) { + updateGas({ amount }) + } } render () { @@ -77,12 +87,12 @@ export default class SendAmountRow extends Component { this.updateAmount(newAmount)} - onChange={newAmount => this.validateAmount(newAmount)} + onBlur={newAmount => this.updateGas(newAmount)} + onChange={newAmount => this.updateAmount(newAmount)} inError={inError} primaryCurrency={primaryCurrency || 'ETH'} selectedToken={selectedToken} - value={amount || '0x0'} + value={amount} /> ) diff --git a/ui/app/components/send_/send-content/send-content.component.js b/ui/app/components/send_/send-content/send-content.component.js index 3a14054eb..adc114c0e 100644 --- a/ui/app/components/send_/send-content/send-content.component.js +++ b/ui/app/components/send_/send-content/send-content.component.js @@ -18,7 +18,7 @@ export default class SendContent extends Component {
this.props.updateGas(updateData)} /> - + this.props.updateGas(updateData)} />
diff --git a/ui/app/components/send_/send.component.js b/ui/app/components/send_/send.component.js index 516251e22..38da4910b 100644 --- a/ui/app/components/send_/send.component.js +++ b/ui/app/components/send_/send.component.js @@ -38,7 +38,7 @@ export default class SendTransactionScreen extends PersistentForm { updateSendTokenBalance: PropTypes.func, }; - updateGas ({ to } = {}) { + updateGas ({ to, amount: value } = {}) { const { amount, blockGasLimit, @@ -60,7 +60,7 @@ export default class SendTransactionScreen extends PersistentForm { selectedAddress, selectedToken, to: to && to.toLowerCase(), - value: amount, + value: value || amount, }) } diff --git a/ui/app/components/send_/send.utils.js b/ui/app/components/send_/send.utils.js index 8772d464b..3d8e1a882 100644 --- a/ui/app/components/send_/send.utils.js +++ b/ui/app/components/send_/send.utils.js @@ -203,21 +203,13 @@ async function estimateGas ({ selectedAddress, selectedToken, blockGasLimit, to, err.message.includes('gas required exceeds allowance or always failing transaction') ) if (simulationFailed) { - const estimateWithBuffer = addGasBuffer( - paramsForGasEstimate.gas, - blockGasLimit, - selectedToken ? 2 : 1.5 - ) + const estimateWithBuffer = addGasBuffer(paramsForGasEstimate.gas, blockGasLimit, 1.5) return resolve(ethUtil.addHexPrefix(estimateWithBuffer)) } else { return reject(err) } } - const estimateWithBuffer = addGasBuffer( - estimatedGas.toString(16), - blockGasLimit, - selectedToken ? 2 : 1.5 - ) + const estimateWithBuffer = addGasBuffer(estimatedGas.toString(16), blockGasLimit, 1.5) return resolve(ethUtil.addHexPrefix(estimateWithBuffer)) }) })