2021-09-15 17:59:51 +02:00
|
|
|
import { Tooltip } from '@material-ui/core';
|
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import Button from '../../ui/button';
|
|
|
|
import { getMaximumGasTotalInHexWei } from '../../../../shared/modules/gas.utils';
|
|
|
|
import { getConversionRate } from '../../../ducks/metamask/metamask';
|
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
|
|
|
import { useIncrementedGasFees } from '../../../hooks/useIncrementedGasFees';
|
|
|
|
import { isBalanceSufficient } from '../../../pages/send/send.utils';
|
|
|
|
import { getSelectedAccount } from '../../../selectors';
|
|
|
|
|
|
|
|
export default function CancelButton({
|
|
|
|
cancelTransaction,
|
|
|
|
transaction,
|
|
|
|
detailsModal,
|
|
|
|
}) {
|
|
|
|
const t = useI18nContext();
|
|
|
|
|
|
|
|
const customCancelGasSettings = useIncrementedGasFees(transaction);
|
|
|
|
|
|
|
|
const selectedAccount = useSelector(getSelectedAccount);
|
|
|
|
const conversionRate = useSelector(getConversionRate);
|
|
|
|
|
|
|
|
const hasEnoughCancelGas = isBalanceSufficient({
|
|
|
|
amount: '0x0',
|
|
|
|
gasTotal: getMaximumGasTotalInHexWei(customCancelGasSettings),
|
|
|
|
balance: selectedAccount.balance,
|
|
|
|
conversionRate,
|
|
|
|
});
|
|
|
|
|
|
|
|
const btn = (
|
|
|
|
<Button
|
|
|
|
onClick={cancelTransaction}
|
2021-10-05 21:20:42 +02:00
|
|
|
type="secondary"
|
2021-09-15 17:59:51 +02:00
|
|
|
className={classnames({
|
|
|
|
'transaction-list-item__header-button': !detailsModal,
|
2022-07-31 20:26:40 +02:00
|
|
|
'transaction-list-item-details__header-button-rounded-button':
|
|
|
|
detailsModal,
|
2021-09-15 17:59:51 +02:00
|
|
|
})}
|
|
|
|
disabled={!hasEnoughCancelGas}
|
2023-01-17 16:51:35 +01:00
|
|
|
data-testid="cancel-button"
|
2021-09-15 17:59:51 +02:00
|
|
|
>
|
|
|
|
{t('cancel')}
|
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
return hasEnoughCancelGas ? (
|
|
|
|
btn
|
|
|
|
) : (
|
|
|
|
<Tooltip
|
|
|
|
title={t('notEnoughGas')}
|
|
|
|
data-testid="not-enough-gas__tooltip"
|
|
|
|
position="bottom"
|
|
|
|
>
|
|
|
|
<div>{btn}</div>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
CancelButton.propTypes = {
|
|
|
|
transaction: PropTypes.object,
|
|
|
|
cancelTransaction: PropTypes.func,
|
|
|
|
detailsModal: PropTypes.bool,
|
|
|
|
};
|