diff --git a/src/components/market/TradeHistory/TradeHistoryTable.tsx b/src/components/market/TradeHistory/TradeHistoryTable.tsx index f8371719..ea20077b 100644 --- a/src/components/market/TradeHistory/TradeHistoryTable.tsx +++ b/src/components/market/TradeHistory/TradeHistoryTable.tsx @@ -61,7 +61,7 @@ export const TradeHistoryTable = memo(function TradeHistoryTable({ } const currentItem = items.at(index)!; - const { cost, generation_time, matched_time } = currentItem; + const { cost, generation_time, updatedOn } = currentItem; const nextItem = items.at(index + 1); const className = nextItem ? getRowClass(nextItem, currentItem) : ''; @@ -72,7 +72,7 @@ export const TradeHistoryTable = memo(function TradeHistoryTable({ className={className} role="row" > - {formatDate(matched_time!, 'DD.MM HH:mm')} + {formatDate(updatedOn!, 'DD.MM HH:mm')} {cost.toFixed(4)} {renderDashOnEmptyValue(generation_time)} diff --git a/src/hooks/market/useInfiniteLoadTrades.ts b/src/hooks/market/useInfiniteLoadTrades.ts index a58e6df3..2b4dffa8 100644 --- a/src/hooks/market/useInfiniteLoadTrades.ts +++ b/src/hooks/market/useInfiniteLoadTrades.ts @@ -90,10 +90,18 @@ export const useInfiniteLoadTrades = ({ ); return { - items: loadedItemsState.items, + items: loadedItemsState.items.sort(sortTradesByUpdatedOnTime), loading, error, loadMoreItems, hasMore: loadedItemsState.hasNextPage, }; }; + +function sortTradesByUpdatedOnTime(a: Proposal, b: Proposal) { + if (!a.updatedOn || !b.updatedOn) { + return 0; + } + + return b.updatedOn - a.updatedOn; +} diff --git a/src/models/market/ManageOrders/ManageOrdersData.ts b/src/models/market/ManageOrders/ManageOrdersData.ts index 014fc2e3..80b09e6d 100644 --- a/src/models/market/ManageOrders/ManageOrdersData.ts +++ b/src/models/market/ManageOrders/ManageOrdersData.ts @@ -9,8 +9,8 @@ import type { TradeOrderStatus, TradeOrderType } from '../TradeOrder'; * Manage orders data. */ export type ManageOrdersData = { - init_time: string; - timestamp: string | null; + init_time: number; + timestamp: number | null; cost: number; eval_time?: number; type: TradeOrderType; diff --git a/src/models/market/Proposal/Proposal.ts b/src/models/market/Proposal/Proposal.ts index 4f4c76f6..10d6dceb 100644 --- a/src/models/market/Proposal/Proposal.ts +++ b/src/models/market/Proposal/Proposal.ts @@ -12,5 +12,5 @@ export interface Proposal extends TradeOrder { /** * Time, when proposal was accepted, either - null. */ - updatedOn: string | null; + updatedOn: number | null; } diff --git a/src/models/market/Request/Request.ts b/src/models/market/Request/Request.ts index 4880ccab..8e1b4967 100644 --- a/src/models/market/Request/Request.ts +++ b/src/models/market/Request/Request.ts @@ -21,5 +21,5 @@ export interface Request extends TradeOrder { /** * Time, when request was accepted, either - null. */ - updatedOn: string | null; + updatedOn: number | null; } diff --git a/src/models/market/TradeOrder/TradeOrder.ts b/src/models/market/TradeOrder/TradeOrder.ts index bf6dfd90..417b68ea 100644 --- a/src/models/market/TradeOrder/TradeOrder.ts +++ b/src/models/market/TradeOrder/TradeOrder.ts @@ -25,11 +25,11 @@ export interface TradeOrder extends CreateTradeOrder { /** * Time of trade order creation. */ - createdOn: string; + createdOn: number; /** * Matched time. */ - matched_time?: string; + matched_time?: number; /** * Real generation time. */ diff --git a/src/utils/dates/floorDateTo.ts b/src/utils/dates/floorDateTo.ts index f8133695..cba5884f 100644 --- a/src/utils/dates/floorDateTo.ts +++ b/src/utils/dates/floorDateTo.ts @@ -8,12 +8,12 @@ import { DateUnit } from '@/enums'; /** * Round date string to provided time value. Always rounds down. * - * @param dateString Date string. + * @param dateTimestamp Date. * @param floorTo Round date to. * @returns Date. */ -export const floorDateTo = (dateString: string, floorTo: DateUnit): Date => { - const date = new Date(dateString); +export const floorDateTo = (dateTimestamp: number, floorTo: DateUnit): Date => { + const date = new Date(dateTimestamp); switch (floorTo) { case DateUnit.minute: diff --git a/src/utils/dates/getUTCTimestamp.ts b/src/utils/dates/getUTCTimestamp.ts index b576113c..ba54aa76 100644 --- a/src/utils/dates/getUTCTimestamp.ts +++ b/src/utils/dates/getUTCTimestamp.ts @@ -10,12 +10,12 @@ import { floorDateTo } from './floorDateTo'; /** * Get UTCTimestamp from date string. * - * @param dateString - Date string. + * @param dateTimestamp - Date. * @param floorTo - Date unit floor to. * @returns UTCTimestamp. */ -export const getUTCTimestamp = (dateString: string, floorTo?: DateUnit): UTCTimestamp => { - const date = floorTo ? floorDateTo(dateString, floorTo) : new Date(dateString); +export const getUTCTimestamp = (dateTimestamp: number, floorTo?: DateUnit): UTCTimestamp => { + const date = floorTo ? floorDateTo(dateTimestamp, floorTo) : new Date(dateTimestamp); return Math.trunc(date.getTime() / 1000) as UTCTimestamp; }; diff --git a/src/utils/dates/sortTradeOrdersByDate.ts b/src/utils/dates/sortTradeOrdersByDate.ts index 7bfec753..6a985e5f 100644 --- a/src/utils/dates/sortTradeOrdersByDate.ts +++ b/src/utils/dates/sortTradeOrdersByDate.ts @@ -12,4 +12,4 @@ import type { Proposal, Request } from '@/models'; * @returns Comparsion result. */ export const sortTradeOrdersByDate = (first: T, second: T): number => - Date.parse(first.createdOn) - Date.parse(second.createdOn); + Date.parse(first.createdOn.toString()) - Date.parse(second.createdOn.toString());