import React, { useContext } from 'react'; import PropTypes from 'prop-types'; import { I18nContext } from '../../../contexts/i18n'; import InfoTooltip from '../../../components/ui/info-tooltip'; import { useNewMetricEvent } from '../../../hooks/useMetricEvent'; import { MAINNET_CHAIN_ID, BSC_CHAIN_ID, LOCALHOST_CHAIN_ID, POLYGON_CHAIN_ID, RINKEBY_CHAIN_ID, } from '../../../../shared/constants/network'; import TransactionDetail from '../../../components/app/transaction-detail/transaction-detail.component'; import TransactionDetailItem from '../../../components/app/transaction-detail-item/transaction-detail-item.component'; import GasTiming from '../../../components/app/gas-timing/gas-timing.component'; import Typography from '../../../components/ui/typography'; import { COLORS, TYPOGRAPHY, FONT_WEIGHT, } from '../../../helpers/constants/design-system'; const GAS_FEES_LEARN_MORE_URL = 'https://community.metamask.io/t/what-is-gas-why-do-transactions-take-so-long/3172'; export default function FeeCard({ primaryFee, secondaryFee, hideTokenApprovalRow, onFeeCardMaxRowClick, tokenApprovalTextComponent, tokenApprovalSourceTokenSymbol, onTokenApprovalClick, metaMaskFee, isBestQuote, numberOfQuotes, onQuotesClick, tokenConversionRate, chainId, networkAndAccountSupports1559, maxPriorityFeePerGasDecGWEI, maxFeePerGasDecGWEI, }) { const t = useContext(I18nContext); let bestQuoteText = ''; if (isBestQuote && tokenConversionRate) { bestQuoteText = t('swapUsingBestQuote'); } else if (tokenConversionRate) { bestQuoteText = t('swapBetterQuoteAvailable'); } const getTranslatedNetworkName = () => { switch (chainId) { case MAINNET_CHAIN_ID: return t('networkNameEthereum'); case BSC_CHAIN_ID: return t('networkNameBSC'); case POLYGON_CHAIN_ID: return t('networkNamePolygon'); case LOCALHOST_CHAIN_ID: return t('networkNameTestnet'); case RINKEBY_CHAIN_ID: return t('networkNameRinkeby'); default: throw new Error('This network is not supported for token swaps'); } }; const gasFeesLearnMoreLinkClickedEvent = useNewMetricEvent({ category: 'Swaps', event: 'Clicked "Gas Fees: Learn More" Link', }); return (
{bestQuoteText && (

{bestQuoteText}

)} {numberOfQuotes > 1 && (

{t('swapNQuotes', [numberOfQuotes])}

)}
{networkAndAccountSupports1559 && ( {t('transactionDetailGasHeading')}

{t('swapGasFeesSummary', [ getTranslatedNetworkName(), ])}

{t('swapGasFeesDetails')}

{ gasFeesLearnMoreLinkClickedEvent(); global.platform.openTab({ url: GAS_FEES_LEARN_MORE_URL, }); }} target="_blank" rel="noopener noreferrer" > {t('swapGasFeesLearnMore')}

} containerClassName="fee-card__info-tooltip-content-container" wrapperClassName="fee-card__row-label fee-card__info-tooltip-container" wide /> } detailText={primaryFee.fee} detailTotal={secondaryFee.fee} subTitle={ } subText={ secondaryFee?.maxFee !== undefined && ( <> {t('maxFee')} {`: ${secondaryFee.maxFee}`} onFeeCardMaxRowClick()} > {t('edit')} ) } />, ]} /> )} {!networkAndAccountSupports1559 && (
{t('swapEstimatedNetworkFee')}

{t('swapNetworkFeeSummary', [getTranslatedNetworkName()])}

{t('swapEstimatedNetworkFeeSummary', [ {t('swapEstimatedNetworkFee')} , ])}

{t('swapMaxNetworkFeeInfo', [ {t('swapMaxNetworkFees')} , ])}

} containerClassName="fee-card__info-tooltip-content-container" wrapperClassName="fee-card__row-label fee-card__info-tooltip-container" wide />
{primaryFee.fee}
{secondaryFee && (
{secondaryFee.fee}
)}
)} {!networkAndAccountSupports1559 && (
onFeeCardMaxRowClick()} >
{t('swapMaxNetworkFees')}
{t('edit')}
{primaryFee.maxFee}
{secondaryFee?.maxFee !== undefined && (
{secondaryFee.maxFee}
)}
)} {!hideTokenApprovalRow && (
{t('swapThisWillAllowApprove', [tokenApprovalTextComponent])}
onTokenApprovalClick()} > {t('swapEditLimit')}
)}
{t('swapQuoteIncludesRate', [metaMaskFee])}
); } FeeCard.propTypes = { primaryFee: PropTypes.shape({ fee: PropTypes.string.isRequired, maxFee: PropTypes.string.isRequired, }).isRequired, secondaryFee: PropTypes.shape({ fee: PropTypes.string.isRequired, maxFee: PropTypes.string.isRequired, }), onFeeCardMaxRowClick: PropTypes.func.isRequired, hideTokenApprovalRow: PropTypes.bool.isRequired, tokenApprovalTextComponent: PropTypes.node, tokenApprovalSourceTokenSymbol: PropTypes.string, onTokenApprovalClick: PropTypes.func, metaMaskFee: PropTypes.string.isRequired, isBestQuote: PropTypes.bool, onQuotesClick: PropTypes.func.isRequired, numberOfQuotes: PropTypes.number.isRequired, tokenConversionRate: PropTypes.number, chainId: PropTypes.string.isRequired, networkAndAccountSupports1559: PropTypes.bool.isRequired, maxPriorityFeePerGasDecGWEI: PropTypes.string, maxFeePerGasDecGWEI: PropTypes.string, };