2018-08-31 21:34:22 +02:00
|
|
|
import { connect } from 'react-redux'
|
2018-12-09 21:48:06 +01:00
|
|
|
import R from 'ramda'
|
2018-08-31 21:34:22 +02:00
|
|
|
import TransactionActivityLog from './transaction-activity-log.component'
|
2018-10-26 10:26:43 +02:00
|
|
|
import { conversionRateSelector, getNativeCurrency } from '../../selectors'
|
2018-12-09 21:48:06 +01:00
|
|
|
import { combineTransactionHistories } from './transaction-activity-log.util'
|
|
|
|
import {
|
|
|
|
TRANSACTION_RESUBMITTED_EVENT,
|
|
|
|
TRANSACTION_CANCEL_ATTEMPTED_EVENT,
|
|
|
|
} from './transaction-activity-log.constants'
|
|
|
|
|
|
|
|
const matchesEventKey = matchEventKey => ({ eventKey }) => eventKey === matchEventKey
|
2018-08-31 21:34:22 +02:00
|
|
|
|
|
|
|
const mapStateToProps = state => {
|
|
|
|
return {
|
|
|
|
conversionRate: conversionRateSelector(state),
|
2018-10-26 10:26:43 +02:00
|
|
|
nativeCurrency: getNativeCurrency(state),
|
2018-08-31 21:34:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-09 21:48:06 +01:00
|
|
|
const mergeProps = (stateProps, dispatchProps, ownProps) => {
|
|
|
|
const {
|
|
|
|
transactionGroup: {
|
|
|
|
transactions = [],
|
|
|
|
primaryTransaction,
|
|
|
|
} = {},
|
|
|
|
...restOwnProps
|
|
|
|
} = ownProps
|
|
|
|
|
|
|
|
const activities = combineTransactionHistories(transactions)
|
|
|
|
const inlineRetryIndex = R.findLastIndex(matchesEventKey(TRANSACTION_RESUBMITTED_EVENT))(activities)
|
|
|
|
const inlineCancelIndex = R.findLastIndex(matchesEventKey(TRANSACTION_CANCEL_ATTEMPTED_EVENT))(activities)
|
|
|
|
|
|
|
|
return {
|
|
|
|
...stateProps,
|
|
|
|
...dispatchProps,
|
|
|
|
...restOwnProps,
|
|
|
|
activities,
|
|
|
|
inlineRetryIndex,
|
|
|
|
inlineCancelIndex,
|
|
|
|
primaryTransaction,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, null, mergeProps)(TransactionActivityLog)
|