2021-02-04 19:15:23 +01:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { compose } from 'redux';
|
|
|
|
import { withRouter } from 'react-router-dom';
|
2018-07-06 20:58:41 +02:00
|
|
|
import {
|
|
|
|
setTransactionToConfirm,
|
|
|
|
clearConfirmTransaction,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../ducks/confirm-transaction/confirm-transaction.duck';
|
|
|
|
import { isTokenMethodAction } from '../../helpers/utils/transactions.util';
|
|
|
|
import { fetchBasicGasEstimates } from '../../ducks/gas/gas.duck';
|
2019-06-18 14:17:14 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
import { getContractMethodData, getTokenParams } from '../../store/actions';
|
|
|
|
import { unconfirmedTransactionsListSelector } from '../../selectors';
|
|
|
|
import { getMostRecentOverviewPage } from '../../ducks/history/history';
|
|
|
|
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 },
|
2021-02-04 19:15:23 +01:00
|
|
|
} = state;
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
match: { params = {} },
|
2021-02-04 19:15:23 +01:00
|
|
|
} = ownProps;
|
|
|
|
const { id } = params;
|
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[id] || unconfirmedTransactions[0]
|
2021-02-04 19:15:23 +01:00
|
|
|
: {};
|
2021-03-10 21:16:44 +01:00
|
|
|
const { id: transactionId, type } = 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,
|
2021-03-10 21:16:44 +01:00
|
|
|
isTokenMethodAction: isTokenMethodAction(type),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
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) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(setTransactionToConfirm(transactionId));
|
2019-06-18 14:17:14 +02:00
|
|
|
},
|
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)),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2018-06-23 08:52:45 +02:00
|
|
|
|
|
|
|
export default compose(
|
|
|
|
withRouter,
|
2018-06-25 21:06:57 +02:00
|
|
|
connect(mapStateToProps, mapDispatchToProps),
|
2021-02-04 19:15:23 +01:00
|
|
|
)(ConfirmTransaction);
|