2021-02-04 19:15:23 +01:00
|
|
|
import React, { useContext } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { I18nContext } from '../../../contexts/i18n';
|
|
|
|
import InfoTooltip from '../../../components/ui/info-tooltip';
|
2022-09-14 16:55:31 +02:00
|
|
|
import { CHAIN_IDS } from '../../../../shared/constants/network';
|
2021-07-30 13:35:30 +02:00
|
|
|
import TransactionDetail from '../../../components/app/transaction-detail/transaction-detail.component';
|
|
|
|
import TransactionDetailItem from '../../../components/app/transaction-detail-item/transaction-detail-item.component';
|
|
|
|
import Typography from '../../../components/ui/typography';
|
|
|
|
import {
|
|
|
|
COLORS,
|
|
|
|
TYPOGRAPHY,
|
|
|
|
FONT_WEIGHT,
|
|
|
|
} from '../../../helpers/constants/design-system';
|
2022-04-01 21:11:12 +02:00
|
|
|
import { MetaMetricsContext } from '../../../contexts/metametrics';
|
2022-04-22 18:09:10 +02:00
|
|
|
import { EVENT } from '../../../../shared/constants/metametrics';
|
2021-07-30 13:35:30 +02:00
|
|
|
|
|
|
|
const GAS_FEES_LEARN_MORE_URL =
|
|
|
|
'https://community.metamask.io/t/what-is-gas-why-do-transactions-take-so-long/3172';
|
2020-10-06 20:28:38 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export default function FeeCard({
|
2020-10-06 20:28:38 +02:00
|
|
|
primaryFee,
|
|
|
|
secondaryFee,
|
2020-10-14 19:06:17 +02:00
|
|
|
hideTokenApprovalRow,
|
2020-10-14 19:12:35 +02:00
|
|
|
tokenApprovalSourceTokenSymbol,
|
|
|
|
onTokenApprovalClick,
|
2020-12-08 17:47:53 +01:00
|
|
|
metaMaskFee,
|
|
|
|
numberOfQuotes,
|
|
|
|
onQuotesClick,
|
2021-04-16 23:52:32 +02:00
|
|
|
chainId,
|
2021-12-07 04:51:26 +01:00
|
|
|
isBestQuote,
|
2020-10-06 20:28:38 +02:00
|
|
|
}) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const t = useContext(I18nContext);
|
2020-10-14 19:06:17 +02:00
|
|
|
|
2022-10-04 18:55:05 +02:00
|
|
|
/* istanbul ignore next */
|
2021-04-16 23:52:32 +02:00
|
|
|
const getTranslatedNetworkName = () => {
|
|
|
|
switch (chainId) {
|
2022-09-14 16:55:31 +02:00
|
|
|
case CHAIN_IDS.MAINNET:
|
2021-04-16 23:52:32 +02:00
|
|
|
return t('networkNameEthereum');
|
2022-09-14 16:55:31 +02:00
|
|
|
case CHAIN_IDS.BSC:
|
2021-04-16 23:52:32 +02:00
|
|
|
return t('networkNameBSC');
|
2022-09-14 16:55:31 +02:00
|
|
|
case CHAIN_IDS.POLYGON:
|
2021-07-09 17:24:00 +02:00
|
|
|
return t('networkNamePolygon');
|
2022-09-14 16:55:31 +02:00
|
|
|
case CHAIN_IDS.LOCALHOST:
|
2021-04-16 23:52:32 +02:00
|
|
|
return t('networkNameTestnet');
|
2022-09-14 16:55:31 +02:00
|
|
|
case CHAIN_IDS.GOERLI:
|
2022-09-12 13:11:29 +02:00
|
|
|
return t('networkNameGoerli');
|
2022-09-14 16:55:31 +02:00
|
|
|
case CHAIN_IDS.AVALANCHE:
|
2022-02-18 15:24:47 +01:00
|
|
|
return t('networkNameAvalanche');
|
2022-11-08 19:14:17 +01:00
|
|
|
case CHAIN_IDS.OPTIMISM:
|
|
|
|
return t('networkNameOptimism');
|
|
|
|
case CHAIN_IDS.ARBITRUM:
|
|
|
|
return t('networkNameArbitrum');
|
2021-04-16 23:52:32 +02:00
|
|
|
default:
|
|
|
|
throw new Error('This network is not supported for token swaps');
|
|
|
|
}
|
|
|
|
};
|
2022-03-25 14:21:29 +01:00
|
|
|
const trackEvent = useContext(MetaMetricsContext);
|
2021-07-30 13:35:30 +02:00
|
|
|
|
2021-12-07 04:51:26 +01:00
|
|
|
const tokenApprovalTextComponent = (
|
|
|
|
<span key="fee-card-approve-symbol" className="fee-card__bold">
|
|
|
|
{t('enableToken', [tokenApprovalSourceTokenSymbol])}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
|
2020-10-06 20:28:38 +02:00
|
|
|
return (
|
|
|
|
<div className="fee-card">
|
|
|
|
<div className="fee-card__main">
|
2021-12-07 04:51:26 +01:00
|
|
|
<TransactionDetail
|
2022-06-15 21:08:13 +02:00
|
|
|
disableEditGasFeeButton
|
2021-12-07 04:51:26 +01:00
|
|
|
rows={[
|
|
|
|
<TransactionDetailItem
|
|
|
|
key="gas-item"
|
|
|
|
detailTitle={
|
2022-06-15 21:08:13 +02:00
|
|
|
<>
|
|
|
|
{t('transactionDetailGasHeading')}
|
|
|
|
<InfoTooltip
|
|
|
|
position="top"
|
|
|
|
contentText={
|
|
|
|
<>
|
|
|
|
<p className="fee-card__info-tooltip-paragraph">
|
|
|
|
{t('swapGasFeesSummary', [
|
|
|
|
getTranslatedNetworkName(),
|
|
|
|
])}
|
|
|
|
</p>
|
|
|
|
<p className="fee-card__info-tooltip-paragraph">
|
|
|
|
{t('swapGasFeesDetails')}
|
|
|
|
</p>
|
|
|
|
<p className="fee-card__info-tooltip-paragraph">
|
|
|
|
<a
|
|
|
|
className="fee-card__link"
|
|
|
|
onClick={() => {
|
2022-10-04 18:55:05 +02:00
|
|
|
/* istanbul ignore next */
|
2022-06-15 21:08:13 +02:00
|
|
|
trackEvent({
|
|
|
|
event: 'Clicked "Gas Fees: Learn More" Link',
|
|
|
|
category: EVENT.CATEGORIES.SWAPS,
|
|
|
|
});
|
|
|
|
global.platform.openTab({
|
|
|
|
url: GAS_FEES_LEARN_MORE_URL,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
{t('swapGasFeesLearnMore')}
|
|
|
|
</a>
|
|
|
|
</p>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
containerClassName="fee-card__info-tooltip-content-container"
|
|
|
|
wrapperClassName="fee-card__row-label fee-card__info-tooltip-container"
|
|
|
|
/>
|
|
|
|
</>
|
2021-12-07 04:51:26 +01:00
|
|
|
}
|
|
|
|
detailText={primaryFee.fee}
|
|
|
|
detailTotal={secondaryFee.fee}
|
|
|
|
subText={
|
|
|
|
secondaryFee?.maxFee !== undefined && (
|
2021-07-30 13:35:30 +02:00
|
|
|
<>
|
2021-12-07 04:51:26 +01:00
|
|
|
<Typography
|
2022-08-10 21:42:42 +02:00
|
|
|
as="span"
|
2021-12-07 04:51:26 +01:00
|
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
2022-03-09 16:24:53 +01:00
|
|
|
color={COLORS.TEXT_ALTERNATIVE}
|
2021-12-07 04:51:26 +01:00
|
|
|
variant={TYPOGRAPHY.H7}
|
|
|
|
>
|
|
|
|
{t('maxFee')}
|
|
|
|
</Typography>
|
|
|
|
{`: ${secondaryFee.maxFee}`}
|
2021-07-30 13:35:30 +02:00
|
|
|
</>
|
2021-12-07 04:51:26 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
/>,
|
|
|
|
]}
|
|
|
|
/>
|
2020-10-14 19:06:17 +02:00
|
|
|
{!hideTokenApprovalRow && (
|
2020-12-08 17:47:53 +01:00
|
|
|
<div className="fee-card__row-header">
|
2020-10-06 20:28:38 +02:00
|
|
|
<div className="fee-card__row-label">
|
|
|
|
<div className="fee-card__row-header-text">
|
2021-12-07 04:51:26 +01:00
|
|
|
{t('swapEnableTokenForSwapping', [tokenApprovalTextComponent])}
|
|
|
|
<InfoTooltip
|
|
|
|
position="top"
|
|
|
|
contentText={t('swapEnableDescription', [
|
|
|
|
tokenApprovalSourceTokenSymbol,
|
|
|
|
])}
|
|
|
|
containerClassName="fee-card__info-tooltip-container"
|
|
|
|
/>
|
2020-10-06 20:28:38 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-12-08 17:47:53 +01:00
|
|
|
<div
|
|
|
|
className="fee-card__link"
|
|
|
|
onClick={() => onTokenApprovalClick()}
|
|
|
|
>
|
|
|
|
{t('swapEditLimit')}
|
|
|
|
</div>
|
2020-10-06 20:28:38 +02:00
|
|
|
</div>
|
|
|
|
)}
|
2021-12-07 04:51:26 +01:00
|
|
|
<div className="fee-card__row-header">
|
2020-12-08 17:47:53 +01:00
|
|
|
<div className="fee-card__row-label">
|
|
|
|
<div className="fee-card__row-header-text">
|
2021-12-07 04:51:26 +01:00
|
|
|
{numberOfQuotes > 1 && (
|
|
|
|
<span
|
|
|
|
onClick={onQuotesClick}
|
|
|
|
className="fee-card__quote-link-text"
|
|
|
|
>
|
|
|
|
{isBestQuote
|
|
|
|
? t('swapBestOfNQuotes', [numberOfQuotes])
|
|
|
|
: t('swapNQuotesWithDot', [numberOfQuotes])}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
{t('swapIncludesMMFee', [metaMaskFee])}
|
|
|
|
<InfoTooltip
|
|
|
|
position="top"
|
|
|
|
contentText={t('swapMetaMaskFeeDescription', [metaMaskFee])}
|
|
|
|
wrapperClassName="fee-card__info-tooltip-container"
|
|
|
|
/>
|
2020-12-08 17:47:53 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-10-06 20:28:38 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
}),
|
2020-10-14 19:06:17 +02:00
|
|
|
hideTokenApprovalRow: PropTypes.bool.isRequired,
|
2020-10-14 19:12:35 +02:00
|
|
|
tokenApprovalSourceTokenSymbol: PropTypes.string,
|
|
|
|
onTokenApprovalClick: PropTypes.func,
|
2020-12-08 17:47:53 +01:00
|
|
|
metaMaskFee: PropTypes.string.isRequired,
|
|
|
|
onQuotesClick: PropTypes.func.isRequired,
|
|
|
|
numberOfQuotes: PropTypes.number.isRequired,
|
2021-04-16 23:52:32 +02:00
|
|
|
chainId: PropTypes.string.isRequired,
|
2022-11-03 14:54:49 +01:00
|
|
|
isBestQuote: PropTypes.bool,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|