From 9c69a4f388e55bdcef0b63e638b32a89a487b7d5 Mon Sep 17 00:00:00 2001 From: IvanShterev Date: Thu, 17 Mar 2022 16:14:44 +0200 Subject: [PATCH 1/2] Fix - shows all the missing events (chronologically ordered) --- src/app/modules/nft/api/get-history-api.ts | 24 ++++++++++++++++++- .../history-listings-event/HistoryEvent.tsx | 15 ++++++++---- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/app/modules/nft/api/get-history-api.ts b/src/app/modules/nft/api/get-history-api.ts index 7c58c2cb1..3bb8ca5e2 100644 --- a/src/app/modules/nft/api/get-history-api.ts +++ b/src/app/modules/nft/api/get-history-api.ts @@ -57,6 +57,26 @@ export const GetHistoryApi = async (collectionAddress: string, tokenId: string): // Api call to get the order creator or the minter data for (let i = 0; i < orderHistory.length; i++) { const order = orderHistory[i]; + if (order.side === 0 && order.status === 2) { + const listingOrder = { + ...order, + createdAt: order.createdAt, + side: 0, + status: 0, + } + orderHistory.push(listingOrder); + order.createdAt = order.updatedAt; + } else if (order.side === 1 && order.status === 2) { + const listingOrder = { + ...order, + createdAt: order.createdAt, + side: 1, + status: 0, + } + orderHistory.push(listingOrder); + order.createdAt = order.updatedAt; + order.maker = order.taker; + } if (order.maker) { order.makerData = await GetUserApi(order.maker); } @@ -68,7 +88,9 @@ export const GetHistoryApi = async (collectionAddress: string, tokenId: string): } return { - orderHistory: orderHistory, + orderHistory: orderHistory.sort((a, b) => { + return new Date(b.createdAt).valueOf() - new Date(a.createdAt).valueOf(); + }), mintEvent: mintEvent } }; diff --git a/src/app/modules/nft/pages/nft-page/components/nft-info/components/shared/history-listings-event/HistoryEvent.tsx b/src/app/modules/nft/pages/nft-page/components/nft-info/components/shared/history-listings-event/HistoryEvent.tsx index d81d20c9d..5ef53dc94 100644 --- a/src/app/modules/nft/pages/nft-page/components/nft-info/components/shared/history-listings-event/HistoryEvent.tsx +++ b/src/app/modules/nft/pages/nft-page/components/nft-info/components/shared/history-listings-event/HistoryEvent.tsx @@ -34,9 +34,9 @@ const HistoryEvent: React.FC = ({ event, onlyListings, cance const side = event.side; const status = event.status; - if (side === OrderSide.SELL && status === OrderStatus.FILLED) { + if (status === OrderStatus.FILLED) { type = HistoryType.BOUGHT; - } else if (side === OrderSide.SELL && status === OrderStatus.CREATED) { + } else if (side === OrderSide.SELL && (status === OrderStatus.CREATED || OrderStatus.CANCELLED || OrderStatus.STALE)) { type = HistoryType.LISTED; } else if (onlyListings) { type = HistoryType.LISTED; @@ -62,12 +62,13 @@ const HistoryEvent: React.FC = ({ event, onlyListings, cance const usd = new BigNumber(price).multipliedBy(usdPrice).toFixed(2); const endDate = new Date(event.end * 1000); - const expired = type === HistoryType.OFFER ? dayjs().diff(endDate) > 0 : false; + const canceled = (type === HistoryType.OFFER || type === HistoryType.LISTED) && (event.status === OrderStatus.CANCELLED || event.status === OrderStatus.STALE); + const expired = !canceled && type === HistoryType.OFFER ? dayjs().diff(endDate) > 0 || event.status === OrderStatus.STALE : false; return ( - {!onlyListings && } + {nameLabels[type]} @@ -78,6 +79,12 @@ const HistoryEvent: React.FC = ({ event, onlyListings, cance {getAddedAtLabel(event.createdAt)} + {!onlyListings && canceled && ( + + {' '} + (canceled) + + )} {!onlyListings && expired && ( {' '} From 990873f268cee9b7b5f0196bcfa939c9a4298c88 Mon Sep 17 00:00:00 2001 From: IvanShterev Date: Thu, 17 Mar 2022 16:14:44 +0200 Subject: [PATCH 2/2] Replaced order side, status numbers with enums --- src/app/modules/nft/api/get-history-api.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/app/modules/nft/api/get-history-api.ts b/src/app/modules/nft/api/get-history-api.ts index 3bb8ca5e2..5302ba1a8 100644 --- a/src/app/modules/nft/api/get-history-api.ts +++ b/src/app/modules/nft/api/get-history-api.ts @@ -1,6 +1,7 @@ import axios from 'axios'; import { utils } from 'ethers'; import { ZERO_ADDRESS } from '../../../constants'; +import { OrderSide, OrderStatus } from '../../marketplace/enums'; import { GetUserApi } from '../api'; import { IOrder, IUser } from '../types'; @@ -57,21 +58,21 @@ export const GetHistoryApi = async (collectionAddress: string, tokenId: string): // Api call to get the order creator or the minter data for (let i = 0; i < orderHistory.length; i++) { const order = orderHistory[i]; - if (order.side === 0 && order.status === 2) { + if (order.side === OrderSide.BUY && order.status === OrderStatus.FILLED) { const listingOrder = { ...order, createdAt: order.createdAt, - side: 0, - status: 0, + side: OrderSide.BUY, + status: OrderStatus.CREATED, } orderHistory.push(listingOrder); order.createdAt = order.updatedAt; - } else if (order.side === 1 && order.status === 2) { + } else if (order.side === OrderSide.SELL && order.status === OrderStatus.FILLED) { const listingOrder = { ...order, createdAt: order.createdAt, - side: 1, - status: 0, + side: OrderSide.SELL, + status: OrderStatus.CREATED, } orderHistory.push(listingOrder); order.createdAt = order.updatedAt;