2021-02-04 19:15:23 +01:00
|
|
|
import { connect } from 'react-redux';
|
2023-09-04 17:48:25 +02:00
|
|
|
import {
|
|
|
|
getUnapprovedTransactions,
|
|
|
|
unconfirmedTransactionsListSelector,
|
|
|
|
} from '../../selectors';
|
2021-02-04 19:15:23 +01:00
|
|
|
import ConfirmTransactionSwitch from './confirm-transaction-switch.component';
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2019-06-18 14:17:14 +02:00
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2023-09-04 17:48:25 +02:00
|
|
|
const unapprovedTxs = getUnapprovedTransactions(state);
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
match: { params = {}, url },
|
2021-02-04 19:15:23 +01:00
|
|
|
} = ownProps;
|
|
|
|
const urlId = url?.match(/\d+/u) && url?.match(/\d+/u)[0];
|
|
|
|
const { id: paramsId } = params;
|
|
|
|
const transactionId = paramsId || urlId;
|
2019-06-18 14:17:14 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const unconfirmedTransactions = unconfirmedTransactionsListSelector(state);
|
|
|
|
const totalUnconfirmed = unconfirmedTransactions.length;
|
2019-06-18 14:17:14 +02:00
|
|
|
const transaction = totalUnconfirmed
|
2020-01-10 15:34:02 +01:00
|
|
|
? unapprovedTxs[transactionId] || unconfirmedTransactions[0]
|
2021-02-04 19:15:23 +01:00
|
|
|
: {};
|
2018-06-25 21:06:57 +02:00
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
return {
|
2019-06-18 14:17:14 +02:00
|
|
|
txData: transaction,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export default connect(mapStateToProps)(ConfirmTransactionSwitch);
|