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';
|
2021-07-30 13:35:30 +02:00
|
|
|
import { useNewMetricEvent } from '../../../hooks/useMetricEvent';
|
2021-04-16 23:52:32 +02:00
|
|
|
import {
|
|
|
|
MAINNET_CHAIN_ID,
|
|
|
|
BSC_CHAIN_ID,
|
|
|
|
LOCALHOST_CHAIN_ID,
|
2021-07-09 17:24:00 +02:00
|
|
|
POLYGON_CHAIN_ID,
|
2021-07-30 13:35:30 +02:00
|
|
|
RINKEBY_CHAIN_ID,
|
2021-04-28 21:53:59 +02:00
|
|
|
} 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 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';
|
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,
|
|
|
|
onFeeCardMaxRowClick,
|
|
|
|
tokenApprovalTextComponent,
|
2020-10-14 19:12:35 +02:00
|
|
|
tokenApprovalSourceTokenSymbol,
|
|
|
|
onTokenApprovalClick,
|
2020-12-08 17:47:53 +01:00
|
|
|
metaMaskFee,
|
|
|
|
isBestQuote,
|
|
|
|
numberOfQuotes,
|
|
|
|
onQuotesClick,
|
|
|
|
tokenConversionRate,
|
2021-04-16 23:52:32 +02:00
|
|
|
chainId,
|
2021-08-03 00:52:18 +02:00
|
|
|
networkAndAccountSupports1559,
|
2021-07-30 13:35:30 +02:00
|
|
|
maxPriorityFeePerGasDecGWEI,
|
2021-07-30 15:19:30 +02:00
|
|
|
maxFeePerGasDecGWEI,
|
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
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let bestQuoteText = '';
|
2020-12-08 17:47:53 +01:00
|
|
|
if (isBestQuote && tokenConversionRate) {
|
2021-02-04 19:15:23 +01:00
|
|
|
bestQuoteText = t('swapUsingBestQuote');
|
2020-12-08 17:47:53 +01:00
|
|
|
} else if (tokenConversionRate) {
|
2021-02-04 19:15:23 +01:00
|
|
|
bestQuoteText = t('swapBetterQuoteAvailable');
|
2020-12-08 17:47:53 +01:00
|
|
|
}
|
|
|
|
|
2021-04-16 23:52:32 +02:00
|
|
|
const getTranslatedNetworkName = () => {
|
|
|
|
switch (chainId) {
|
|
|
|
case MAINNET_CHAIN_ID:
|
|
|
|
return t('networkNameEthereum');
|
|
|
|
case BSC_CHAIN_ID:
|
|
|
|
return t('networkNameBSC');
|
2021-07-09 17:24:00 +02:00
|
|
|
case POLYGON_CHAIN_ID:
|
|
|
|
return t('networkNamePolygon');
|
2021-04-16 23:52:32 +02:00
|
|
|
case LOCALHOST_CHAIN_ID:
|
|
|
|
return t('networkNameTestnet');
|
2021-07-30 13:35:30 +02:00
|
|
|
case RINKEBY_CHAIN_ID:
|
|
|
|
return t('networkNameRinkeby');
|
2021-04-16 23:52:32 +02:00
|
|
|
default:
|
|
|
|
throw new Error('This network is not supported for token swaps');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-30 13:35:30 +02:00
|
|
|
const gasFeesLearnMoreLinkClickedEvent = useNewMetricEvent({
|
|
|
|
category: 'Swaps',
|
|
|
|
event: 'Clicked "Gas Fees: Learn More" Link',
|
|
|
|
});
|
|
|
|
|
2020-10-06 20:28:38 +02:00
|
|
|
return (
|
|
|
|
<div className="fee-card">
|
2021-07-02 15:48:34 +02:00
|
|
|
<div
|
|
|
|
className="fee-card__savings-and-quotes-header"
|
|
|
|
data-testid="fee-card__savings-and-quotes-header"
|
|
|
|
>
|
2020-12-08 17:47:53 +01:00
|
|
|
<div className="fee-card__savings-and-quotes-row">
|
|
|
|
{bestQuoteText && (
|
|
|
|
<p className="fee-card__savings-text">{bestQuoteText}</p>
|
|
|
|
)}
|
2021-09-08 20:08:55 +02:00
|
|
|
{numberOfQuotes > 1 && (
|
|
|
|
<div
|
|
|
|
className="fee-card__quote-link-container"
|
|
|
|
onClick={onQuotesClick}
|
|
|
|
>
|
|
|
|
<p className="fee-card__quote-link-text">
|
|
|
|
{t('swapNQuotes', [numberOfQuotes])}
|
|
|
|
</p>
|
|
|
|
<div className="fee-card__caret-right">
|
|
|
|
<i className="fa fa-angle-up" />
|
|
|
|
</div>
|
2020-12-08 17:47:53 +01:00
|
|
|
</div>
|
2021-09-08 20:08:55 +02:00
|
|
|
)}
|
2020-12-08 17:47:53 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-10-06 20:28:38 +02:00
|
|
|
<div className="fee-card__main">
|
2021-08-03 00:52:18 +02:00
|
|
|
{networkAndAccountSupports1559 && (
|
2021-07-30 13:35:30 +02:00
|
|
|
<TransactionDetail
|
|
|
|
rows={[
|
|
|
|
<TransactionDetailItem
|
|
|
|
key="gas-item"
|
|
|
|
detailTitle={
|
|
|
|
<>
|
|
|
|
{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={() => {
|
|
|
|
gasFeesLearnMoreLinkClickedEvent();
|
|
|
|
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"
|
|
|
|
wide
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
detailText={primaryFee.fee}
|
|
|
|
detailTotal={secondaryFee.fee}
|
|
|
|
subTitle={
|
|
|
|
<GasTiming
|
|
|
|
maxPriorityFeePerGas={maxPriorityFeePerGasDecGWEI}
|
2021-07-30 15:19:30 +02:00
|
|
|
maxFeePerGas={maxFeePerGasDecGWEI}
|
2021-07-30 13:35:30 +02:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
subText={
|
|
|
|
secondaryFee?.maxFee !== undefined && (
|
|
|
|
<>
|
|
|
|
<Typography
|
|
|
|
tag="span"
|
|
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
|
|
color={COLORS.UI4}
|
|
|
|
variant={TYPOGRAPHY.H7}
|
|
|
|
>
|
|
|
|
{t('maxFee')}
|
|
|
|
</Typography>
|
|
|
|
{`: ${secondaryFee.maxFee}`}
|
|
|
|
<span
|
|
|
|
className="fee-card__edit-link"
|
|
|
|
onClick={() => onFeeCardMaxRowClick()}
|
|
|
|
>
|
|
|
|
{t('edit')}
|
|
|
|
</span>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>,
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
)}
|
2021-08-03 00:52:18 +02:00
|
|
|
{!networkAndAccountSupports1559 && (
|
2021-07-30 13:35:30 +02:00
|
|
|
<div
|
|
|
|
className="fee-card__row-header"
|
|
|
|
data-testid="fee-card__row-header"
|
|
|
|
>
|
|
|
|
<div>
|
|
|
|
<div className="fee-card__row-header-text--bold">
|
|
|
|
{t('swapEstimatedNetworkFee')}
|
|
|
|
</div>
|
|
|
|
<InfoTooltip
|
|
|
|
position="top"
|
|
|
|
contentText={
|
|
|
|
<>
|
|
|
|
<p className="fee-card__info-tooltip-paragraph">
|
|
|
|
{t('swapNetworkFeeSummary', [getTranslatedNetworkName()])}
|
|
|
|
</p>
|
|
|
|
<p className="fee-card__info-tooltip-paragraph">
|
|
|
|
{t('swapEstimatedNetworkFeeSummary', [
|
|
|
|
<span className="fee-card__bold" key="fee-card-bold-1">
|
|
|
|
{t('swapEstimatedNetworkFee')}
|
|
|
|
</span>,
|
|
|
|
])}
|
|
|
|
</p>
|
|
|
|
<p className="fee-card__info-tooltip-paragraph">
|
|
|
|
{t('swapMaxNetworkFeeInfo', [
|
|
|
|
<span className="fee-card__bold" key="fee-card-bold-2">
|
|
|
|
{t('swapMaxNetworkFees')}
|
|
|
|
</span>,
|
|
|
|
])}
|
|
|
|
</p>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
containerClassName="fee-card__info-tooltip-content-container"
|
|
|
|
wrapperClassName="fee-card__row-label fee-card__info-tooltip-container"
|
|
|
|
wide
|
|
|
|
/>
|
2020-10-06 20:28:38 +02:00
|
|
|
</div>
|
2021-07-30 13:35:30 +02:00
|
|
|
<div>
|
|
|
|
<div className="fee-card__row-header-secondary--bold">
|
|
|
|
{primaryFee.fee}
|
2020-10-06 20:28:38 +02:00
|
|
|
</div>
|
2021-07-30 13:35:30 +02:00
|
|
|
{secondaryFee && (
|
|
|
|
<div className="fee-card__row-header-primary--bold">
|
|
|
|
{secondaryFee.fee}
|
|
|
|
</div>
|
|
|
|
)}
|
2020-10-06 20:28:38 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-07-30 13:35:30 +02:00
|
|
|
)}
|
2021-08-03 00:52:18 +02:00
|
|
|
{!networkAndAccountSupports1559 && (
|
2021-07-30 13:35:30 +02:00
|
|
|
<div
|
|
|
|
className="fee-card__row-header"
|
|
|
|
onClick={() => onFeeCardMaxRowClick()}
|
|
|
|
>
|
|
|
|
<div>
|
|
|
|
<div className="fee-card__row-header-text">
|
|
|
|
{t('swapMaxNetworkFees')}
|
|
|
|
</div>
|
|
|
|
<div className="fee-card__link">{t('edit')}</div>
|
2020-10-06 20:28:38 +02:00
|
|
|
</div>
|
2021-07-30 13:35:30 +02:00
|
|
|
<div>
|
|
|
|
<div className="fee-card__row-header-secondary">
|
|
|
|
{primaryFee.maxFee}
|
2020-10-06 20:28:38 +02:00
|
|
|
</div>
|
2021-07-30 13:35:30 +02:00
|
|
|
{secondaryFee?.maxFee !== undefined && (
|
|
|
|
<div className="fee-card__row-header-primary">
|
|
|
|
{secondaryFee.maxFee}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
2020-10-06 20:28:38 +02:00
|
|
|
</div>
|
2021-07-30 13:35:30 +02: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">
|
2020-10-14 19:06:17 +02:00
|
|
|
{t('swapThisWillAllowApprove', [tokenApprovalTextComponent])}
|
2020-10-06 20:28:38 +02:00
|
|
|
</div>
|
|
|
|
<InfoTooltip
|
|
|
|
position="top"
|
2020-11-03 00:41:28 +01:00
|
|
|
contentText={t('swapEnableDescription', [
|
|
|
|
tokenApprovalSourceTokenSymbol,
|
|
|
|
])}
|
2020-12-08 17:47:53 +01:00
|
|
|
containerClassName="fee-card__info-tooltip-container"
|
2020-10-06 20:28:38 +02:00
|
|
|
/>
|
|
|
|
</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>
|
|
|
|
)}
|
2020-12-08 17:47:53 +01:00
|
|
|
<div className="fee-card__top-bordered-row">
|
|
|
|
<div className="fee-card__row-label">
|
|
|
|
<div className="fee-card__row-header-text">
|
|
|
|
{t('swapQuoteIncludesRate', [metaMaskFee])}
|
|
|
|
</div>
|
|
|
|
<InfoTooltip
|
|
|
|
position="top"
|
|
|
|
contentText={t('swapMetaMaskFeeDescription', [metaMaskFee])}
|
|
|
|
wrapperClassName="fee-card__info-tooltip-container"
|
|
|
|
/>
|
|
|
|
</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
|
|
|
onFeeCardMaxRowClick: PropTypes.func.isRequired,
|
|
|
|
hideTokenApprovalRow: PropTypes.bool.isRequired,
|
|
|
|
tokenApprovalTextComponent: PropTypes.node,
|
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,
|
|
|
|
isBestQuote: PropTypes.bool,
|
|
|
|
onQuotesClick: PropTypes.func.isRequired,
|
|
|
|
numberOfQuotes: PropTypes.number.isRequired,
|
|
|
|
tokenConversionRate: PropTypes.number,
|
2021-04-16 23:52:32 +02:00
|
|
|
chainId: PropTypes.string.isRequired,
|
2021-08-03 00:52:18 +02:00
|
|
|
networkAndAccountSupports1559: PropTypes.bool.isRequired,
|
2021-07-30 13:35:30 +02:00
|
|
|
maxPriorityFeePerGasDecGWEI: PropTypes.string,
|
2021-07-30 15:19:30 +02:00
|
|
|
maxFeePerGasDecGWEI: PropTypes.string,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|