Commit 251339a9 authored by Tott0's avatar Tott0 Committed by GitHub

feat: changes usdcPrice formatting to fixed decimals (#3849)

* change usdcPrice in swap modal to use fixed decimals instead of significant formatting

* change text for fiatValue as well

* change decimal points condition to 1.05

* (m) missed one value
parent 148e415f
......@@ -27,13 +27,16 @@ export function FiatValue({
return theme.red1
}, [priceImpact, theme.green1, theme.red1, theme.text3, theme.yellow1])
const p = Number(fiatValue?.toFixed())
const visibleDecimalPlaces = p < 1.05 ? 4 : 2
return (
<ThemedText.Body fontSize={14} color={fiatValue ? theme.text3 : theme.text4}>
{fiatValue ? (
<Trans>
$
<HoverInlineText
text={fiatValue?.toSignificant(6, { groupSeparator: ',' })}
text={fiatValue?.toFixed(visibleDecimalPlaces, { groupSeparator: ',' })}
textColor={fiatValue ? theme.text3 : theme.text4}
/>
</Trans>
......
......@@ -33,6 +33,11 @@ export default function TradePrice({ price, showInverted, setShowInverted }: Tra
const theme = useContext(ThemeContext)
const usdcPrice = useUSDCPrice(showInverted ? price.baseCurrency : price.quoteCurrency)
/*
* calculate needed amount of decimal prices, for prices between 0.95-1.05 use 4 decimal places
*/
const p = Number(usdcPrice?.toFixed())
const visibleDecimalPlaces = p < 1.05 ? 4 : 2
let formattedPrice: string
try {
......@@ -60,7 +65,7 @@ export default function TradePrice({ price, showInverted, setShowInverted }: Tra
</Text>{' '}
{usdcPrice && (
<ThemedText.DarkGray>
<Trans>(${usdcPrice.toSignificant(6, { groupSeparator: ',' })})</Trans>
<Trans>(${usdcPrice.toFixed(visibleDecimalPlaces, { groupSeparator: ',' })})</Trans>
</ThemedText.DarkGray>
)}
</StyledPriceContainer>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment