Estimate gas limit when the token amount changes. Fix amount input

feature/default_network_editable
Alexander Tseung 7 years ago
parent e4d3bdba12
commit 5685c4bafe
  1. 16
      ui/app/components/send_/send-content/send-amount-row/send-amount-row.component.js
  2. 2
      ui/app/components/send_/send-content/send-content.component.js
  3. 4
      ui/app/components/send_/send.component.js
  4. 12
      ui/app/components/send_/send.utils.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 {
<CurrencyDisplay
conversionRate={amountConversionRate}
convertedCurrency={convertedCurrency}
onBlur={newAmount => 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}
/>
</SendRowWrapper>
)

@ -18,7 +18,7 @@ export default class SendContent extends Component {
<div className="send-v2__form">
<SendFromRow />
<SendToRow updateGas={(updateData) => this.props.updateGas(updateData)} />
<SendAmountRow />
<SendAmountRow updateGas={(updateData) => this.props.updateGas(updateData)} />
<SendGasRow />
</div>
</PageContainerContent>

@ -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,
})
}

@ -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))
})
})

Loading…
Cancel
Save