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'
|
2018-07-06 20:58:41 +02:00
|
|
|
import {
|
|
|
|
setTransactionToConfirm,
|
|
|
|
clearConfirmTransaction,
|
2019-03-22 00:03:30 +01:00
|
|
|
} from '../../ducks/confirm-transaction/confirm-transaction.duck'
|
2020-11-03 00:41:28 +01:00
|
|
|
import { isTokenMethodAction } from '../../helpers/utils/transactions.util'
|
2020-12-03 00:25:19 +01:00
|
|
|
import { fetchBasicGasEstimates } from '../../ducks/gas/gas.duck'
|
2019-06-18 14:17:14 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
import { getContractMethodData, getTokenParams } from '../../store/actions'
|
2020-05-02 21:41:17 +02:00
|
|
|
import { unconfirmedTransactionsListSelector } from '../../selectors'
|
2020-06-01 19:54:32 +02:00
|
|
|
import { getMostRecentOverviewPage } from '../../ducks/history/history'
|
2020-08-18 21:18:25 +02:00
|
|
|
import ConfirmTransaction from './confirm-transaction.component'
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2019-06-18 14:17:14 +02:00
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2019-09-24 23:08:38 +02:00
|
|
|
const {
|
2020-11-03 00:41:28 +01:00
|
|
|
metamask: { send, unapprovedTxs },
|
2019-09-24 23:08:38 +02:00
|
|
|
} = state
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
match: { params = {} },
|
|
|
|
} = ownProps
|
2019-06-18 14:17:14 +02:00
|
|
|
const { id } = params
|
|
|
|
|
|
|
|
const unconfirmedTransactions = unconfirmedTransactionsListSelector(state)
|
|
|
|
const totalUnconfirmed = unconfirmedTransactions.length
|
|
|
|
const transaction = totalUnconfirmed
|
2020-01-10 15:34:02 +01:00
|
|
|
? unapprovedTxs[id] || unconfirmedTransactions[0]
|
2019-06-18 14:17:14 +02:00
|
|
|
: {}
|
2019-10-22 01:59:02 +02:00
|
|
|
const { id: transactionId, transactionCategory } = transaction
|
2019-09-24 23:08:38 +02:00
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
return {
|
2019-06-18 14:17:14 +02:00
|
|
|
totalUnapprovedCount: totalUnconfirmed,
|
2018-06-23 08:52:45 +02:00
|
|
|
send,
|
2019-06-18 14:17:14 +02:00
|
|
|
unapprovedTxs,
|
|
|
|
id,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: getMostRecentOverviewPage(state),
|
2019-06-18 14:17:14 +02:00
|
|
|
paramsTransactionId: id && String(id),
|
2019-06-28 05:53:12 +02:00
|
|
|
transactionId: transactionId && String(transactionId),
|
2019-06-18 14:17:14 +02:00
|
|
|
transaction,
|
2019-06-28 05:53:12 +02:00
|
|
|
isTokenMethodAction: isTokenMethodAction(transactionCategory),
|
2018-06-25 21:06:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
const mapDispatchToProps = (dispatch) => {
|
2018-06-25 21:06:57 +02:00
|
|
|
return {
|
2020-02-15 21:34:12 +01:00
|
|
|
setTransactionToConfirm: (transactionId) => {
|
2019-06-18 14:17:14 +02:00
|
|
|
dispatch(setTransactionToConfirm(transactionId))
|
|
|
|
},
|
2018-07-06 20:58:41 +02:00
|
|
|
clearConfirmTransaction: () => dispatch(clearConfirmTransaction()),
|
2020-12-03 00:25:19 +01:00
|
|
|
fetchBasicGasEstimates: () => dispatch(fetchBasicGasEstimates()),
|
2019-06-18 14:17:14 +02:00
|
|
|
getContractMethodData: (data) => dispatch(getContractMethodData(data)),
|
2019-06-28 05:53:12 +02:00
|
|
|
getTokenParams: (tokenAddress) => dispatch(getTokenParams(tokenAddress)),
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default compose(
|
|
|
|
withRouter,
|
2018-06-25 21:06:57 +02:00
|
|
|
connect(mapStateToProps, mapDispatchToProps),
|
2018-06-23 08:52:45 +02:00
|
|
|
)(ConfirmTransaction)
|