1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-24 19:10:22 +01:00
metamask-extension/ui/app/pages/send/send.container.js
Mark Stacey f20e028cde
Remove unused props, prevent redundant gas update (#7769)
These unused props weren't being caught by ESLint because this
component extended another, which I guess made it difficult for the
React plugin to determine what was unused.

The `componentWillUpdate` logic was moved into `componentDidUpdate` so
that it would be picked up by ESLint. Also it seemed like a sensible
place for it to go. Having three redundant gas updates as part of
the same lifecycle function seemed too far, so I ensured it's
only called once.
2020-01-10 10:39:44 -04:00

135 lines
3.9 KiB
JavaScript

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,
getSelectedToken,
getSelectedTokenContract,
getSendAmount,
getSendEditingTransactionId,
getSendHexDataFeatureFlagState,
getSendFromObject,
getSendTo,
getSendToNickname,
getTokenBalance,
getQrCodeData,
} from './send.selectors'
import {
getSelectedAddress,
getAddressBook,
} from '../../selectors/selectors'
import { getTokens } from './send-content/add-recipient/add-recipient.selectors'
import {
updateSendTo,
updateSendTokenBalance,
updateGasData,
setGasTotal,
showQrScanner,
qrCodeDetected,
updateSendEnsResolution,
updateSendEnsResolutionError,
} from '../../store/actions'
import {
resetSendState,
updateSendErrors,
} from '../../ducks/send/send.duck'
import {
fetchBasicGasEstimates,
} from '../../ducks/gas/gas.duck'
import {
calcGasTotal,
} from './send.utils.js'
import {
isValidENSAddress,
} from '../../helpers/utils/util'
import {
SEND_ROUTE,
} from '../../helpers/constants/routes'
function mapStateToProps (state) {
return {
addressBook: getAddressBook(state),
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),
qrCodeData: getQrCodeData(state),
recentBlocks: getRecentBlocks(state),
selectedAddress: getSelectedAddress(state),
selectedToken: getSelectedToken(state),
showHexData: getSendHexDataFeatureFlagState(state),
to: getSendTo(state),
toNickname: getSendToNickname(state),
tokens: getTokens(state),
tokenBalance: getTokenBalance(state),
tokenContract: getSelectedTokenContract(state),
}
}
function mapDispatchToProps (dispatch) {
return {
updateAndSetGasLimit: ({
blockGasLimit,
editingTransactionId,
gasLimit,
gasPrice,
recentBlocks,
selectedAddress,
selectedToken,
to,
value,
data,
}) => {
!editingTransactionId
? dispatch(updateGasData({ gasPrice, 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)),
resetSendState: () => dispatch(resetSendState()),
scanQrCode: () => dispatch(showQrScanner(SEND_ROUTE)),
qrCodeDetected: (data) => dispatch(qrCodeDetected(data)),
updateSendTo: (to, nickname) => dispatch(updateSendTo(to, nickname)),
fetchBasicGasEstimates: () => dispatch(fetchBasicGasEstimates()),
updateSendEnsResolution: (ensResolution) => dispatch(updateSendEnsResolution(ensResolution)),
updateSendEnsResolutionError: (message) => dispatch(updateSendEnsResolutionError(message)),
updateToNicknameIfNecessary: (to, toNickname, addressBook) => {
if (isValidENSAddress(toNickname)) {
const addressBookEntry = addressBook.find(({ address }) => to === address) || {}
if (!addressBookEntry.name !== toNickname) {
dispatch(updateSendTo(to, addressBookEntry.name || ''))
}
}
},
}
}
export default compose(
withRouter,
connect(mapStateToProps, mapDispatchToProps)
)(SendEther)