You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
3.4 KiB
106 lines
3.4 KiB
4 years ago
|
import React, { useContext } from 'react';
|
||
4 years ago
|
|
||
4 years ago
|
import PropTypes from 'prop-types';
|
||
|
import classnames from 'classnames';
|
||
|
import { I18nContext } from '../../../contexts/i18n';
|
||
4 years ago
|
|
||
4 years ago
|
import ActionableMessage from '../actionable-message';
|
||
|
import Tooltip from '../../../components/ui/tooltip';
|
||
4 years ago
|
|
||
|
export default function ViewQuotePriceDifference(props) {
|
||
4 years ago
|
const {
|
||
|
usedQuote,
|
||
|
sourceTokenValue,
|
||
|
destinationTokenValue,
|
||
|
onAcknowledgementClick,
|
||
|
acknowledged,
|
||
|
priceSlippageFromSource,
|
||
|
priceSlippageFromDestination,
|
||
|
priceDifferencePercentage,
|
||
|
priceSlippageUnknownFiatValue,
|
||
4 years ago
|
} = props;
|
||
4 years ago
|
|
||
4 years ago
|
const t = useContext(I18nContext);
|
||
4 years ago
|
|
||
4 years ago
|
let priceDifferenceTitle = '';
|
||
|
let priceDifferenceMessage = '';
|
||
|
let priceDifferenceClass = '';
|
||
|
let priceDifferenceAcknowledgementText = '';
|
||
4 years ago
|
if (priceSlippageUnknownFiatValue) {
|
||
|
// A calculation error signals we cannot determine dollar value
|
||
4 years ago
|
priceDifferenceMessage = t('swapPriceDifferenceUnavailable');
|
||
|
priceDifferenceClass = 'fiat-error';
|
||
4 years ago
|
priceDifferenceAcknowledgementText = t('continue');
|
||
4 years ago
|
} else {
|
||
|
priceDifferenceTitle = t('swapPriceDifferenceTitle', [
|
||
|
priceDifferencePercentage,
|
||
4 years ago
|
]);
|
||
4 years ago
|
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
|
||
4 years ago
|
]);
|
||
|
priceDifferenceClass = usedQuote.priceSlippage.bucket;
|
||
|
priceDifferenceAcknowledgementText = t(
|
||
|
'swapPriceDifferenceAcknowledgement',
|
||
|
);
|
||
4 years ago
|
}
|
||
|
|
||
|
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">
|
||
|
{priceDifferenceTitle && (
|
||
|
<div className="view-quote__price-difference-warning-contents-title">
|
||
|
{priceDifferenceTitle}
|
||
|
</div>
|
||
|
)}
|
||
|
{priceDifferenceMessage}
|
||
4 years ago
|
{!acknowledged && (
|
||
|
<div className="view-quote__price-difference-warning-contents-actions">
|
||
|
<button
|
||
|
onClick={() => {
|
||
4 years ago
|
onAcknowledgementClick();
|
||
4 years ago
|
}}
|
||
|
>
|
||
|
{priceDifferenceAcknowledgementText}
|
||
|
</button>
|
||
|
</div>
|
||
|
)}
|
||
4 years ago
|
</div>
|
||
|
<Tooltip
|
||
|
position="bottom"
|
||
|
theme="white"
|
||
|
title={t('swapPriceDifferenceTooltip')}
|
||
|
>
|
||
|
<i className="fa fa-info-circle" />
|
||
|
</Tooltip>
|
||
|
</div>
|
||
|
}
|
||
|
/>
|
||
|
</div>
|
||
4 years ago
|
);
|
||
4 years ago
|
}
|
||
|
|
||
|
ViewQuotePriceDifference.propTypes = {
|
||
|
usedQuote: PropTypes.object,
|
||
|
sourceTokenValue: PropTypes.string,
|
||
|
destinationTokenValue: PropTypes.string,
|
||
4 years ago
|
onAcknowledgementClick: PropTypes.func,
|
||
|
acknowledged: PropTypes.bool,
|
||
|
priceSlippageFromSource: PropTypes.string,
|
||
|
priceSlippageFromDestination: PropTypes.string,
|
||
|
priceDifferencePercentage: PropTypes.number,
|
||
|
priceSlippageUnknownFiatValue: PropTypes.bool,
|
||
4 years ago
|
};
|