handle large and small numbers in orderbook

This commit is contained in:
saml33 2023-04-26 10:58:33 +10:00
parent 724680ea11
commit d1620ced49
1 changed files with 19 additions and 7 deletions

View File

@ -30,6 +30,13 @@ import { INITIAL_ANIMATION_SETTINGS } from '@components/settings/AnimationSettin
import { ArrowPathIcon } from '@heroicons/react/20/solid' import { ArrowPathIcon } from '@heroicons/react/20/solid'
import { sleep } from 'utils' import { sleep } from 'utils'
const sizeCompacter = Intl.NumberFormat('en', {
maximumFractionDigits: 6,
notation: 'compact',
})
const SHOW_EXPONENTIAL_THRESHOLD = 0.00001
const getMarket = () => { const getMarket = () => {
const group = mangoStore.getState().group const group = mangoStore.getState().group
const selectedMarket = mangoStore.getState().selectedMarket.current const selectedMarket = mangoStore.getState().selectedMarket.current
@ -609,10 +616,12 @@ const Orderbook = () => {
</div> </div>
<div className="col-span-1 text-right font-mono"> <div className="col-span-1 text-right font-mono">
{orderbookData?.spread {orderbookData?.spread
? formatNumericValue( ? orderbookData.spread < SHOW_EXPONENTIAL_THRESHOLD
orderbookData.spread, ? orderbookData.spread.toExponential()
market ? getDecimalCount(market.tickSize) : undefined : formatNumericValue(
) orderbookData.spread,
market ? getDecimalCount(market.tickSize) : undefined
)
: null} : null}
</div> </div>
</div> </div>
@ -753,9 +762,10 @@ const OrderbookRow = ({
className={`z-10 w-full text-right font-mono text-xs ${ className={`z-10 w-full text-right font-mono text-xs ${
hasOpenOrder ? 'text-th-active' : '' hasOpenOrder ? 'text-th-active' : ''
}`} }`}
// onClick={handleSizeClick}
> >
{formattedSize.toFixed(minOrderSizeDecimals)} {size >= 1000000
? sizeCompacter.format(size)
: formattedSize.toFixed(minOrderSizeDecimals)}
</div> </div>
</div> </div>
<div <div
@ -763,7 +773,9 @@ const OrderbookRow = ({
onClick={handlePriceClick} onClick={handlePriceClick}
> >
<div className="w-full text-right font-mono text-xs"> <div className="w-full text-right font-mono text-xs">
{formattedPrice.toFixed(groupingDecimalCount)} {price < SHOW_EXPONENTIAL_THRESHOLD
? formattedPrice.toExponential()
: formattedPrice.toFixed(groupingDecimalCount)}
</div> </div>
</div> </div>
</div> </div>