2021-02-04 19:15:23 +01:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { compose } from 'redux';
|
|
|
|
import withModalProps from '../../../../helpers/higher-order-components/with-modal-props';
|
|
|
|
import { showModal, createCancelTransaction } from '../../../../store/actions';
|
|
|
|
import CancelTransaction from './cancel-transaction.component';
|
2018-09-17 19:34:29 +02:00
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { metamask } = state;
|
2021-03-12 20:26:07 +01:00
|
|
|
const {
|
|
|
|
transactionId,
|
|
|
|
originalGasPrice,
|
|
|
|
newGasFee,
|
2021-07-08 20:48:23 +02:00
|
|
|
customGasSettings,
|
2021-03-12 20:26:07 +01:00
|
|
|
} = ownProps;
|
2021-02-04 19:15:23 +01:00
|
|
|
const { currentNetworkTxList } = metamask;
|
2020-11-03 00:41:28 +01:00
|
|
|
const transaction = currentNetworkTxList.find(
|
|
|
|
({ id }) => id === transactionId,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
const transactionStatus = transaction ? transaction.status : '';
|
2018-09-17 19:34:29 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
transactionId,
|
|
|
|
transactionStatus,
|
|
|
|
originalGasPrice,
|
2021-07-08 20:48:23 +02:00
|
|
|
customGasSettings,
|
2018-09-21 04:35:45 +02:00
|
|
|
newGasFee,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2018-09-17 19:34:29 +02:00
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
const mapDispatchToProps = (dispatch) => {
|
2018-09-17 19:34:29 +02:00
|
|
|
return {
|
2021-07-08 20:48:23 +02:00
|
|
|
createCancelTransaction: (txId, customGasSettings) => {
|
|
|
|
return dispatch(createCancelTransaction(txId, customGasSettings));
|
2018-12-09 21:48:06 +01:00
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
showTransactionConfirmedModal: () =>
|
|
|
|
dispatch(showModal({ name: 'TRANSACTION_CONFIRMED' })),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2018-09-17 19:34:29 +02:00
|
|
|
|
|
|
|
const mergeProps = (stateProps, dispatchProps, ownProps) => {
|
2021-07-08 20:48:23 +02:00
|
|
|
const { transactionId, customGasSettings, ...restStateProps } = stateProps;
|
2020-08-18 18:36:45 +02:00
|
|
|
// eslint-disable-next-line no-shadow
|
2021-02-04 19:15:23 +01:00
|
|
|
const { createCancelTransaction, ...restDispatchProps } = dispatchProps;
|
2018-09-17 19:34:29 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
...restStateProps,
|
|
|
|
...restDispatchProps,
|
|
|
|
...ownProps,
|
2020-11-03 00:41:28 +01:00
|
|
|
createCancelTransaction: () =>
|
2021-07-08 20:48:23 +02:00
|
|
|
createCancelTransaction(transactionId, customGasSettings),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2018-09-17 19:34:29 +02:00
|
|
|
|
|
|
|
export default compose(
|
|
|
|
withModalProps,
|
|
|
|
connect(mapStateToProps, mapDispatchToProps, mergeProps),
|
2021-02-04 19:15:23 +01:00
|
|
|
)(CancelTransaction);
|