2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import BigNumber from 'bignumber.js';
|
|
|
|
import Tooltip from '../../../components/ui/tooltip';
|
|
|
|
import UrlIcon from '../../../components/ui/url-icon';
|
|
|
|
import ExchangeRateDisplay from '../exchange-rate-display';
|
|
|
|
import { formatSwapsValueForDisplay } from '../swaps.util';
|
2022-09-16 21:05:21 +02:00
|
|
|
import {
|
|
|
|
calcTokenAmount,
|
|
|
|
toPrecisionWithoutTrailingZeros,
|
|
|
|
} from '../../../../shared/lib/transactions-controller-utils';
|
2020-10-06 20:28:38 +02:00
|
|
|
|
2020-12-08 17:47:53 +01:00
|
|
|
function getFontSizesAndLineHeights(fontSizeScore) {
|
|
|
|
if (fontSizeScore <= 9) {
|
2021-12-07 04:51:26 +01:00
|
|
|
return [50, 48];
|
2020-11-19 02:40:24 +01:00
|
|
|
}
|
2020-12-08 17:47:53 +01:00
|
|
|
if (fontSizeScore <= 13) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return [40, 32];
|
2020-11-19 02:40:24 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
return [26, 15];
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export default function MainQuoteSummary({
|
2020-10-06 20:28:38 +02:00
|
|
|
sourceValue,
|
|
|
|
sourceSymbol,
|
|
|
|
sourceDecimals,
|
2020-12-08 17:47:53 +01:00
|
|
|
sourceIconUrl,
|
2020-10-06 20:28:38 +02:00
|
|
|
destinationValue,
|
|
|
|
destinationSymbol,
|
|
|
|
destinationDecimals,
|
2020-12-08 17:47:53 +01:00
|
|
|
destinationIconUrl,
|
2020-10-06 20:28:38 +02:00
|
|
|
}) {
|
2020-11-03 00:41:28 +01:00
|
|
|
const sourceAmount = toPrecisionWithoutTrailingZeros(
|
|
|
|
calcTokenAmount(sourceValue, sourceDecimals).toString(10),
|
|
|
|
12,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const destinationAmount = calcTokenAmount(
|
|
|
|
destinationValue,
|
|
|
|
destinationDecimals,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-06 20:28:38 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const amountToDisplay = formatSwapsValueForDisplay(destinationAmount);
|
|
|
|
const amountDigitLength = amountToDisplay.match(/\d+/gu).join('').length;
|
2022-07-31 20:26:40 +02:00
|
|
|
const [numberFontSize, lineHeight] =
|
|
|
|
getFontSizesAndLineHeights(amountDigitLength);
|
2021-02-04 19:15:23 +01:00
|
|
|
let ellipsedAmountToDisplay = amountToDisplay;
|
2020-12-08 17:47:53 +01:00
|
|
|
|
|
|
|
if (amountDigitLength > 20) {
|
2021-02-04 19:15:23 +01:00
|
|
|
ellipsedAmountToDisplay = `${amountToDisplay.slice(0, 20)}...`;
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="main-quote-summary">
|
|
|
|
<div className="main-quote-summary__details">
|
|
|
|
<div className="main-quote-summary__quote-details-top">
|
2021-07-02 15:48:34 +02:00
|
|
|
<div
|
|
|
|
className="main-quote-summary__source-row"
|
|
|
|
data-testid="main-quote-summary__source-row"
|
|
|
|
>
|
2020-12-08 17:47:53 +01:00
|
|
|
<span
|
|
|
|
className="main-quote-summary__source-row-value"
|
|
|
|
title={formatSwapsValueForDisplay(sourceAmount)}
|
|
|
|
>
|
|
|
|
{formatSwapsValueForDisplay(sourceAmount)}
|
|
|
|
</span>
|
|
|
|
<UrlIcon
|
|
|
|
url={sourceIconUrl}
|
|
|
|
className="main-quote-summary__icon"
|
|
|
|
name={sourceSymbol}
|
|
|
|
fallbackClassName="main-quote-summary__icon-fallback"
|
|
|
|
/>
|
|
|
|
<span
|
|
|
|
className="main-quote-summary__source-row-symbol"
|
|
|
|
title={sourceSymbol}
|
|
|
|
>
|
|
|
|
{sourceSymbol}
|
|
|
|
</span>
|
|
|
|
</div>
|
2022-03-23 16:25:28 +01:00
|
|
|
<i className="fa fa-arrow-down main-quote-summary__down-arrow" />
|
2020-12-08 17:47:53 +01:00
|
|
|
<div className="main-quote-summary__destination-row">
|
|
|
|
<UrlIcon
|
|
|
|
url={destinationIconUrl}
|
|
|
|
className="main-quote-summary__icon"
|
|
|
|
name={destinationSymbol}
|
|
|
|
fallbackClassName="main-quote-summary__icon-fallback"
|
|
|
|
/>
|
|
|
|
<span className="main-quote-summary__destination-row-symbol">
|
|
|
|
{destinationSymbol}
|
|
|
|
</span>
|
|
|
|
</div>
|
2020-10-06 20:28:38 +02:00
|
|
|
<div className="main-quote-summary__quote-large">
|
|
|
|
<Tooltip
|
|
|
|
interactive
|
|
|
|
position="bottom"
|
|
|
|
html={amountToDisplay}
|
|
|
|
disabled={ellipsedAmountToDisplay === amountToDisplay}
|
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
<span
|
|
|
|
className="main-quote-summary__quote-large-number"
|
|
|
|
style={{
|
|
|
|
fontSize: numberFontSize,
|
|
|
|
lineHeight: `${lineHeight}px`,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{`${ellipsedAmountToDisplay}`}
|
|
|
|
</span>
|
2020-10-06 20:28:38 +02:00
|
|
|
</Tooltip>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-07-02 15:48:34 +02:00
|
|
|
<div
|
|
|
|
className="main-quote-summary__exchange-rate-container"
|
|
|
|
data-testid="main-quote-summary__exchange-rate-container"
|
|
|
|
>
|
2020-10-06 20:28:38 +02:00
|
|
|
<ExchangeRateDisplay
|
|
|
|
primaryTokenValue={sourceValue}
|
|
|
|
primaryTokenDecimals={sourceDecimals}
|
|
|
|
primaryTokenSymbol={sourceSymbol}
|
|
|
|
secondaryTokenValue={destinationValue}
|
|
|
|
secondaryTokenDecimals={destinationDecimals}
|
|
|
|
secondaryTokenSymbol={destinationSymbol}
|
2022-03-25 23:15:31 +01:00
|
|
|
arrowColor="var(--color-primary-default)"
|
2020-12-08 17:47:53 +01:00
|
|
|
boldSymbols={false}
|
|
|
|
className="main-quote-summary__exchange-rate-display"
|
2020-10-06 20:28:38 +02:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MainQuoteSummary.propTypes = {
|
2022-06-15 17:43:26 +02:00
|
|
|
/**
|
|
|
|
* The amount that will be sent in the smallest denomination.
|
|
|
|
* For example, wei is the smallest denomination for ether.
|
|
|
|
*/
|
2020-10-06 20:28:38 +02:00
|
|
|
sourceValue: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
|
|
|
PropTypes.instanceOf(BigNumber),
|
|
|
|
]).isRequired,
|
2022-06-15 17:43:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Maximum number of decimal places for the source token.
|
|
|
|
*/
|
2020-10-06 20:28:38 +02:00
|
|
|
sourceDecimals: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
2022-06-15 17:43:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The ticker symbol for the source token.
|
|
|
|
*/
|
2020-10-06 20:28:38 +02:00
|
|
|
sourceSymbol: PropTypes.string.isRequired,
|
2022-06-15 17:43:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The amount that will be received in the smallest denomination.
|
|
|
|
* For example, wei is the smallest denomination for ether.
|
|
|
|
*/
|
2020-10-06 20:28:38 +02:00
|
|
|
destinationValue: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
|
|
|
PropTypes.instanceOf(BigNumber),
|
|
|
|
]).isRequired,
|
2022-06-15 17:43:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Maximum number of decimal places for the destination token.
|
|
|
|
*/
|
2020-11-03 00:41:28 +01:00
|
|
|
destinationDecimals: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
|
|
|
PropTypes.number,
|
|
|
|
]),
|
2022-06-15 17:43:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The ticker symbol for the destination token.
|
|
|
|
*/
|
2020-10-06 20:28:38 +02:00
|
|
|
destinationSymbol: PropTypes.string.isRequired,
|
2022-06-15 17:43:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The location of the source token icon file.
|
|
|
|
*/
|
2020-12-08 17:47:53 +01:00
|
|
|
sourceIconUrl: PropTypes.string,
|
2022-06-15 17:43:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The location of the destination token icon file.
|
|
|
|
*/
|
2020-12-08 17:47:53 +01:00
|
|
|
destinationIconUrl: PropTypes.string,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|