diff --git a/components/DayHighLow.tsx b/components/DayHighLow.tsx index b6b3b344..eb844737 100644 --- a/components/DayHighLow.tsx +++ b/components/DayHighLow.tsx @@ -1,18 +1,24 @@ +import useOraclePrice from '../hooks/useOraclePrice' import { formatUsdValue } from '../utils' import { MarketDataLoader } from './MarketDetails' interface DayHighLowProps { high: number low: number - latest: number isTableView?: boolean } -const DayHighLow = ({ high, low, latest, isTableView }: DayHighLowProps) => { +const DayHighLow = ({ high, low, isTableView }: DayHighLowProps) => { + const price = useOraclePrice() let rangePercent = 0 + let latestPrice = 0 + + if (price) { + latestPrice = price?.toNumber() + } if (high) { - rangePercent = ((latest - low) * 100) / (high - low) + rangePercent = ((latestPrice - low) * 100) / (high - low) } return ( diff --git a/components/MarketDetails.tsx b/components/MarketDetails.tsx index 87b273cd..ae85f1d9 100644 --- a/components/MarketDetails.tsx +++ b/components/MarketDetails.tsx @@ -15,11 +15,30 @@ import { useTranslation } from 'next-i18next' import SwitchMarketDropdown from './SwitchMarketDropdown' import Tooltip from './Tooltip' +const OraclePrice = () => { + const oraclePrice = useOraclePrice() + const selectedMarket = useMangoStore((s) => s.selectedMarket.current) + + const decimals = useMemo( + () => getPrecisionDigits(selectedMarket?.tickSize), + [selectedMarket] + ) + + return ( +
+ {oraclePrice && selectedMarket + ? oraclePrice.toNumber().toLocaleString(undefined, { + minimumFractionDigits: decimals, + maximumFractionDigits: decimals, + }) + : '--'} +
+ ) +} + const MarketDetails = () => { const { t } = useTranslation('common') - const oraclePrice = useOraclePrice() const marketConfig = useMangoStore((s) => s.selectedMarket.config) - const selectedMarket = useMangoStore((s) => s.selectedMarket.current) const baseSymbol = marketConfig.baseSymbol const selectedMarketName = marketConfig.name const isPerpMarket = marketConfig.kind === 'perp' @@ -50,18 +69,7 @@ const MarketDetails = () => {
{t('oracle-price')}
-
- {oraclePrice && selectedMarket - ? oraclePrice.toNumber().toLocaleString(undefined, { - minimumFractionDigits: getPrecisionDigits( - selectedMarket.tickSize - ), - maximumFractionDigits: getPrecisionDigits( - selectedMarket.tickSize - ), - }) - : '--'} -
+ {market ? ( <> @@ -125,11 +133,7 @@ const MarketDetails = () => {
{t('daily-range')}
- + ) : (