1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 08:09:15 +01:00
metamask-extension/ui/app/pages/confirm-transaction/confirm-transaction.container.js

64 lines
2.0 KiB
JavaScript
Raw Normal View History

import { connect } from 'react-redux'
import { compose } from 'recompose'
import { withRouter } from 'react-router-dom'
2018-07-06 20:58:41 +02:00
import {
setTransactionToConfirm,
clearConfirmTransaction,
} from '../../ducks/confirm-transaction/confirm-transaction.duck'
import {
isTokenMethodAction,
} from '../../helpers/utils/transactions.util'
import {
fetchBasicGasAndTimeEstimates,
} from '../../ducks/gas/gas.duck'
import {
getContractMethodData,
getTokenParams,
} from '../../store/actions'
import ConfirmTransaction from './confirm-transaction.component'
import { unconfirmedTransactionsListSelector } from '../../selectors/confirm-transaction'
const mapStateToProps = (state, ownProps) => {
const { metamask: { send, unapprovedTxs }, confirmTransaction } = state
const { match: { params = {} } } = ownProps
const { id } = params
const unconfirmedTransactions = unconfirmedTransactionsListSelector(state)
const totalUnconfirmed = unconfirmedTransactions.length
const transaction = totalUnconfirmed
? unapprovedTxs[id] || unconfirmedTransactions[totalUnconfirmed - 1]
: {}
const { id: transactionId, transactionCategory } = transaction
return {
totalUnapprovedCount: totalUnconfirmed,
send,
confirmTransaction,
unapprovedTxs,
id,
paramsTransactionId: id && String(id),
transactionId: transactionId && String(transactionId),
unconfirmedTransactions,
transaction,
isTokenMethodAction: isTokenMethodAction(transactionCategory),
}
}
const mapDispatchToProps = dispatch => {
return {
setTransactionToConfirm: transactionId => {
dispatch(setTransactionToConfirm(transactionId))
},
2018-07-06 20:58:41 +02:00
clearConfirmTransaction: () => dispatch(clearConfirmTransaction()),
fetchBasicGasAndTimeEstimates: () => dispatch(fetchBasicGasAndTimeEstimates()),
getContractMethodData: (data) => dispatch(getContractMethodData(data)),
getTokenParams: (tokenAddress) => dispatch(getTokenParams(tokenAddress)),
}
}
export default compose(
withRouter,
connect(mapStateToProps, mapDispatchToProps),
)(ConfirmTransaction)