mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-24 19:10:22 +01:00
ddaa492751
The chosen token in the `send` flow was set from one of two places: `metamask.selectedTokenAddress` or `metamask.send.token`. The former is used most of the time, but the latter is used for the 'Edit' button shown in the upper-left of the confirmation UI. The send flow will now exclusively use `metamask.send.token` for the token state during the send flow. `metamask.selectedTokenAddress` is now only used for the selected token state on the Home screen. This simplifies the Redux state, as the send token is now in one place instead of two, and `metamask.selectedTokenAddress` has only one purpose.
132 lines
3.9 KiB
JavaScript
132 lines
3.9 KiB
JavaScript
import { connect } from 'react-redux'
|
|
import {
|
|
getConversionRate,
|
|
getGasTotal,
|
|
getGasPrice,
|
|
getGasLimit,
|
|
getSendAmount,
|
|
getSendFromBalance,
|
|
getTokenBalance,
|
|
getSendMaxModeState,
|
|
getGasLoadingError,
|
|
gasFeeIsInError,
|
|
getGasButtonGroupShown,
|
|
getAdvancedInlineGasShown,
|
|
getCurrentEthBalance,
|
|
getSendToken,
|
|
getBasicGasEstimateLoadingStatus,
|
|
getRenderableEstimateDataForSmallButtonsFromGWEI,
|
|
getDefaultActiveButtonIndex,
|
|
} from '../../../../selectors'
|
|
import {
|
|
isBalanceSufficient,
|
|
calcGasTotal,
|
|
} from '../../send.utils.js'
|
|
import { calcMaxAmount } from '../send-amount-row/amount-max-button/amount-max-button.utils'
|
|
import {
|
|
showGasButtonGroup,
|
|
updateSendErrors,
|
|
} from '../../../../ducks/send/send.duck'
|
|
import {
|
|
resetCustomData,
|
|
setCustomGasPrice,
|
|
setCustomGasLimit,
|
|
} from '../../../../ducks/gas/gas.duck'
|
|
import { showModal, setGasPrice, setGasLimit, setGasTotal, updateSendAmount } from '../../../../store/actions'
|
|
import SendGasRow from './send-gas-row.component'
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(SendGasRow)
|
|
|
|
function mapStateToProps (state) {
|
|
const gasButtonInfo = getRenderableEstimateDataForSmallButtonsFromGWEI(state)
|
|
const gasPrice = getGasPrice(state)
|
|
const gasLimit = getGasLimit(state)
|
|
const activeButtonIndex = getDefaultActiveButtonIndex(gasButtonInfo, gasPrice)
|
|
|
|
const gasTotal = getGasTotal(state)
|
|
const conversionRate = getConversionRate(state)
|
|
const balance = getCurrentEthBalance(state)
|
|
|
|
const insufficientBalance = !isBalanceSufficient({
|
|
amount: getSendToken(state) ? '0x0' : getSendAmount(state),
|
|
gasTotal,
|
|
balance,
|
|
conversionRate,
|
|
})
|
|
|
|
return {
|
|
balance: getSendFromBalance(state),
|
|
gasTotal,
|
|
gasFeeError: gasFeeIsInError(state),
|
|
gasLoadingError: getGasLoadingError(state),
|
|
gasPriceButtonGroupProps: {
|
|
buttonDataLoading: getBasicGasEstimateLoadingStatus(state),
|
|
defaultActiveButtonIndex: 1,
|
|
newActiveButtonIndex: activeButtonIndex > -1 ? activeButtonIndex : null,
|
|
gasButtonInfo,
|
|
},
|
|
gasButtonGroupShown: getGasButtonGroupShown(state),
|
|
advancedInlineGasShown: getAdvancedInlineGasShown(state),
|
|
gasPrice,
|
|
gasLimit,
|
|
insufficientBalance,
|
|
maxModeOn: getSendMaxModeState(state),
|
|
sendToken: getSendToken(state),
|
|
tokenBalance: getTokenBalance(state),
|
|
}
|
|
}
|
|
|
|
function mapDispatchToProps (dispatch) {
|
|
return {
|
|
showCustomizeGasModal: () => dispatch(showModal({ name: 'CUSTOMIZE_GAS', hideBasic: true })),
|
|
setGasPrice: (newPrice, gasLimit) => {
|
|
dispatch(setGasPrice(newPrice))
|
|
dispatch(setCustomGasPrice(newPrice))
|
|
if (gasLimit) {
|
|
dispatch(setGasTotal(calcGasTotal(gasLimit, newPrice)))
|
|
}
|
|
},
|
|
setGasLimit: (newLimit, gasPrice) => {
|
|
dispatch(setGasLimit(newLimit))
|
|
dispatch(setCustomGasLimit(newLimit))
|
|
if (gasPrice) {
|
|
dispatch(setGasTotal(calcGasTotal(newLimit, gasPrice)))
|
|
}
|
|
},
|
|
setAmountToMax: (maxAmountDataObject) => {
|
|
dispatch(updateSendErrors({ amount: null }))
|
|
dispatch(updateSendAmount(calcMaxAmount(maxAmountDataObject)))
|
|
},
|
|
showGasButtonGroup: () => dispatch(showGasButtonGroup()),
|
|
resetCustomData: () => dispatch(resetCustomData()),
|
|
}
|
|
}
|
|
|
|
function mergeProps (stateProps, dispatchProps, ownProps) {
|
|
const { gasPriceButtonGroupProps } = stateProps
|
|
const { gasButtonInfo } = gasPriceButtonGroupProps
|
|
const {
|
|
setGasPrice: dispatchSetGasPrice,
|
|
showGasButtonGroup: dispatchShowGasButtonGroup,
|
|
resetCustomData: dispatchResetCustomData,
|
|
...otherDispatchProps
|
|
} = dispatchProps
|
|
|
|
return {
|
|
...stateProps,
|
|
...otherDispatchProps,
|
|
...ownProps,
|
|
gasPriceButtonGroupProps: {
|
|
...gasPriceButtonGroupProps,
|
|
handleGasPriceSelection: dispatchSetGasPrice,
|
|
},
|
|
resetGasButtons: () => {
|
|
dispatchResetCustomData()
|
|
dispatchSetGasPrice(gasButtonInfo[1].priceInHexWei)
|
|
dispatchShowGasButtonGroup()
|
|
},
|
|
setGasPrice: dispatchSetGasPrice,
|
|
}
|
|
}
|