diff --git a/src/pages/trade/ui/route-book.tsx b/src/pages/trade/ui/route-book.tsx index 77112bb3..69efef25 100644 --- a/src/pages/trade/ui/route-book.tsx +++ b/src/pages/trade/ui/route-book.tsx @@ -5,37 +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 ? ( - - -
-
- -
- -
- -
+
+
+
+ +
+
+ +
+
+ +
+
+
- - +
+
) : ( - - -
- - -
- - -
- - -
- - +
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
); const RouteBookData = observer(({ bookData }: { bookData?: RouteBookResponse }) => { @@ -46,17 +58,17 @@ const RouteBookData = observer(({ bookData }: { bookData?: RouteBookResponse }) const buyRelativeSizes = calculateRelativeSizes(multiHops?.buy ?? []); return ( - - - - - - - - - - - +
+ {/* Header */} +
+
Price({pair.quoteSymbol})
+
Amount({pair.baseSymbol})
+
Total
+
Route
+
+ + {/* Body */} +
{multiHops ? ( <> {multiHops.sell.map((trace, idx) => ( @@ -84,8 +96,8 @@ const RouteBookData = observer(({ bookData }: { bookData?: RouteBookResponse }) .fill(1) .map((_, i) => ) )} -
-
Price({pair.quoteSymbol})Amount({pair.baseSymbol})TotalRoute
+
+ ); }); @@ -99,27 +111,41 @@ 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(); if (!spreadInfo) { - return; + return null; } return ( - - -
- {parseFloat(spreadInfo.midPrice)} - Spread: - - {parseFloat(spreadInfo.amount)} {pair.quoteSymbol} - - ({spreadInfo.percentage}%) -
- - +
+
+ {formatPrice(spreadInfo.midPrice)} + Spread: + + {formatNumber(spreadInfo.amount)} {pair.quoteSymbol} + + ({parseFloat(spreadInfo.percentage).toFixed(2)}%) +
+
); }; diff --git a/src/pages/trade/ui/route-tabs.tsx b/src/pages/trade/ui/route-tabs.tsx index c307b54e..b879ca77 100644 --- a/src/pages/trade/ui/route-tabs.tsx +++ b/src/pages/trade/ui/route-tabs.tsx @@ -15,7 +15,7 @@ export const RouteTabs = () => { const [tab, setTab] = useState(RouteTabsType.Book); return ( -
+
{ const bgColor = isSell ? SELL_BG_COLOR : 'rgba(28, 121, 63, 0.24)'; - const paddedPrice = padPrice(trace.price); return ( - - {paddedPrice} - {trace.amount} - {trace.total} - +
{formatPrice(trace.price)}
+
{formatNumber(trace.amount)}
+
{formatNumber(trace.total)}
+
- +
- {/* Overlay row that appears on hover */} - {/* eslint-disable-next-line react/no-unknown-property -- JSX style is valid in nextjs */} + {/* Overlay that appears on hover */} + {/* eslint-disable-next-line react/no-unknown-property -- jsx is, in fact, a property */} {/* Route display that shows on hover */} - getSymbolFromValueView(valueView))} /> - - +
+
); };