1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

format quotes consistently on main-view and list-view (#9495)

This commit is contained in:
Brad Decker 2020-10-06 19:37:38 -05:00 committed by GitHub
parent 534ac25a93
commit 1ba4061f46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 6 deletions

View File

@ -8,6 +8,7 @@ import { toPrecisionWithoutTrailingZeros } from '../../../helpers/utils/util'
import Tooltip from '../../../components/ui/tooltip'
import SunCheckIcon from '../../../components/ui/icon/sun-check-icon.component'
import ExchangeRateDisplay from '../exchange-rate-display'
import { formatSwapsValueForDisplay } from '../swaps.util'
import QuoteBackdrop from './quote-backdrop'
function getFontSizes (fontSizeScore) {
@ -60,10 +61,7 @@ export default function MainQuoteSummary ({
const sourceAmount = toPrecisionWithoutTrailingZeros(calcTokenAmount(sourceValue, sourceDecimals).toString(10), 12)
const destinationAmount = calcTokenAmount(destinationValue, destinationDecimals)
let amountToDisplay = toPrecisionWithoutTrailingZeros(destinationAmount, 12)
if (amountToDisplay.match(/e[+-]/u)) {
amountToDisplay = (new BigNumber(amountToDisplay)).toFixed()
}
const amountToDisplay = formatSwapsValueForDisplay(destinationAmount)
const fontSizeScore = getFontSizeScore(amountToDisplay, destinationSymbol)
const [numberFontSize, symbolFontSize] = getFontSizes(fontSizeScore)
const lineHeight = getLineHeight(fontSizeScore)

View File

@ -122,7 +122,7 @@ export default function SortList ({
>
<div className="select-quote-popover__receiving-value">
{isBestQuote && <SunCheckIcon reverseColors={selectedRow !== i} />}
<div className="select-quote-popover__receiving-value-text">{destinationTokenValue}</div>
<div className="select-quote-popover__receiving-value-text" title={destinationTokenValue}>{destinationTokenValue}</div>
</div>
{ quoteSource === 'RFQ' && <span className="select-quote-popover__zero-slippage">{t('swapZeroSlippage')}</span> }
</div>

View File

@ -345,7 +345,7 @@ export function quotesToRenderableData (quotes, gasPrice, conversionRate, curren
amountReceiving: `${destinationValue} ${destinationTokenInfo.symbol}`,
destinationTokenDecimals: destinationTokenInfo.decimals,
destinationTokenSymbol: destinationTokenInfo.symbol,
destinationTokenValue: destinationValue,
destinationTokenValue: formatSwapsValueForDisplay(destinationValue),
isBestQuote: quote.isBestQuote,
liquiditySourceKey,
metaMaskFee,
@ -402,3 +402,11 @@ export function getSwapsTokensReceivedFromTxMeta (tokenSymbol, txMeta, tokenAddr
}
return null
}
export function formatSwapsValueForDisplay (destinationAmount) {
let amountToDisplay = toPrecisionWithoutTrailingZeros(destinationAmount, 12)
if (amountToDisplay.match(/e[+-]/u)) {
amountToDisplay = (new BigNumber(amountToDisplay)).toFixed()
}
return amountToDisplay
}