Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
1104/fix issue with small usd amounts again (#1126)
Browse files Browse the repository at this point in the history
* Using token decimal precision instead of arbitrary value

* Removing MAX_PRECISION constant

* Tiny doc string fix

Co-authored-by: Anxo Rodriguez <[email protected]>
Co-authored-by: Leandro Boscariol <[email protected]>
  • Loading branch information
3 people authored Jul 30, 2021
1 parent 3ef8286 commit b11f385
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/custom/components/swap/TradePrice/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import TradePriceMod, { TradePriceProps } from './TradePriceMod'
import { useUSDCValue } from 'hooks/useUSDCPrice'
import { formatSmart } from 'utils/format'
import { tryParseAmount } from 'state/swap/hooks'
import { FIAT_FORMAT_SMART_OPTIONS, MAX_PRECISION } from 'constants/index'
import { FIAT_FORMAT_SMART_OPTIONS } from 'constants/index'

export * from './TradePriceMod'

Expand All @@ -13,8 +13,8 @@ export default function TradePrice(props: Omit<TradePriceProps, 'fiatValue'>) {
const priceSide = useMemo(
() =>
!showInverted
? tryParseAmount(price.invert().toFixed(MAX_PRECISION), price.baseCurrency)
: tryParseAmount(price.toFixed(MAX_PRECISION), price.quoteCurrency),
? tryParseAmount(price.invert().toFixed(price.baseCurrency.decimals), price.baseCurrency)
: tryParseAmount(price.toFixed(price.quoteCurrency.decimals), price.quoteCurrency),
[price, showInverted]
)
const amount = useUSDCValue(priceSide)
Expand Down
1 change: 0 additions & 1 deletion src/custom/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const DEFAULT_DECIMALS = 18
export const DEFAULT_PRECISION = 6
export const SHORT_PRECISION = 4
export const SHORTEST_PRECISION = 3
export const MAX_PRECISION = 18
export const LONG_PRECISION = 10
export const FIAT_PRECISION = 2
export const PERCENTAGE_PRECISION = 2
Expand Down
2 changes: 1 addition & 1 deletion src/custom/hooks/useUSDCPrice/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default function useUSDCPrice(currency?: Currency) {

/**
* Returns the price in USDC of the input currency from price APIs
* @param currency currency to compute the USDC price of
* @param currencyAmount currency to compute the USDC price of
*/
export function useUSDCValue(currencyAmount?: CurrencyAmount<Currency>) {
const { price, error } = useUSDCPrice(currencyAmount?.currency)
Expand Down

0 comments on commit b11f385

Please sign in to comment.