mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-24 19:10:22 +01:00
f0f5554846
The `metamask.send.from` field was assumed by various selectors to be an object, but instead it was recently set to a string. The selectors have been updated to assume it's a string, and to fetch the full account object explicitly. The selector `getSendFromObject` was repurposed for this, as that's basically what it already did. The optional address parameter was removed though, as that was only used to fetch the `from` address in cases where the `send` state was set without there being a `from` address set. That case is no longer possible, as the `from` address is always set upon the initialization of the `send` state. The `getSendFromObject` selector no longer fetches the 'name' of that address from the address book state either. This property was not used in either of the cases this selector was used.
125 lines
3.2 KiB
JavaScript
125 lines
3.2 KiB
JavaScript
import { connect } from 'react-redux'
|
|
import ethUtil from 'ethereumjs-util'
|
|
import {
|
|
addToAddressBook,
|
|
clearSend,
|
|
signTokenTx,
|
|
signTx,
|
|
updateTransaction,
|
|
} from '../../../store/actions'
|
|
import SendFooter from './send-footer.component'
|
|
import {
|
|
getGasLimit,
|
|
getGasPrice,
|
|
getGasTotal,
|
|
getSelectedToken,
|
|
getSendAmount,
|
|
getSendEditingTransactionId,
|
|
getSendFromObject,
|
|
getSendTo,
|
|
getSendToAccounts,
|
|
getSendHexData,
|
|
getTokenBalance,
|
|
getUnapprovedTxs,
|
|
getSendErrors,
|
|
} from '../send.selectors'
|
|
import { getGasIsLoading } from '../../../selectors/selectors'
|
|
import {
|
|
isSendFormInError,
|
|
} from './send-footer.selectors'
|
|
import {
|
|
addressIsNew,
|
|
constructTxParams,
|
|
constructUpdatedTx,
|
|
} from './send-footer.utils'
|
|
import {
|
|
getRenderableEstimateDataForSmallButtonsFromGWEI,
|
|
getDefaultActiveButtonIndex,
|
|
} from '../../../selectors/custom-gas'
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(SendFooter)
|
|
|
|
function mapStateToProps (state) {
|
|
|
|
const gasButtonInfo = getRenderableEstimateDataForSmallButtonsFromGWEI(state)
|
|
const gasPrice = getGasPrice(state)
|
|
const activeButtonIndex = getDefaultActiveButtonIndex(gasButtonInfo, gasPrice)
|
|
const gasEstimateType = activeButtonIndex >= 0
|
|
? gasButtonInfo[activeButtonIndex].gasEstimateType
|
|
: 'custom'
|
|
const editingTransactionId = getSendEditingTransactionId(state)
|
|
|
|
return {
|
|
amount: getSendAmount(state),
|
|
data: getSendHexData(state),
|
|
editingTransactionId,
|
|
from: getSendFromObject(state),
|
|
gasLimit: getGasLimit(state),
|
|
gasPrice: getGasPrice(state),
|
|
gasTotal: getGasTotal(state),
|
|
inError: isSendFormInError(state),
|
|
selectedToken: getSelectedToken(state),
|
|
to: getSendTo(state),
|
|
toAccounts: getSendToAccounts(state),
|
|
tokenBalance: getTokenBalance(state),
|
|
unapprovedTxs: getUnapprovedTxs(state),
|
|
sendErrors: getSendErrors(state),
|
|
gasEstimateType,
|
|
gasIsLoading: getGasIsLoading(state),
|
|
}
|
|
}
|
|
|
|
function mapDispatchToProps (dispatch) {
|
|
return {
|
|
clearSend: () => dispatch(clearSend()),
|
|
sign: ({ selectedToken, to, amount, from, gas, gasPrice, data }) => {
|
|
const txParams = constructTxParams({
|
|
amount,
|
|
data,
|
|
from,
|
|
gas,
|
|
gasPrice,
|
|
selectedToken,
|
|
to,
|
|
})
|
|
|
|
selectedToken
|
|
? dispatch(signTokenTx(selectedToken.address, to, amount, txParams))
|
|
: dispatch(signTx(txParams))
|
|
},
|
|
update: ({
|
|
amount,
|
|
data,
|
|
editingTransactionId,
|
|
from,
|
|
gas,
|
|
gasPrice,
|
|
selectedToken,
|
|
to,
|
|
unapprovedTxs,
|
|
}) => {
|
|
const editingTx = constructUpdatedTx({
|
|
amount,
|
|
data,
|
|
editingTransactionId,
|
|
from,
|
|
gas,
|
|
gasPrice,
|
|
selectedToken,
|
|
to,
|
|
unapprovedTxs,
|
|
})
|
|
|
|
return dispatch(updateTransaction(editingTx))
|
|
},
|
|
|
|
addToAddressBookIfNew: (newAddress, toAccounts, nickname = '') => {
|
|
const hexPrefixedAddress = ethUtil.addHexPrefix(newAddress)
|
|
if (addressIsNew(toAccounts, hexPrefixedAddress)) {
|
|
// TODO: nickname, i.e. addToAddressBook(recipient, nickname)
|
|
dispatch(addToAddressBook(hexPrefixedAddress, nickname))
|
|
}
|
|
},
|
|
}
|
|
}
|