fix: notation

This commit is contained in:
AzizbekFayziyev 2025-08-25 19:49:47 +05:00
parent 04abd67496
commit 193e9df821
5 changed files with 23 additions and 15 deletions

View file

@ -5,7 +5,7 @@ import RangeInput from '@/components/UI/RangeInput/RangeInput';
import ConnectButton from '@/components/UI/ConnectButton/ConnectButton';
import Button from '@/components/UI/Button/Button';
import { useRouter } from 'next/router';
import { classes, formatDollarValue } from '@/utils/utils';
import { classes, formatDollarValue, notationToString } from '@/utils/utils';
import InputPanelItemProps from '@/interfaces/props/pages/dex/trading/InputPanelItem/InputPanelItemProps';
import CreateOrderData from '@/interfaces/fetch-data/create-order/CreateOrderData';
import Decimal from 'decimal.js';
@ -197,7 +197,7 @@ function InputPanelItem(props: InputPanelItemProps) {
<div className={styles.inputPanel__body_total}>
<LabeledInput
value={totalState}
value={notationToString(totalState)}
setValue={() => undefined}
currency={secondCurrencyName}
label="Total"

View file

@ -29,6 +29,7 @@ const tabsData: tabsType[] = [
const OrdersPool = (props: OrdersPoolProps) => {
const {
ordersBuySell,
OrdersHistory,
setOrdersBuySell,
currencyNames,
ordersLoading,
@ -44,7 +45,7 @@ const OrdersPool = (props: OrdersPoolProps) => {
const [infoTooltipPos, setInfoTooltipPos] = useState({ x: 0, y: 0 });
const [ordersInfoTooltip, setOrdersInfoTooltip] = useState<PageOrderData | null>(null);
const [currentOrder, setCurrentOrder] = useState<tabsType>(tabsData[0]);
const { maxBuyLeftValue, maxSellLeftValue } = filteredOrdersHistory.reduce(
const { maxBuyLeftValue, maxSellLeftValue } = OrdersHistory.reduce(
(acc, order) => {
const left = parseFloat(String(order.left)) || 0;
if (order.type === 'buy') acc.maxBuyLeftValue = Math.max(acc.maxBuyLeftValue, left);
@ -200,7 +201,7 @@ const OrdersPool = (props: OrdersPoolProps) => {
<div className={styles.ordersPool__content}>
{renderTable()}
{currentOrder.type === 'orders' && (
{currentOrder.type === 'orders' && totalLeft > 0 && (
<div className={styles.ordersPool__content_stats}>
<div
style={
@ -268,19 +269,24 @@ const OrdersPool = (props: OrdersPoolProps) => {
: '#FF6767',
}}
>
{notationToString(ordersInfoTooltip?.price)}
{ordersInfoTooltip?.price}
</p>
<span>
~
{secondAssetUsdPrice && ordersInfoTooltip?.price !== undefined
? (() => {
const total =
secondAssetUsdPrice * ordersInfoTooltip.price;
const formatted =
ordersInfoTooltip.price < 0.9
? `$${total.toFixed(5)}`
: `$${total.toFixed(2)}`;
return formatted;
const total = new Decimal(secondAssetUsdPrice).mul(
ordersInfoTooltip.price,
);
if (total.abs().lt(0.01)) {
return `$${total
.toFixed(8)
.replace(/(\.\d*?[1-9])0+$/, '$1')
.replace(/\.0+$/, '')}`;
}
return `$${total.toFixed(2).replace(/\.0+$/, '')}`;
})()
: 'undefined'}
</span>

View file

@ -13,6 +13,7 @@ export interface OrdersPoolProps {
secondCurrencyName: string;
};
ordersLoading: boolean;
OrdersHistory: PageOrderData[];
filteredOrdersHistory: PageOrderData[];
trades: Trade[];
tradesLoading: boolean;

View file

@ -163,11 +163,12 @@ function Trading() {
ordersBuySell={ordersBuySell}
ordersLoading={ordersLoading}
filteredOrdersHistory={filteredOrdersHistory}
trades={trades}
trades={trades.slice(0, 100)}
tradesLoading={tradesLoading}
setOrdersBuySell={setOrdersBuySell}
takeOrderClick={onHandleTakeOrder}
matrixAddresses={matrixAddresses}
OrdersHistory={ordersHistory}
/>
<div className={styles.trading__top_chart}>

View file

@ -90,10 +90,10 @@ export const notationToString = (notation: number | string, fixed?: number) => {
const decimalValue = new Decimal(notation || '0');
if (fixed !== undefined) {
return decimalValue.toDecimalPlaces(fixed).toString();
return decimalValue.toFixed(fixed).replace(/\.?0+$/, '');
}
return decimalValue.toString();
return decimalValue.toFixed();
};
export const localeTimeLeft = (now: number | null, timestamp: number) => {