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
This commit is contained in:
Tott0 2022-05-23 13:47:18 -05:00 committed by GitHub
parent 148e415fe8
commit 251339a9ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

@ -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>