mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Estimate gas limit when the token amount changes. Fix amount input
This commit is contained in:
parent
e4d3bdba12
commit
5685c4bafe
@ -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…
Reference in New Issue
Block a user