1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-12 20:57:12 +01:00
metamask-extension/ui/app/components/send/send.container.js

109 lines
2.9 KiB
JavaScript
Raw Normal View History

import { connect } from 'react-redux'
import SendEther from './send.component'
import { withRouter } from 'react-router-dom'
import { compose } from 'recompose'
import {
getAmountConversionRate,
getBlockGasLimit,
getConversionRate,
getCurrentNetwork,
getGasLimit,
getGasPrice,
getGasTotal,
getPrimaryCurrency,
getRecentBlocks,
getSelectedAddress,
getSelectedToken,
getSelectedTokenContract,
getSelectedTokenToFiatRate,
getSendAmount,
getSendEditingTransactionId,
getSendHexDataFeatureFlagState,
getSendFromObject,
getSendTo,
getTokenBalance,
2018-07-25 02:32:20 +02:00
getQrCodeData,
} from './send.selectors'
import {
updateSendTo,
updateSendTokenBalance,
2018-05-20 02:37:44 +02:00
updateGasData,
setGasTotal,
showQrScanner,
2018-08-04 02:11:46 +02:00
qrCodeDetected,
} from '../../actions'
import {
2018-06-29 19:19:40 +02:00
resetSendState,
updateSendErrors,
} from '../../ducks/send.duck'
import {
calcGasTotal,
} from './send.utils.js'
import {
SEND_ROUTE,
} from '../../routes'
module.exports = compose(
withRouter,
connect(mapStateToProps, mapDispatchToProps)
)(SendEther)
function mapStateToProps (state) {
return {
amount: getSendAmount(state),
amountConversionRate: getAmountConversionRate(state),
blockGasLimit: getBlockGasLimit(state),
conversionRate: getConversionRate(state),
editingTransactionId: getSendEditingTransactionId(state),
from: getSendFromObject(state),
gasLimit: getGasLimit(state),
gasPrice: getGasPrice(state),
gasTotal: getGasTotal(state),
network: getCurrentNetwork(state),
primaryCurrency: getPrimaryCurrency(state),
recentBlocks: getRecentBlocks(state),
selectedAddress: getSelectedAddress(state),
selectedToken: getSelectedToken(state),
showHexData: getSendHexDataFeatureFlagState(state),
to: getSendTo(state),
tokenBalance: getTokenBalance(state),
tokenContract: getSelectedTokenContract(state),
tokenToFiatRate: getSelectedTokenToFiatRate(state),
2018-07-25 02:32:20 +02:00
qrCodeData: getQrCodeData(state),
}
}
function mapDispatchToProps (dispatch) {
return {
updateAndSetGasTotal: ({
blockGasLimit,
editingTransactionId,
gasLimit,
gasPrice,
recentBlocks,
selectedAddress,
selectedToken,
to,
value,
data,
}) => {
!editingTransactionId
? dispatch(updateGasData({ recentBlocks, selectedAddress, selectedToken, blockGasLimit, to, value, data }))
: dispatch(setGasTotal(calcGasTotal(gasLimit, gasPrice)))
},
updateSendTokenBalance: ({ selectedToken, tokenContract, address }) => {
dispatch(updateSendTokenBalance({
selectedToken,
tokenContract,
address,
}))
},
updateSendErrors: newError => dispatch(updateSendErrors(newError)),
2018-06-29 19:19:40 +02:00
resetSendState: () => dispatch(resetSendState()),
scanQrCode: () => dispatch(showQrScanner(SEND_ROUTE)),
2018-08-04 02:11:46 +02:00
qrCodeDetected: (data) => dispatch(qrCodeDetected(data)),
updateSendTo: (to, nickname) => dispatch(updateSendTo(to, nickname)),
}
}