1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/components/app/cancel-button/cancel-button.js
Thomas Huang 4c3c4eebac
Final conversion of tests from enzyme to @testing-library/react (#16862)
* Add transaction activity log component

* Remove duplicate tx activity log snapshot.

* Convert Advanced Tab to tlr.

* Lint fix

* Change ENS to DNS in mock state data.

* Add test ids for speedup, cancel, rety buttons.

* Convert TransactionListItemDetails component to RTL.

* Convert PageContainerHeader component to RTL.

* Convert TokenInput component to RTL.

* Convert UnitInput component to RTL.

* Convert withModalProps to RTL.

* Convert i18n-helper to RTL.

* Convert ConfirmSeedPhrase component to TLR.

* Convert AddRecipient component to RTL.

* Set process.env metamask build type to 'main' for test

Co-authored-by: Brad Decker <bhdecker84@gmail.com>
Co-authored-by: Pedro Figueiredo <pedro.figueiredo@consensys.net>
2023-01-17 07:51:35 -08:00

66 lines
1.9 KiB
JavaScript

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}
type="secondary"
className={classnames({
'transaction-list-item__header-button': !detailsModal,
'transaction-list-item-details__header-button-rounded-button':
detailsModal,
})}
disabled={!hasEnoughCancelGas}
data-testid="cancel-button"
>
{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,
};