Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1423 from UniverseXYZ/ivanshterev/sc-2228
Browse files Browse the repository at this point in the history
Fix/history tab - shows all the missing events (chronologically ordered)
  • Loading branch information
taskudis authored Mar 17, 2022
2 parents 681c772 + 990873f commit 4589b3d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
25 changes: 24 additions & 1 deletion src/app/modules/nft/api/get-history-api.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -57,6 +58,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 === OrderSide.BUY && order.status === OrderStatus.FILLED) {
const listingOrder = {
...order,
createdAt: order.createdAt,
side: OrderSide.BUY,
status: OrderStatus.CREATED,
}
orderHistory.push(listingOrder);
order.createdAt = order.updatedAt;
} else if (order.side === OrderSide.SELL && order.status === OrderStatus.FILLED) {
const listingOrder = {
...order,
createdAt: order.createdAt,
side: OrderSide.SELL,
status: OrderStatus.CREATED,
}
orderHistory.push(listingOrder);
order.createdAt = order.updatedAt;
order.maker = order.taker;
}
if (order.maker) {
order.makerData = await GetUserApi(order.maker);
}
Expand All @@ -68,7 +89,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
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ const HistoryEvent: React.FC<IHistoryEventProps> = ({ 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;
Expand All @@ -62,12 +62,13 @@ const HistoryEvent: React.FC<IHistoryEventProps> = ({ 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 (
<NFTTabItemWrapper>
<Flex>
{!onlyListings && <Box {...styles.ActionIconStyle} bg={actionIcon[type]} />}
<Box {...styles.ActionIconStyle} bg={actionIcon[type]} />
<Box>
<Text {...styles.NameStyle}>
<Box {...styles.ActionLabelStyle}>{nameLabels[type]} </Box>
Expand All @@ -78,6 +79,12 @@ const HistoryEvent: React.FC<IHistoryEventProps> = ({ event, onlyListings, cance
</Text>
<Text {...styles.AddedLabelStyle}>
{getAddedAtLabel(event.createdAt)}
{!onlyListings && canceled && (
<Box as={'span'} {...styles.ExpiredStyle}>
{' '}
(canceled)
</Box>
)}
{!onlyListings && expired && (
<Box as={'span'} {...styles.ExpiredStyle}>
{' '}
Expand Down

0 comments on commit 4589b3d

Please sign in to comment.