Skip to content

Commit

Permalink
fix trades order #130
Browse files Browse the repository at this point in the history
  • Loading branch information
ukorvl committed Jul 18, 2023
1 parent 066a6c2 commit 0f4c8c7
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/components/market/TradeHistory/TradeHistoryTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) : '';
Expand All @@ -72,7 +72,7 @@ export const TradeHistoryTable = memo(function TradeHistoryTable({
className={className}
role="row"
>
<TCell>{formatDate(matched_time!, 'DD.MM HH:mm')}</TCell>
<TCell>{formatDate(updatedOn!, 'DD.MM HH:mm')}</TCell>
<TCell>{cost.toFixed(4)}</TCell>
<TCell>{renderDashOnEmptyValue(generation_time)}</TCell>
</TRow>
Expand Down
10 changes: 9 additions & 1 deletion src/hooks/market/useInfiniteLoadTrades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions src/models/market/ManageOrders/ManageOrdersData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/models/market/Proposal/Proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export interface Proposal extends TradeOrder {
/**
* Time, when proposal was accepted, either - null.
*/
updatedOn: string | null;
updatedOn: number | null;
}
2 changes: 1 addition & 1 deletion src/models/market/Request/Request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export interface Request extends TradeOrder {
/**
* Time, when request was accepted, either - null.
*/
updatedOn: string | null;
updatedOn: number | null;
}
4 changes: 2 additions & 2 deletions src/models/market/TradeOrder/TradeOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
6 changes: 3 additions & 3 deletions src/utils/dates/floorDateTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions src/utils/dates/getUTCTimestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
2 changes: 1 addition & 1 deletion src/utils/dates/sortTradeOrdersByDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ import type { Proposal, Request } from '@/models';
* @returns Comparsion result.
*/
export const sortTradeOrdersByDate = <T extends Request | Proposal>(first: T, second: T): number =>
Date.parse(first.createdOn) - Date.parse(second.createdOn);
Date.parse(first.createdOn.toString()) - Date.parse(second.createdOn.toString());

0 comments on commit 0f4c8c7

Please sign in to comment.