1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-28 23:06:37 +01:00
metamask-extension/ui/app/components/send/send-footer/send-footer.container.js

106 lines
2.5 KiB
JavaScript
Raw Normal View History

2018-04-26 18:38:38 +02:00
import { connect } from 'react-redux'
import ethUtil from 'ethereumjs-util'
2018-04-26 18:38:38 +02:00
import {
addToAddressBook,
clearSend,
signTokenTx,
signTx,
updateTransaction,
} from '../../../actions'
import SendFooter from './send-footer.component'
import {
getGasLimit,
getGasPrice,
getGasTotal,
getSelectedToken,
getSendAmount,
getSendEditingTransactionId,
getSendFromObject,
getSendTo,
getSendToAccounts,
2018-07-17 00:50:26 +02:00
getSendHexData,
2018-04-26 18:38:38 +02:00
getTokenBalance,
getUnapprovedTxs,
} from '../send.selectors'
import {
isSendFormInError,
} from './send-footer.selectors'
2018-04-26 18:38:38 +02:00
import {
addressIsNew,
constructTxParams,
constructUpdatedTx,
2018-04-26 18:38:38 +02:00
} from './send-footer.utils'
export default connect(mapStateToProps, mapDispatchToProps)(SendFooter)
function mapStateToProps (state) {
return {
amount: getSendAmount(state),
2018-07-17 00:50:26 +02:00
data: getSendHexData(state),
2018-04-26 18:38:38 +02:00
editingTransactionId: getSendEditingTransactionId(state),
from: getSendFromObject(state),
gasLimit: getGasLimit(state),
gasPrice: getGasPrice(state),
gasTotal: getGasTotal(state),
inError: isSendFormInError(state),
2018-04-26 18:38:38 +02:00
selectedToken: getSelectedToken(state),
to: getSendTo(state),
toAccounts: getSendToAccounts(state),
tokenBalance: getTokenBalance(state),
unapprovedTxs: getUnapprovedTxs(state),
2018-04-26 18:38:38 +02:00
}
}
function mapDispatchToProps (dispatch) {
return {
clearSend: () => dispatch(clearSend()),
2018-07-17 00:50:26 +02:00
sign: ({ selectedToken, to, amount, from, gas, gasPrice, data }) => {
2018-04-26 18:38:38 +02:00
const txParams = constructTxParams({
amount,
2018-07-17 00:50:26 +02:00
data,
2018-04-26 18:38:38 +02:00
from,
gas,
gasPrice,
selectedToken,
to,
})
selectedToken
? dispatch(signTokenTx(selectedToken.address, to, amount, txParams))
: dispatch(signTx(txParams))
},
update: ({
amount,
2018-07-17 00:50:26 +02:00
data,
2018-04-26 18:38:38 +02:00
editingTransactionId,
from,
gas,
gasPrice,
selectedToken,
to,
unapprovedTxs,
}) => {
const editingTx = constructUpdatedTx({
amount,
2018-07-17 00:50:26 +02:00
data,
2018-04-26 18:38:38 +02:00
editingTransactionId,
from,
gas,
gasPrice,
selectedToken,
to,
unapprovedTxs,
})
return dispatch(updateTransaction(editingTx))
2018-04-26 18:38:38 +02:00
},
addToAddressBookIfNew: (newAddress, toAccounts, nickname = '') => {
const hexPrefixedAddress = ethUtil.addHexPrefix(newAddress)
if (addressIsNew(toAccounts)) {
// TODO: nickname, i.e. addToAddressBook(recipient, nickname)
dispatch(addToAddressBook(hexPrefixedAddress, nickname))
}
},
2018-04-26 18:38:38 +02:00
}
}