2018-06-23 08:52:45 +02:00
|
|
|
import { connect } from 'react-redux'
|
2020-02-24 23:58:26 +01:00
|
|
|
import { compose } from 'redux'
|
2018-06-23 08:52:45 +02:00
|
|
|
import { withRouter } from 'react-router-dom'
|
|
|
|
import ConfirmSendToken from './confirm-send-token.component'
|
2019-03-22 00:03:30 +01:00
|
|
|
import { clearConfirmTransaction } from '../../ducks/confirm-transaction/confirm-transaction.duck'
|
2020-05-29 19:46:10 +02:00
|
|
|
import { updateSend, showSendTokenPage } from '../../store/actions'
|
2019-03-22 00:03:30 +01:00
|
|
|
import { conversionUtil } from '../../helpers/utils/conversion-util'
|
2020-05-02 21:41:17 +02:00
|
|
|
import { sendTokenTokenAmountAndToAddressSelector } from '../../selectors'
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
const mapStateToProps = (state) => {
|
2018-07-14 22:47:07 +02:00
|
|
|
const { tokenAmount } = sendTokenTokenAmountAndToAddressSelector(state)
|
2018-06-23 08:52:45 +02:00
|
|
|
|
|
|
|
return {
|
2018-07-14 22:47:07 +02:00
|
|
|
tokenAmount,
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
const mapDispatchToProps = (dispatch) => {
|
2018-06-23 08:52:45 +02:00
|
|
|
return {
|
|
|
|
editTransaction: ({ txData, tokenData, tokenProps }) => {
|
2020-03-06 22:34:56 +01:00
|
|
|
|
|
|
|
const {
|
|
|
|
id,
|
|
|
|
txParams: {
|
|
|
|
from,
|
|
|
|
to: tokenAddress,
|
|
|
|
gas: gasLimit,
|
|
|
|
gasPrice,
|
|
|
|
} = {},
|
|
|
|
} = txData
|
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
const { params = [] } = tokenData
|
|
|
|
const { value: to } = params[0] || {}
|
|
|
|
const { value: tokenAmountInDec } = params[1] || {}
|
2020-03-06 22:34:56 +01:00
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
const tokenAmountInHex = conversionUtil(tokenAmountInDec, {
|
|
|
|
fromNumericBase: 'dec',
|
|
|
|
toNumericBase: 'hex',
|
|
|
|
})
|
2020-03-06 22:34:56 +01:00
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
dispatch(updateSend({
|
2020-03-06 22:34:56 +01:00
|
|
|
from,
|
2018-06-23 08:52:45 +02:00
|
|
|
gasLimit,
|
|
|
|
gasPrice,
|
|
|
|
gasTotal: null,
|
|
|
|
to,
|
|
|
|
amount: tokenAmountInHex,
|
|
|
|
errors: { to: null, amount: null },
|
|
|
|
editingTransactionId: id && id.toString(),
|
|
|
|
token: {
|
|
|
|
...tokenProps,
|
|
|
|
address: tokenAddress,
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
dispatch(clearConfirmTransaction())
|
|
|
|
dispatch(showSendTokenPage())
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default compose(
|
|
|
|
withRouter,
|
|
|
|
connect(mapStateToProps, mapDispatchToProps)
|
|
|
|
)(ConfirmSendToken)
|