2021-02-04 19:15:23 +01:00
|
|
|
import React, { useContext } from 'react';
|
2020-12-02 22:27:45 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import { I18nContext } from '../../../contexts/i18n';
|
2020-12-02 22:27:45 +01:00
|
|
|
|
2021-07-02 21:07:56 +02:00
|
|
|
import ActionableMessage from '../../../components/ui/actionable-message/actionable-message';
|
2021-02-04 19:15:23 +01:00
|
|
|
import Tooltip from '../../../components/ui/tooltip';
|
2021-05-21 19:02:23 +02:00
|
|
|
import Box from '../../../components/ui/box';
|
|
|
|
import {
|
|
|
|
JUSTIFY_CONTENT,
|
|
|
|
DISPLAY,
|
|
|
|
} from '../../../helpers/constants/design-system';
|
2021-11-06 01:59:23 +01:00
|
|
|
import { GAS_RECOMMENDATIONS } from '../../../../shared/constants/gas';
|
2020-12-02 22:27:45 +01:00
|
|
|
|
|
|
|
export default function ViewQuotePriceDifference(props) {
|
2021-02-04 16:58:46 +01:00
|
|
|
const {
|
|
|
|
usedQuote,
|
|
|
|
sourceTokenValue,
|
|
|
|
destinationTokenValue,
|
|
|
|
onAcknowledgementClick,
|
|
|
|
acknowledged,
|
|
|
|
priceSlippageFromSource,
|
|
|
|
priceSlippageFromDestination,
|
|
|
|
priceDifferencePercentage,
|
|
|
|
priceSlippageUnknownFiatValue,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = props;
|
2020-12-02 22:27:45 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const t = useContext(I18nContext);
|
2020-12-02 22:27:45 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let priceDifferenceTitle = '';
|
|
|
|
let priceDifferenceMessage = '';
|
|
|
|
let priceDifferenceClass = '';
|
|
|
|
let priceDifferenceAcknowledgementText = '';
|
2020-12-02 22:27:45 +01:00
|
|
|
if (priceSlippageUnknownFiatValue) {
|
|
|
|
// A calculation error signals we cannot determine dollar value
|
2021-05-21 19:02:23 +02:00
|
|
|
priceDifferenceTitle = t('swapPriceUnavailableTitle');
|
|
|
|
priceDifferenceMessage = t('swapPriceUnavailableDescription');
|
2021-11-06 01:59:23 +01:00
|
|
|
priceDifferenceClass = GAS_RECOMMENDATIONS.HIGH;
|
2021-05-21 19:02:23 +02:00
|
|
|
priceDifferenceAcknowledgementText = t('tooltipApproveButton');
|
2020-12-02 22:27:45 +01:00
|
|
|
} else {
|
|
|
|
priceDifferenceTitle = t('swapPriceDifferenceTitle', [
|
|
|
|
priceDifferencePercentage,
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
2020-12-02 22:27:45 +01:00
|
|
|
priceDifferenceMessage = t('swapPriceDifference', [
|
|
|
|
sourceTokenValue, // Number of source token to swap
|
|
|
|
usedQuote.sourceTokenInfo.symbol, // Source token symbol
|
|
|
|
priceSlippageFromSource, // Source tokens total value
|
|
|
|
destinationTokenValue, // Number of destination tokens in return
|
|
|
|
usedQuote.destinationTokenInfo.symbol, // Destination token symbol,
|
|
|
|
priceSlippageFromDestination, // Destination tokens total value
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
priceDifferenceClass = usedQuote.priceSlippage.bucket;
|
2021-05-21 19:02:23 +02:00
|
|
|
priceDifferenceAcknowledgementText = t('tooltipApproveButton');
|
2020-12-02 22:27:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={classnames(
|
|
|
|
'view-quote__price-difference-warning-wrapper',
|
|
|
|
priceDifferenceClass,
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<ActionableMessage
|
|
|
|
message={
|
|
|
|
<div className="view-quote__price-difference-warning-contents">
|
|
|
|
<div className="view-quote__price-difference-warning-contents-text">
|
2021-05-21 19:02:23 +02:00
|
|
|
<Box
|
|
|
|
display={DISPLAY.FLEX}
|
|
|
|
justifyContent={JUSTIFY_CONTENT.SPACE_BETWEEN}
|
|
|
|
paddingBottom={2}
|
|
|
|
>
|
2020-12-02 22:27:45 +01:00
|
|
|
<div className="view-quote__price-difference-warning-contents-title">
|
|
|
|
{priceDifferenceTitle}
|
|
|
|
</div>
|
2021-05-21 19:02:23 +02:00
|
|
|
<Tooltip
|
|
|
|
position="bottom"
|
|
|
|
theme="white"
|
|
|
|
title={t('swapPriceImpactTooltip')}
|
|
|
|
>
|
|
|
|
<i className="fa fa-info-circle" />
|
|
|
|
</Tooltip>
|
|
|
|
</Box>
|
2020-12-02 22:27:45 +01:00
|
|
|
{priceDifferenceMessage}
|
2021-02-04 16:58:46 +01:00
|
|
|
{!acknowledged && (
|
|
|
|
<div className="view-quote__price-difference-warning-contents-actions">
|
|
|
|
<button
|
|
|
|
onClick={() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
onAcknowledgementClick();
|
2021-02-04 16:58:46 +01:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{priceDifferenceAcknowledgementText}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
)}
|
2020-12-02 22:27:45 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-12-02 22:27:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ViewQuotePriceDifference.propTypes = {
|
|
|
|
usedQuote: PropTypes.object,
|
|
|
|
sourceTokenValue: PropTypes.string,
|
|
|
|
destinationTokenValue: PropTypes.string,
|
2021-02-04 16:58:46 +01:00
|
|
|
onAcknowledgementClick: PropTypes.func,
|
|
|
|
acknowledged: PropTypes.bool,
|
|
|
|
priceSlippageFromSource: PropTypes.string,
|
|
|
|
priceSlippageFromDestination: PropTypes.string,
|
|
|
|
priceDifferencePercentage: PropTypes.number,
|
|
|
|
priceSlippageUnknownFiatValue: PropTypes.bool,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|