From 174beee7dc855eff8ec093b12e7a4a64703ff8ef Mon Sep 17 00:00:00 2001 From: Matthew Russell Date: Wed, 30 Aug 2023 19:19:25 -0700 Subject: [PATCH] feat: update resolution creation to add more aggregation levels --- .../src/lib/orderbook-controls.tsx | 83 ++++++++++++++----- libs/market-depth/src/lib/orderbook.spec.tsx | 77 +++++++++++++---- libs/market-depth/src/lib/orderbook.tsx | 15 ++-- 3 files changed, 131 insertions(+), 44 deletions(-) diff --git a/libs/market-depth/src/lib/orderbook-controls.tsx b/libs/market-depth/src/lib/orderbook-controls.tsx index 62c3f6b0a..7fd44374e 100644 --- a/libs/market-depth/src/lib/orderbook-controls.tsx +++ b/libs/market-depth/src/lib/orderbook-controls.tsx @@ -7,7 +7,7 @@ import { TradingDropdownContent, TradingDropdownItem, } from '@vegaprotocol/ui-toolkit'; -import { formatNumberFixed } from '@vegaprotocol/utils'; +import { addDecimal, getNumberFormat } from '@vegaprotocol/utils'; export const OrderbookControls = ({ lastTradedPrice, @@ -15,27 +15,14 @@ export const OrderbookControls = ({ decimalPlaces, setResolution, }: { - lastTradedPrice: string | undefined; + lastTradedPrice: string; resolution: number; decimalPlaces: number; setResolution: (resolution: number) => void; }) => { const [isOpen, setOpen] = useState(false); - const resolutions = new Array( - Math.max(lastTradedPrice?.toString().length ?? 0, decimalPlaces + 1) - ) - .fill(null) - .map((v, i) => Math.pow(10, i)); - - const formatResolution = (r: number) => { - return formatNumberFixed( - Math.log10(r) - decimalPlaces > 0 - ? Math.pow(10, Math.log10(r) - decimalPlaces) - : 0, - decimalPlaces - Math.log10(r) - ); - }; + const resolutions = createResolutions(lastTradedPrice, decimalPlaces); const increaseResolution = () => { const index = resolutions.indexOf(resolution); @@ -56,7 +43,7 @@ export const OrderbookControls = ({ } > {resolutions.map((r) => ( - setResolution(r)}> - {formatResolution(r)} + setResolution(r)} + className="justify-end" + > + {formatResolution(r, decimalPlaces)} ))} @@ -99,7 +92,7 @@ export const OrderbookControls = ({