2018-04-27 21:03:00 +02:00
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import SendEther from './send.component'
|
|
|
|
import { withRouter } from 'react-router-dom'
|
|
|
|
import { compose } from 'recompose'
|
|
|
|
import {
|
|
|
|
getAmountConversionRate,
|
2018-05-22 17:16:53 +02:00
|
|
|
getBlockGasLimit,
|
2018-04-27 21:03:00 +02:00
|
|
|
getConversionRate,
|
|
|
|
getCurrentNetwork,
|
|
|
|
getGasLimit,
|
|
|
|
getGasPrice,
|
|
|
|
getGasTotal,
|
|
|
|
getPrimaryCurrency,
|
2018-05-22 10:10:06 +02:00
|
|
|
getRecentBlocks,
|
2018-04-27 21:03:00 +02:00
|
|
|
getSelectedAddress,
|
|
|
|
getSelectedToken,
|
|
|
|
getSelectedTokenContract,
|
|
|
|
getSelectedTokenToFiatRate,
|
|
|
|
getSendAmount,
|
|
|
|
getSendEditingTransactionId,
|
|
|
|
getSendFromObject,
|
2018-06-18 18:37:01 +02:00
|
|
|
getSendTo,
|
2018-04-27 21:03:00 +02:00
|
|
|
getTokenBalance,
|
|
|
|
} from './send.selectors'
|
|
|
|
import {
|
|
|
|
updateSendTokenBalance,
|
2018-05-20 02:37:44 +02:00
|
|
|
updateGasData,
|
2018-04-27 21:03:00 +02:00
|
|
|
setGasTotal,
|
|
|
|
} from '../../actions'
|
|
|
|
import {
|
|
|
|
updateSendErrors,
|
2018-05-14 14:19:09 +02:00
|
|
|
} from '../../ducks/send.duck'
|
2018-04-27 21:03:00 +02:00
|
|
|
import {
|
|
|
|
calcGasTotal,
|
|
|
|
} from './send.utils.js'
|
|
|
|
|
|
|
|
module.exports = compose(
|
|
|
|
withRouter,
|
|
|
|
connect(mapStateToProps, mapDispatchToProps)
|
|
|
|
)(SendEther)
|
|
|
|
|
|
|
|
function mapStateToProps (state) {
|
|
|
|
return {
|
|
|
|
amount: getSendAmount(state),
|
|
|
|
amountConversionRate: getAmountConversionRate(state),
|
2018-05-22 17:16:53 +02:00
|
|
|
blockGasLimit: getBlockGasLimit(state),
|
2018-04-27 21:03:00 +02:00
|
|
|
conversionRate: getConversionRate(state),
|
|
|
|
editingTransactionId: getSendEditingTransactionId(state),
|
|
|
|
from: getSendFromObject(state),
|
|
|
|
gasLimit: getGasLimit(state),
|
|
|
|
gasPrice: getGasPrice(state),
|
|
|
|
gasTotal: getGasTotal(state),
|
|
|
|
network: getCurrentNetwork(state),
|
|
|
|
primaryCurrency: getPrimaryCurrency(state),
|
2018-05-22 10:10:06 +02:00
|
|
|
recentBlocks: getRecentBlocks(state),
|
2018-04-27 21:03:00 +02:00
|
|
|
selectedAddress: getSelectedAddress(state),
|
|
|
|
selectedToken: getSelectedToken(state),
|
2018-06-18 18:37:01 +02:00
|
|
|
to: getSendTo(state),
|
2018-04-27 21:03:00 +02:00
|
|
|
tokenBalance: getTokenBalance(state),
|
|
|
|
tokenContract: getSelectedTokenContract(state),
|
|
|
|
tokenToFiatRate: getSelectedTokenToFiatRate(state),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps (dispatch) {
|
|
|
|
return {
|
|
|
|
updateAndSetGasTotal: ({
|
2018-05-22 17:16:53 +02:00
|
|
|
blockGasLimit,
|
2018-04-27 21:03:00 +02:00
|
|
|
editingTransactionId,
|
|
|
|
gasLimit,
|
|
|
|
gasPrice,
|
2018-05-22 10:10:06 +02:00
|
|
|
recentBlocks,
|
2018-04-27 21:03:00 +02:00
|
|
|
selectedAddress,
|
|
|
|
selectedToken,
|
2018-05-23 18:43:25 +02:00
|
|
|
to,
|
|
|
|
value,
|
2018-04-27 21:03:00 +02:00
|
|
|
}) => {
|
|
|
|
!editingTransactionId
|
2018-06-02 06:23:01 +02:00
|
|
|
? dispatch(updateGasData({ recentBlocks, selectedAddress, selectedToken, blockGasLimit, to, value }))
|
2018-04-27 21:03:00 +02:00
|
|
|
: dispatch(setGasTotal(calcGasTotal(gasLimit, gasPrice)))
|
|
|
|
},
|
|
|
|
updateSendTokenBalance: ({ selectedToken, tokenContract, address }) => {
|
|
|
|
dispatch(updateSendTokenBalance({
|
|
|
|
selectedToken,
|
|
|
|
tokenContract,
|
|
|
|
address,
|
|
|
|
}))
|
|
|
|
},
|
|
|
|
updateSendErrors: newError => dispatch(updateSendErrors(newError)),
|
|
|
|
}
|
|
|
|
}
|