From 9cb526357d925fc6d63eac71e738f612b58df2b7 Mon Sep 17 00:00:00 2001 From: Andrew Besedin Date: Fri, 20 Feb 2026 13:29:48 +0300 Subject: [PATCH] update: fix prices in My Orders page --- .../responses/orders/GetUserOrdersRes.ts | 40 +++++++++++- .../dex/orders/OrdersTable/OrdersTable.tsx | 62 ++++++++++++++----- 2 files changed, 82 insertions(+), 20 deletions(-) diff --git a/src/interfaces/responses/orders/GetUserOrdersRes.ts b/src/interfaces/responses/orders/GetUserOrdersRes.ts index fca3f67..4e023e0 100644 --- a/src/interfaces/responses/orders/GetUserOrdersRes.ts +++ b/src/interfaces/responses/orders/GetUserOrdersRes.ts @@ -1,7 +1,28 @@ import CurrencyRow from '@/interfaces/common/CurrencyRow'; import OfferType from '@/interfaces/common/OfferType'; -interface UserOrderData { +export type GetUserOrdersResCurrency = { + id: number; + name: string; + code: string; + type: string; + asset_id: string; + auto_parsed: boolean; + asset_info?: { + asset_id: string; + logo: string; + price_url: string; + ticker: string; + full_name: string; + total_max_supply: string; + current_supply: string; + decimal_point: number; + meta_info: string; + }; + whitelisted: boolean; +}; + +export interface UserOrderData { id: string; type: OfferType; timestamp: string; @@ -15,6 +36,21 @@ interface UserOrderData { left: number; first_currency: CurrencyRow; second_currency: CurrencyRow; + + pair: { + id: number; + first_currency_id: number; + second_currency_id: number; + rate?: number; + coefficient?: number; + high?: number; + low?: number; + volume: number; + featured: boolean; + + first_currency: GetUserOrdersResCurrency; + second_currency: GetUserOrdersResCurrency; + }; } interface GetUserOrdersRes { @@ -24,5 +60,3 @@ interface GetUserOrdersRes { } export default GetUserOrdersRes; - -export type { UserOrderData }; diff --git a/src/pages/dex/orders/OrdersTable/OrdersTable.tsx b/src/pages/dex/orders/OrdersTable/OrdersTable.tsx index dee1ef8..929a97e 100644 --- a/src/pages/dex/orders/OrdersTable/OrdersTable.tsx +++ b/src/pages/dex/orders/OrdersTable/OrdersTable.tsx @@ -8,7 +8,8 @@ import OrdersTableProps from '@/interfaces/props/pages/dex/orders/OrdersTable/Or import { UserOrderData } from '@/interfaces/responses/orders/GetUserOrdersRes'; import Decimal from 'decimal.js'; import Tooltip from '@/components/UI/Tooltip/Tooltip'; -import { useState } from 'react'; +import { useContext, useState } from 'react'; +import { Store } from '@/store/store-reducer'; import styles from './OrdersTable.module.scss'; function OrdersTable(props: OrdersTableProps) { @@ -19,23 +20,50 @@ function OrdersTable(props: OrdersTableProps) { const isActive = category === 'active-orders'; function Row(props: { orderData: UserOrderData }) { + const { state } = useContext(Store); const { orderData } = props; const firstCurrencyName = orderData?.first_currency?.name || ''; const secondCurrencyName = orderData?.second_currency?.name || ''; + const secondCurrencyId = orderData.second_currency.asset_id ?? undefined; + const timestampDate = new Date(parseInt(orderData.timestamp, 10)); - const amount = ( - isActive - ? new Decimal(orderData.amount) - : new Decimal(orderData.amount).minus(orderData.left) - ).toString(); - const total = ( - isActive - ? new Decimal(orderData.total) - : new Decimal(orderData.amount).minus(orderData.left).mul(orderData.price) - ).toString(); + const secondAssetUsdPriceNumber = secondCurrencyId + ? state.assetsRates.get(secondCurrencyId) + : undefined; + const secondAssetUsdPrice = secondAssetUsdPriceNumber + ? new Decimal(secondAssetUsdPriceNumber) + : undefined; + + const pairRateNumber = orderData.pair.rate; + const pairRate = pairRateNumber !== undefined ? new Decimal(pairRateNumber) : undefined; + + const firstCurrencyUsdPrice = + pairRate && secondAssetUsdPrice ? pairRate.mul(secondAssetUsdPrice) : undefined; + + const actualAmount = isActive + ? new Decimal(orderData.amount) + : new Decimal(orderData.amount).minus(orderData.left); + + const actualTotal = isActive + ? new Decimal(orderData.total) + : new Decimal(orderData.amount).minus(orderData.left).mul(orderData.price); + + const amountUSD = firstCurrencyUsdPrice + ? firstCurrencyUsdPrice.mul(actualAmount) + : undefined; + const priceUSD = secondAssetUsdPrice ? secondAssetUsdPrice.mul(orderData.price) : undefined; + const totalUSD = secondAssetUsdPrice ? secondAssetUsdPrice.mul(actualTotal) : undefined; + + const amountPresentation: string = notationToString(actualAmount.toFixed()); + const pricePresentation: string = notationToString(orderData.price); + const totalPresentation: string = notationToString(actualTotal.toFixed()); + + const amountUSDPresentation: string = amountUSD ? amountUSD.toFixed(2) : 'N/A'; + const priceUSDPresentation: string = priceUSD ? priceUSD.toFixed(2) : 'N/A'; + const totalUSDPresentation: string = totalUSD ? totalUSD.toFixed(2) : 'N/A'; function CurrencyTableData({ header, @@ -102,21 +130,21 @@ function OrdersTable(props: OrdersTableProps) { {isActive && (