diff --git a/src/pages/trade/ui/route-book.tsx b/src/pages/trade/ui/route-book.tsx index 1c1ce9e3..a632d450 100644 --- a/src/pages/trade/ui/route-book.tsx +++ b/src/pages/trade/ui/route-book.tsx @@ -5,35 +5,49 @@ import { RouteBookResponse, Trace } from '@/shared/api/server/book/types'; import { usePathSymbols } from '@/pages/trade/model/use-path.ts'; import { calculateSpread } from '@/pages/trade/model/trace.ts'; import { TradeRow } from '@/pages/trade/ui/trade-row.tsx'; +import { Skeleton } from '@/shared/ui/skeleton'; const SkeletonRow = (props: { isSpread: boolean }) => props.isSpread ? (
-
- -
- -
- -
+
+ +
+
+ +
+
+ +
+
+ +
) : ( - -
+ +
+ +
- -
+ +
+ +
- -
+ +
+ +
- -
+ +
+ +
); @@ -49,10 +63,10 @@ const RouteBookData = observer(({ bookData }: { bookData?: RouteBookResponse }) - - - - + + + + @@ -99,6 +113,22 @@ export const RouteBook = observer(() => { return ; }); +function formatPrice(price: string): string { + const num = parseFloat(price); + const [whole] = num.toString().split('.'); + const totalDigits = 7; + const availableDecimals = Math.max(0, totalDigits - (whole?.length ?? 0)); + return num.toFixed(availableDecimals); +} + +function formatNumber(value: string): string { + const num = parseFloat(value); + const [whole] = num.toString().split('.'); + const totalDigits = 6; + const availableDecimals = Math.max(0, totalDigits - (whole?.length ?? 0)); + return num.toFixed(availableDecimals); +} + const SpreadRow = ({ sellOrders, buyOrders }: { sellOrders: Trace[]; buyOrders: Trace[] }) => { const spreadInfo = calculateSpread(sellOrders, buyOrders); const pair = usePathSymbols(); @@ -111,12 +141,12 @@ const SpreadRow = ({ sellOrders, buyOrders }: { sellOrders: Trace[]; buyOrders: diff --git a/src/pages/trade/ui/trade-row.tsx b/src/pages/trade/ui/trade-row.tsx index a63a1492..cbb64f81 100644 --- a/src/pages/trade/ui/trade-row.tsx +++ b/src/pages/trade/ui/trade-row.tsx @@ -3,11 +3,22 @@ import { getSymbolFromValueView } from '@penumbra-zone/getters/value-view'; import React from 'react'; import { ChevronRight } from 'lucide-react'; -function padPrice(price: string): string { - const [whole, decimal = ''] = price.split('.'); - const maxDigits = 8; // Maximum decimals commonly used for crypto prices - const paddedDecimal = decimal.padEnd(maxDigits, '0'); - return `${whole}.${paddedDecimal}`; +function formatPrice(price: string): string { + const num = parseFloat(price); + const parts = num.toString().split('.'); + const whole = parts[0] ?? '0'; + const totalDigits = 7; + const availableDecimals = Math.max(0, totalDigits - whole.length); + return num.toFixed(availableDecimals); +} + +function formatNumber(value: string): string { + const num = parseFloat(value); + const parts = num.toString().split('.'); + const whole = parts[0] ?? '0'; + const totalDigits = 6; + const availableDecimals = Math.max(0, totalDigits - whole.length); + return num.toFixed(availableDecimals); } const SELL_BG_COLOR = 'rgba(175, 38, 38, 0.24)'; @@ -21,7 +32,6 @@ export const TradeRow = ({ relativeSize: number; }) => { const bgColor = isSell ? SELL_BG_COLOR : 'rgba(28, 121, 63, 0.24)'; - const paddedPrice = padPrice(trace.price); return ( - - + +
Price({pair.quoteSymbol})Amount({pair.baseSymbol})TotalRoutePrice({pair.quoteSymbol})Amount({pair.baseSymbol})TotalRoute
- {parseFloat(spreadInfo.midPrice)} + {formatPrice(spreadInfo.midPrice)} Spread: - {parseFloat(spreadInfo.amount)} {pair.quoteSymbol} + {formatNumber(spreadInfo.amount)} {pair.quoteSymbol} - ({spreadInfo.percentage}%) + ({parseFloat(spreadInfo.percentage).toFixed(2)}%)
- {paddedPrice} + {formatPrice(trace.price)} {trace.amount}{trace.total}{formatNumber(trace.amount)}{formatNumber(trace.total)}