2021-02-04 19:15:23 +01:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import Modal from '../../modal';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { TRANSACTION_STATUSES } from '../../../../../shared/constants/transaction';
|
2021-02-04 19:15:23 +01:00
|
|
|
import CancelTransactionGasFee from './cancel-transaction-gas-fee';
|
2018-09-17 19:34:29 +02:00
|
|
|
|
|
|
|
export default class CancelTransaction extends PureComponent {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-09-17 19:34:29 +02:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
createCancelTransaction: PropTypes.func,
|
|
|
|
hideModal: PropTypes.func,
|
|
|
|
showTransactionConfirmedModal: PropTypes.func,
|
|
|
|
transactionStatus: PropTypes.string,
|
2018-09-21 04:35:45 +02:00
|
|
|
newGasFee: PropTypes.string,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-09-17 19:34:29 +02:00
|
|
|
|
2018-12-12 00:04:57 +01:00
|
|
|
state = {
|
|
|
|
busy: false,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-12-12 00:04:57 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
componentDidUpdate() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { transactionStatus, showTransactionConfirmedModal } = this.props;
|
2018-09-17 19:34:29 +02:00
|
|
|
|
2020-11-03 23:57:51 +01:00
|
|
|
if (transactionStatus !== TRANSACTION_STATUSES.SUBMITTED) {
|
2021-02-04 19:15:23 +01:00
|
|
|
showTransactionConfirmedModal();
|
2018-09-17 19:34:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSubmit = async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { createCancelTransaction, hideModal } = this.props;
|
2018-09-17 19:34:29 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
this.setState({ busy: true });
|
2018-12-12 00:04:57 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await createCancelTransaction();
|
|
|
|
this.setState({ busy: false }, () => hideModal());
|
|
|
|
};
|
2018-09-17 19:34:29 +02:00
|
|
|
|
|
|
|
handleCancel = () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.props.hideModal();
|
|
|
|
};
|
2018-09-17 19:34:29 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { t } = this.context;
|
|
|
|
const { newGasFee } = this.props;
|
|
|
|
const { busy } = this.state;
|
2018-09-17 19:34:29 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
headerText={t('attemptToCancel')}
|
2018-09-21 04:35:45 +02:00
|
|
|
onClose={this.handleCancel}
|
2018-09-17 19:34:29 +02:00
|
|
|
onSubmit={this.handleSubmit}
|
|
|
|
onCancel={this.handleCancel}
|
|
|
|
submitText={t('yesLetsTry')}
|
|
|
|
cancelText={t('nevermind')}
|
2018-12-12 00:04:57 +01:00
|
|
|
submitDisabled={busy}
|
2018-09-17 19:34:29 +02:00
|
|
|
>
|
|
|
|
<div>
|
|
|
|
<div className="cancel-transaction__title">
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('cancellationGasFee')}
|
2018-09-17 19:34:29 +02:00
|
|
|
</div>
|
2018-09-19 23:30:52 +02:00
|
|
|
<div className="cancel-transaction__cancel-transaction-gas-fee-container">
|
|
|
|
<CancelTransactionGasFee value={newGasFee} />
|
|
|
|
</div>
|
2018-09-17 19:34:29 +02:00
|
|
|
<div className="cancel-transaction__description">
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('attemptToCancelDescription')}
|
2018-09-17 19:34:29 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Modal>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-09-17 19:34:29 +02:00
|
|
|
}
|
|
|
|
}
|