import React, { useContext } from 'react' import PropTypes from 'prop-types' import BigNumber from 'bignumber.js' import classnames from 'classnames' import { I18nContext } from '../../../contexts/i18n' import InfoTooltip from '../../../components/ui/info-tooltip' import { decEthToConvertedCurrency } from '../../../helpers/utils/conversions.util' import { formatCurrency } from '../../../helpers/utils/confirm-tx.util' import PigIcon from './pig-icon' export default function FeeCard({ primaryFee, secondaryFee, hideTokenApprovalRow, onFeeCardMaxRowClick, tokenApprovalTextComponent, tokenApprovalSourceTokenSymbol, onTokenApprovalClick, metaMaskFee, savings, isBestQuote, numberOfQuotes, onQuotesClick, conversionRate, currentCurrency, tokenConversionRate, }) { const t = useContext(I18nContext) const savingAmount = isBestQuote && savings?.total ? formatCurrency( decEthToConvertedCurrency( savings.total, currentCurrency, conversionRate, ), currentCurrency, ) : null const savingsIsPositive = savings?.total && new BigNumber(savings.total, 10).gt(0) const inDevelopment = process.env.NODE_ENV === 'development' const shouldDisplaySavings = inDevelopment && isBestQuote && tokenConversionRate && savingsIsPositive let savingsText = '' if (inDevelopment && shouldDisplaySavings) { savingsText = t('swapSaving', [ ~ , savingAmount, ]) } else if (inDevelopment && isBestQuote && tokenConversionRate) { savingsText = t('swapUsingBestQuote') } else if (inDevelopment && savingsIsPositive && tokenConversionRate) { savingsText = t('swapBetterQuoteAvailable') } return (
{shouldDisplaySavings && (
)}
{savingsText && (

{savingsText}

)}

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

{t('swapEstimatedNetworkFee')}

{t('swapNetworkFeeSummary')}

{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}
)}
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, savings: PropTypes.object, isBestQuote: PropTypes.bool, onQuotesClick: PropTypes.func.isRequired, numberOfQuotes: PropTypes.number.isRequired, conversionRate: PropTypes.number, currentCurrency: PropTypes.string, tokenConversionRate: PropTypes.number, }