mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Handle and set gas estimation when max mode is clicked (#8176)
* Handle and set gas estimation when max mode is clicked Add componentDidMount to SendAmountRow to check for maxMode boolean to update amount and gas.
This commit is contained in:
parent
f0f5554846
commit
e791882959
@ -107,9 +107,11 @@ const mapStateToProps = (state, ownProps) => {
|
||||
const isMainnet = getIsMainnet(state)
|
||||
const showFiat = Boolean(isMainnet || showFiatInTestnets)
|
||||
|
||||
const newTotalEth = maxModeOn ? addHexWEIsToRenderableEth(balance, '0x0') : addHexWEIsToRenderableEth(value, customGasTotal)
|
||||
const isTokenSelected = Boolean(getSelectedToken(state))
|
||||
|
||||
const sendAmount = maxModeOn ? subtractHexWEIsFromRenderableEth(balance, customGasTotal) : addHexWEIsToRenderableEth(value, '0x0')
|
||||
const newTotalEth = maxModeOn && !isTokenSelected ? addHexWEIsToRenderableEth(balance, '0x0') : addHexWEIsToRenderableEth(value, customGasTotal)
|
||||
|
||||
const sendAmount = maxModeOn && !isTokenSelected ? subtractHexWEIsFromRenderableEth(balance, customGasTotal) : addHexWEIsToRenderableEth(value, '0x0')
|
||||
|
||||
const insufficientBalance = maxModeOn ? false : !isBalanceSufficient({
|
||||
amount: value,
|
||||
|
@ -26,12 +26,26 @@ export default class SendAmountRow extends Component {
|
||||
updateSendAmount: PropTypes.func,
|
||||
updateSendAmountError: PropTypes.func,
|
||||
updateGas: PropTypes.func,
|
||||
maxModeOn: PropTypes.bool,
|
||||
}
|
||||
|
||||
static contextTypes = {
|
||||
t: PropTypes.func,
|
||||
}
|
||||
|
||||
componentDidUpdate (prevProps) {
|
||||
const { maxModeOn: prevMaxModeOn, gasTotal: prevGasTotal } = prevProps
|
||||
const { maxModeOn, amount, gasTotal, selectedToken } = this.props
|
||||
|
||||
if (maxModeOn && selectedToken && !prevMaxModeOn) {
|
||||
this.updateGas(amount)
|
||||
}
|
||||
|
||||
if (prevGasTotal !== gasTotal) {
|
||||
this.validateAmount(amount)
|
||||
}
|
||||
}
|
||||
|
||||
updateGas = debounce(this.updateGas.bind(this), 500)
|
||||
|
||||
validateAmount (amount) {
|
||||
@ -86,17 +100,19 @@ export default class SendAmountRow extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
handleChange = (newAmount) => {
|
||||
this.validateAmount(newAmount)
|
||||
this.updateGas(newAmount)
|
||||
this.updateAmount(newAmount)
|
||||
}
|
||||
|
||||
renderInput () {
|
||||
const { amount, inError, selectedToken } = this.props
|
||||
const Component = selectedToken ? UserPreferencedTokenInput : UserPreferencedCurrencyInput
|
||||
|
||||
return (
|
||||
<Component
|
||||
onChange={(newAmount) => {
|
||||
this.validateAmount(newAmount)
|
||||
this.updateGas(newAmount)
|
||||
this.updateAmount(newAmount)
|
||||
}}
|
||||
onChange={this.handleChange}
|
||||
error={inError}
|
||||
value={amount}
|
||||
/>
|
||||
|
@ -8,6 +8,7 @@ import {
|
||||
getSendAmount,
|
||||
getSendFromBalance,
|
||||
getTokenBalance,
|
||||
getSendMaxModeState,
|
||||
} from '../../send.selectors'
|
||||
import {
|
||||
sendAmountIsInError,
|
||||
@ -35,6 +36,7 @@ function mapStateToProps (state) {
|
||||
primaryCurrency: getPrimaryCurrency(state),
|
||||
selectedToken: getSelectedToken(state),
|
||||
tokenBalance: getTokenBalance(state),
|
||||
maxModeOn: getSendMaxModeState(state),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user