You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
3.7 KiB
119 lines
3.7 KiB
7 years ago
|
import { connect } from 'react-redux'
|
||
7 years ago
|
import {
|
||
6 years ago
|
getConversionRate,
|
||
|
getCurrentCurrency,
|
||
|
getGasTotal,
|
||
6 years ago
|
getGasPrice,
|
||
6 years ago
|
getGasLimit,
|
||
|
getSendAmount,
|
||
7 years ago
|
} from '../../send.selectors.js'
|
||
6 years ago
|
import {
|
||
|
isBalanceSufficient,
|
||
|
calcGasTotal,
|
||
|
} from '../../send.utils.js'
|
||
6 years ago
|
import {
|
||
6 years ago
|
getBasicGasEstimateLoadingStatus,
|
||
6 years ago
|
getRenderableEstimateDataForSmallButtonsFromGWEI,
|
||
6 years ago
|
getDefaultActiveButtonIndex,
|
||
6 years ago
|
} from '../../../../selectors/custom-gas'
|
||
6 years ago
|
import {
|
||
|
showGasButtonGroup,
|
||
6 years ago
|
} from '../../../../ducks/send/send.duck'
|
||
6 years ago
|
import {
|
||
|
resetCustomData,
|
||
6 years ago
|
setCustomGasPrice,
|
||
|
setCustomGasLimit,
|
||
6 years ago
|
} from '../../../../ducks/gas/gas.duck'
|
||
6 years ago
|
import { getGasLoadingError, gasFeeIsInError, getGasButtonGroupShown } from './send-gas-row.selectors.js'
|
||
6 years ago
|
import { showModal, setGasPrice, setGasLimit, setGasTotal } from '../../../../store/actions'
|
||
|
import { getAdvancedInlineGasShown, getCurrentEthBalance, getSelectedToken } from '../../../../selectors/selectors'
|
||
7 years ago
|
import SendGasRow from './send-gas-row.component'
|
||
7 years ago
|
|
||
6 years ago
|
export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(SendGasRow)
|
||
7 years ago
|
|
||
|
function mapStateToProps (state) {
|
||
6 years ago
|
const gasButtonInfo = getRenderableEstimateDataForSmallButtonsFromGWEI(state)
|
||
6 years ago
|
const gasPrice = getGasPrice(state)
|
||
6 years ago
|
const gasLimit = getGasLimit(state)
|
||
6 years ago
|
const activeButtonIndex = getDefaultActiveButtonIndex(gasButtonInfo, gasPrice)
|
||
|
|
||
|
const gasTotal = getGasTotal(state)
|
||
|
const conversionRate = getConversionRate(state)
|
||
|
const balance = getCurrentEthBalance(state)
|
||
|
|
||
|
const insufficientBalance = !isBalanceSufficient({
|
||
6 years ago
|
amount: getSelectedToken(state) ? '0x0' : getSendAmount(state),
|
||
6 years ago
|
gasTotal,
|
||
|
balance,
|
||
|
conversionRate,
|
||
|
})
|
||
6 years ago
|
|
||
7 years ago
|
return {
|
||
6 years ago
|
conversionRate,
|
||
7 years ago
|
convertedCurrency: getCurrentCurrency(state),
|
||
6 years ago
|
gasTotal,
|
||
7 years ago
|
gasFeeError: gasFeeIsInError(state),
|
||
|
gasLoadingError: getGasLoadingError(state),
|
||
6 years ago
|
gasPriceButtonGroupProps: {
|
||
|
buttonDataLoading: getBasicGasEstimateLoadingStatus(state),
|
||
|
defaultActiveButtonIndex: 1,
|
||
|
newActiveButtonIndex: activeButtonIndex > -1 ? activeButtonIndex : null,
|
||
|
gasButtonInfo,
|
||
|
},
|
||
|
gasButtonGroupShown: getGasButtonGroupShown(state),
|
||
6 years ago
|
advancedInlineGasShown: getAdvancedInlineGasShown(state),
|
||
6 years ago
|
gasPrice,
|
||
|
gasLimit,
|
||
6 years ago
|
insufficientBalance,
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
|
function mapDispatchToProps (dispatch) {
|
||
|
return {
|
||
6 years ago
|
showCustomizeGasModal: () => dispatch(showModal({ name: 'CUSTOMIZE_GAS', hideBasic: true })),
|
||
6 years ago
|
setGasPrice: (newPrice, gasLimit) => {
|
||
|
dispatch(setGasPrice(newPrice))
|
||
6 years ago
|
dispatch(setCustomGasPrice(newPrice))
|
||
6 years ago
|
if (gasLimit) {
|
||
|
dispatch(setGasTotal(calcGasTotal(gasLimit, newPrice)))
|
||
|
}
|
||
6 years ago
|
},
|
||
|
setGasLimit: (newLimit, gasPrice) => {
|
||
|
dispatch(setGasLimit(newLimit))
|
||
6 years ago
|
dispatch(setCustomGasLimit(newLimit))
|
||
6 years ago
|
if (gasPrice) {
|
||
|
dispatch(setGasTotal(calcGasTotal(newLimit, gasPrice)))
|
||
|
}
|
||
6 years ago
|
},
|
||
6 years ago
|
showGasButtonGroup: () => dispatch(showGasButtonGroup()),
|
||
6 years ago
|
resetCustomData: () => dispatch(resetCustomData()),
|
||
7 years ago
|
}
|
||
|
}
|
||
6 years ago
|
|
||
|
function mergeProps (stateProps, dispatchProps, ownProps) {
|
||
|
const { gasPriceButtonGroupProps } = stateProps
|
||
6 years ago
|
const { gasButtonInfo } = gasPriceButtonGroupProps
|
||
6 years ago
|
const {
|
||
|
setGasPrice: dispatchSetGasPrice,
|
||
6 years ago
|
showGasButtonGroup: dispatchShowGasButtonGroup,
|
||
|
resetCustomData: dispatchResetCustomData,
|
||
6 years ago
|
...otherDispatchProps
|
||
|
} = dispatchProps
|
||
|
|
||
|
return {
|
||
|
...stateProps,
|
||
|
...otherDispatchProps,
|
||
|
...ownProps,
|
||
|
gasPriceButtonGroupProps: {
|
||
|
...gasPriceButtonGroupProps,
|
||
|
handleGasPriceSelection: dispatchSetGasPrice,
|
||
|
},
|
||
6 years ago
|
resetGasButtons: () => {
|
||
|
dispatchResetCustomData()
|
||
|
dispatchSetGasPrice(gasButtonInfo[1].priceInHexWei)
|
||
|
dispatchShowGasButtonGroup()
|
||
|
},
|
||
6 years ago
|
setGasPrice: dispatchSetGasPrice,
|
||
6 years ago
|
}
|
||
6 years ago
|
}
|