@@ -28,6 +28,17 @@ import {
2828} from '@/state/slices/selectors'
2929import { useSelectorWithArgs } from '@/state/store'
3030
31+ const getAdaptivePrecision = ( value : string | number ) : number => {
32+ const absValue = bnOrZero ( value ) . abs ( )
33+
34+ if ( absValue . gte ( 10000 ) ) return 2
35+ if ( absValue . gte ( 1000 ) ) return 3
36+ if ( absValue . gte ( 100 ) ) return 4
37+ if ( absValue . gte ( 10 ) ) return 5
38+
39+ return 6
40+ }
41+
3142export type LimitOrderCardProps = {
3243 uid : string
3344 buyAmountCryptoBaseUnit : string
@@ -202,6 +213,23 @@ export const LimitOrderCard: FC<LimitOrderCardProps> = ({
202213 [ executionPrice , toCrypto , buyAsset ] ,
203214 )
204215
216+ const sellAmountPrecision = useMemo (
217+ ( ) => getAdaptivePrecision ( sellAmountCryptoPrecision ) ,
218+ [ sellAmountCryptoPrecision ] ,
219+ )
220+
221+ const buyAmountPrecision = useMemo (
222+ ( ) => getAdaptivePrecision ( buyAmountCryptoPrecision ) ,
223+ [ buyAmountCryptoPrecision ] ,
224+ )
225+
226+ const limitPricePrecision = useMemo ( ( ) => getAdaptivePrecision ( limitPrice ) , [ limitPrice ] )
227+
228+ const executionPricePrecision = useMemo (
229+ ( ) => getAdaptivePrecision ( executionPrice ) ,
230+ [ executionPrice ] ,
231+ )
232+
205233 const tagColorScheme = useMemo ( ( ) => {
206234 switch ( status ) {
207235 case OrderStatus . OPEN :
@@ -284,15 +312,15 @@ export const LimitOrderCard: FC<LimitOrderCardProps> = ({
284312 value = { sellAmountCryptoPrecision }
285313 symbol = { sellAsset . symbol }
286314 fontSize = { fontSize }
287- maximumFractionDigits = { 6 }
315+ maximumFractionDigits = { sellAmountPrecision }
288316 />
289317 </ HoverTooltip >
290318 < HoverTooltip placement = 'top' label = { buyAmountCryptoFormatted } >
291319 < Amount . Crypto
292320 value = { buyAmountCryptoPrecision }
293321 symbol = { buyAsset . symbol }
294322 fontSize = { fontSize }
295- maximumFractionDigits = { 6 }
323+ maximumFractionDigits = { buyAmountPrecision }
296324 />
297325 </ HoverTooltip >
298326 </ Flex >
@@ -307,7 +335,7 @@ export const LimitOrderCard: FC<LimitOrderCardProps> = ({
307335 symbol = { buyAsset . symbol }
308336 color = { status === OrderStatus . FULFILLED ? 'text.subtle' : 'text.base' }
309337 fontSize = { fontSize }
310- maximumFractionDigits = { 6 }
338+ maximumFractionDigits = { limitPricePrecision }
311339 />
312340 </ HoverTooltip >
313341 { status === OrderStatus . FULFILLED && (
@@ -317,7 +345,7 @@ export const LimitOrderCard: FC<LimitOrderCardProps> = ({
317345 symbol = { buyAsset . symbol }
318346 fontSize = { fontSize }
319347 color = 'text.base'
320- maximumFractionDigits = { 6 }
348+ maximumFractionDigits = { executionPricePrecision }
321349 />
322350 </ HoverTooltip >
323351 ) }
0 commit comments