2020-10-14 19:06:17 +02:00
|
|
|
import React, { useContext } from 'react'
|
2020-10-06 20:28:38 +02:00
|
|
|
import PropTypes from 'prop-types'
|
2020-11-13 18:12:50 +01:00
|
|
|
import BigNumber from 'bignumber.js'
|
|
|
|
import classnames from 'classnames'
|
2020-10-14 19:06:17 +02:00
|
|
|
import { I18nContext } from '../../../contexts/i18n'
|
2020-10-06 20:28:38 +02:00
|
|
|
import InfoTooltip from '../../../components/ui/info-tooltip'
|
2020-11-13 18:12:50 +01:00
|
|
|
import { decEthToConvertedCurrency } from '../../../helpers/utils/conversions.util'
|
|
|
|
import { formatCurrency } from '../../../helpers/utils/confirm-tx.util'
|
|
|
|
import PigIcon from './pig-icon'
|
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-11-13 18:12:50 +01:00
|
|
|
metaMaskFee,
|
|
|
|
savings,
|
|
|
|
isBestQuote,
|
|
|
|
numberOfQuotes,
|
|
|
|
onQuotesClick,
|
|
|
|
conversionRate,
|
|
|
|
currentCurrency,
|
|
|
|
tokenConversionRate,
|
2020-10-06 20:28:38 +02:00
|
|
|
}) {
|
2020-10-14 19:06:17 +02:00
|
|
|
const t = useContext(I18nContext)
|
|
|
|
|
2020-11-13 18:12:50 +01:00
|
|
|
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', [
|
|
|
|
<span key="savings-tilde" className="fee-card__tilde">
|
|
|
|
~
|
|
|
|
</span>,
|
|
|
|
savingAmount,
|
|
|
|
])
|
|
|
|
} else if (inDevelopment && isBestQuote && tokenConversionRate) {
|
|
|
|
savingsText = t('swapUsingBestQuote')
|
|
|
|
} else if (inDevelopment && savingsIsPositive && tokenConversionRate) {
|
|
|
|
savingsText = t('swapBetterQuoteAvailable')
|
|
|
|
}
|
|
|
|
|
2020-10-06 20:28:38 +02:00
|
|
|
return (
|
|
|
|
<div className="fee-card">
|
2020-11-13 18:12:50 +01:00
|
|
|
<div className="fee-card__savings-and-quotes-header">
|
|
|
|
<div className="fee-card__savings-and-quotes-header-first-part" />
|
|
|
|
<div
|
|
|
|
className={classnames(
|
|
|
|
'fee-card__savings-and-quotes-header-second-part',
|
|
|
|
{
|
|
|
|
'fee-card__savings-and-quotes-header-second-part--top-border': !shouldDisplaySavings,
|
|
|
|
},
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<div className="fee-card__savings-and-quotes-header-third-part" />
|
|
|
|
{shouldDisplaySavings && (
|
|
|
|
<div className="fee-card__pig-icon-container">
|
|
|
|
<PigIcon />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<div
|
|
|
|
className={classnames('fee-card__savings-and-quotes-row', {
|
|
|
|
'fee-card__savings-and-quotes-row--align-left': !shouldDisplaySavings,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
{savingsText && (
|
|
|
|
<p className="fee-card__savings-text">{savingsText}</p>
|
|
|
|
)}
|
|
|
|
<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>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-10-06 20:28:38 +02:00
|
|
|
<div className="fee-card__main">
|
|
|
|
<div className="fee-card__row-header">
|
|
|
|
<div>
|
|
|
|
<div className="fee-card__row-header-text--bold">
|
2020-10-14 19:06:17 +02:00
|
|
|
{t('swapEstimatedNetworkFee')}
|
2020-10-06 20:28:38 +02:00
|
|
|
</div>
|
2020-10-19 10:24:59 +02:00
|
|
|
<InfoTooltip
|
|
|
|
position="top"
|
2020-11-03 00:41:28 +01:00
|
|
|
contentText={
|
2020-10-19 10:24:59 +02:00
|
|
|
<>
|
2020-11-03 00:41:28 +01:00
|
|
|
<p className="fee-card__info-tooltip-paragraph">
|
|
|
|
{t('swapNetworkFeeSummary')}
|
2020-10-19 10:24:59 +02:00
|
|
|
</p>
|
2020-11-03 00:41:28 +01:00
|
|
|
<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>,
|
|
|
|
])}
|
2020-10-19 10:24:59 +02:00
|
|
|
</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>
|
|
|
|
<div>
|
|
|
|
<div className="fee-card__row-header-secondary--bold">
|
|
|
|
{primaryFee.fee}
|
|
|
|
</div>
|
|
|
|
{secondaryFee && (
|
|
|
|
<div className="fee-card__row-header-primary--bold">
|
|
|
|
{secondaryFee.fee}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-11-03 00:41:28 +01:00
|
|
|
<div
|
|
|
|
className="fee-card__row-header"
|
|
|
|
onClick={() => onFeeCardMaxRowClick()}
|
|
|
|
>
|
2020-10-06 20:28:38 +02:00
|
|
|
<div>
|
|
|
|
<div className="fee-card__row-header-text">
|
2020-10-14 19:06:17 +02:00
|
|
|
{t('swapMaxNetworkFees')}
|
2020-10-06 20:28:38 +02:00
|
|
|
</div>
|
2020-11-03 00:41:28 +01:00
|
|
|
<div className="fee-card__link">{t('edit')}</div>
|
2020-10-06 20:28:38 +02:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div className="fee-card__row-header-secondary">
|
|
|
|
{primaryFee.maxFee}
|
|
|
|
</div>
|
|
|
|
{secondaryFee?.maxFee !== undefined && (
|
|
|
|
<div className="fee-card__row-header-primary">
|
|
|
|
{secondaryFee.maxFee}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-10-14 19:06:17 +02:00
|
|
|
{!hideTokenApprovalRow && (
|
2020-11-13 18:12:50 +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-11-13 18:12:50 +01:00
|
|
|
containerClassName="fee-card__info-tooltip-container"
|
2020-10-06 20:28:38 +02:00
|
|
|
/>
|
|
|
|
</div>
|
2020-11-13 18:12:50 +01:00
|
|
|
<div
|
|
|
|
className="fee-card__link"
|
|
|
|
onClick={() => onTokenApprovalClick()}
|
|
|
|
>
|
|
|
|
{t('swapEditLimit')}
|
|
|
|
</div>
|
2020-10-06 20:28:38 +02:00
|
|
|
</div>
|
|
|
|
)}
|
2020-11-13 18:12:50 +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>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
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-11-13 18:12:50 +01:00
|
|
|
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,
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|