From 3d12b047d053fbd943049f1d014a434646b8fd7f Mon Sep 17 00:00:00 2001 From: Josef Date: Tue, 10 Dec 2024 12:53:17 +0100 Subject: [PATCH] fix: routebook visual updates (#187) * fix: padding in route book * refactor: update skeleton loading rows and format price/number functions in trade components - Replaced static loading placeholders with a reusable Skeleton component for better consistency in the RouteBook. - Adjusted table header padding for improved alignment. - Introduced formatPrice and formatNumber functions to standardize price and number formatting across TradeRow and RouteBook components. - Updated TradeRow to utilize new formatting functions for displaying prices, amounts, and totals. * feat: almost there * fix: no more tables, grid is king * fix: lints * fix: lints --- src/pages/trade/ui/route-book.tsx | 130 ++++++++++++++++++------------ src/pages/trade/ui/route-tabs.tsx | 2 +- src/pages/trade/ui/trade-row.tsx | 51 +++++++----- 3 files changed, 109 insertions(+), 74 deletions(-) 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))} /> - - +
+
); };