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