1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-18 15:33:21 +01:00
metamask-extension/ui/app/pages/swaps/fee-card/fee-card.js

126 lines
4.0 KiB
JavaScript
Raw Normal View History

import React, { useContext } from 'react'
2020-10-06 20:28:38 +02:00
import PropTypes from 'prop-types'
import { I18nContext } from '../../../contexts/i18n'
2020-10-06 20:28:38 +02:00
import InfoTooltip from '../../../components/ui/info-tooltip'
2020-11-03 00:41:28 +01:00
export default function FeeCard({
2020-10-06 20:28:38 +02:00
primaryFee,
secondaryFee,
hideTokenApprovalRow,
onFeeCardMaxRowClick,
tokenApprovalTextComponent,
2020-10-14 19:12:35 +02:00
tokenApprovalSourceTokenSymbol,
onTokenApprovalClick,
2020-10-06 20:28:38 +02:00
}) {
const t = useContext(I18nContext)
2020-10-06 20:28:38 +02:00
return (
<div className="fee-card">
<div className="fee-card__main">
<div className="fee-card__row-header">
<div>
<div className="fee-card__row-header-text--bold">
{t('swapEstimatedNetworkFee')}
2020-10-06 20:28:38 +02:00
</div>
<InfoTooltip
position="top"
2020-11-03 00:41:28 +01:00
contentText={
<>
2020-11-03 00:41:28 +01:00
<p className="fee-card__info-tooltip-paragraph">
{t('swapNetworkFeeSummary')}
</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>,
])}
</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">
{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>
{!hideTokenApprovalRow && (
2020-10-06 20:28:38 +02:00
<div className="fee-card__top-bordered-row">
<div className="fee-card__row-label">
<div className="fee-card__row-header-text">
{t('swapThisWillAllowApprove', [tokenApprovalTextComponent])}
2020-10-06 20:28:38 +02:00
</div>
2020-11-03 00:41:28 +01:00
<div
className="fee-card__link"
onClick={() => onTokenApprovalClick()}
>
{t('swapEditLimit')}
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-10-06 20:28:38 +02:00
/>
</div>
</div>
)}
</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,
}),
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-10-06 20:28:38 +02:00
}