-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: tvminh <[email protected]>
- Loading branch information
1 parent
8e9b126
commit 13edf50
Showing
14 changed files
with
239 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import React, { useState, useCallback, useEffect } from 'react'; | ||
|
||
import { ExplorerLink } from 'components/ExplorerLink'; | ||
import { Processing } from 'components/Processing'; | ||
import InfiniteScroll from 'react-infinite-scroll-component'; | ||
|
||
import { CandyShop, fetchAuctionHistory } from '@liqnft/candy-shop-sdk'; | ||
import { AuctionBid, AuctionStatus, ListBase, ShopStatusType, SortBy } from '@liqnft/candy-shop-types'; | ||
import { useUpdateSubject } from 'public/Context/CandyShopDataValidator'; | ||
import { removeDuplicate, EMPTY_FUNCTION } from 'utils/helperFunc'; | ||
|
||
import dayjs from 'dayjs'; | ||
import relativeTime from 'dayjs/plugin/relativeTime'; | ||
dayjs.extend(relativeTime); | ||
import './style.less'; | ||
|
||
interface AuctionActivityProps { | ||
candyShop: CandyShop; | ||
orderBy?: SortBy; | ||
auctionAddress: string; | ||
} | ||
|
||
const LIMIT = 10; | ||
const Logger = 'CandyShopUI/AuctionActivity'; | ||
|
||
export const AuctionActivity: React.FC<AuctionActivityProps> = ({ candyShop, auctionAddress, orderBy }) => { | ||
const [bids, setBids] = useState<AuctionBid[]>([]); | ||
const [hasMore, setHasMore] = useState<boolean>(true); | ||
const [offset, setOffset] = useState<number>(0); | ||
|
||
useUpdateSubject({ subject: ShopStatusType.Auction }); | ||
|
||
const getAuctionBids = useCallback( | ||
(offset: number, limit: number, firstLoad?: boolean) => () => { | ||
fetchAuctionHistory(auctionAddress, { offset, limit, orderByArr: orderBy }) | ||
.then((res: ListBase<AuctionBid>) => { | ||
const { result, offset, totalCount, count, success } = res; | ||
if (!success) { | ||
return setHasMore(false); | ||
} | ||
const hasMore = offset + count < Number(totalCount); | ||
if (hasMore) { | ||
setOffset(offset + count + 1); | ||
} | ||
|
||
setHasMore(hasMore); | ||
setBids((list) => { | ||
if (firstLoad) return result || []; | ||
return removeDuplicate<AuctionBid>(list, result, 'bidAddress'); | ||
}); | ||
}) | ||
.catch((error: any) => { | ||
setHasMore(false); | ||
console.log(`${Logger}: fetchAuctionHistory failed, error=`, error); | ||
}); | ||
}, | ||
[auctionAddress, orderBy] | ||
); | ||
|
||
useEffect(() => { | ||
getAuctionBids(0, LIMIT)(); | ||
}, [getAuctionBids]); | ||
|
||
return ( | ||
<div className="candy-activity-auction"> | ||
<div className="candy-activity-auction-table-container" id="candy-activity-auction-scroll-target"> | ||
<div className="candy-activity-auction-header candy-activity-auction-item"> | ||
<span>BUYER ADDRESS</span> | ||
<span>PRICE</span> | ||
<span>STATUS</span> | ||
</div> | ||
|
||
<InfiniteScroll | ||
dataLength={bids.length} | ||
next={offset === 0 ? EMPTY_FUNCTION : getAuctionBids(offset, LIMIT)} | ||
loader={<Processing />} | ||
hasMore={hasMore} | ||
> | ||
{bids.map((auction) => { | ||
return ( | ||
<div key={auction.bidAddress} className="candy-activity-auction-item"> | ||
<div> | ||
<ExplorerLink type="address" address={auction.buyerAddress} /> | ||
</div> | ||
<div className="candy-activity-auction-price"> | ||
{`${(Number(auction.price) / candyShop.baseUnitsPerCurrency).toLocaleString(undefined, { | ||
minimumFractionDigits: candyShop.priceDecimalsMin, | ||
maximumFractionDigits: candyShop.priceDecimals | ||
})} ${candyShop.currencySymbol}`} | ||
</div> | ||
<div>{AuctionStatus[auction.status]}</div> | ||
</div> | ||
); | ||
})} | ||
</InfiniteScroll> | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
@import '../../variable.less'; | ||
|
||
.candy-activity-auction { | ||
padding: 20px 50px; | ||
font-size: 16px; | ||
|
||
@media @desktopS { | ||
padding: 20px 15px; | ||
} | ||
.infinite-scroll-component { | ||
overflow: unset !important; | ||
} | ||
|
||
.candy-activity-auction-item { | ||
display: grid; | ||
text-align: left; | ||
align-items: center; | ||
|
||
grid-template-columns: minmax(300px, 1fr) 1fr 200px; | ||
> * { | ||
padding: 8px 12px; | ||
border-bottom: 1px solid @gray-light; | ||
min-height: 67px; | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
@media @desktopL { | ||
grid-template-columns: minmax(300px, 1fr) 1fr 200px; | ||
} | ||
|
||
img { | ||
width: 50px; | ||
height: 50px; | ||
background-color: @gray-light; | ||
object-fit: cover; | ||
margin-right: 20px; | ||
} | ||
} | ||
|
||
.candy-activity-auction-header { | ||
span { | ||
border-bottom: 2px solid @gray-medium; | ||
font-size: 14px; | ||
color: #757575; | ||
font-weight: 700; | ||
text-align: left; | ||
min-height: unset; | ||
} | ||
} | ||
|
||
.candy-activity-auction-table-container { | ||
overflow: auto; | ||
|
||
.candy-activity-auction-price { | ||
white-space: nowrap; | ||
} | ||
} | ||
|
||
.candy-processing { | ||
margin: 60px auto; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Some component has infinity load logic. Because APIs with pagination can return same item, | ||
* so this function to help filter that item out of list | ||
* and guarantee React render function and duplicate item UI | ||
* | ||
* @param oldList current list is saved in local state | ||
* @param addList new list is from api response | ||
* @param key unique field in each item of list | ||
* @returns | ||
*/ | ||
export function removeDuplicate<T>(oldList: T[], addList: T[], key: keyof T): T[] { | ||
const duplicateList = [...oldList, ...addList]; | ||
const newList: T[] = []; | ||
const memo: any = {}; | ||
for (const item of duplicateList) { | ||
if (memo[item[key]]) break; | ||
newList.push(item); | ||
memo[item[key]] = true; | ||
} | ||
return newList; | ||
} | ||
|
||
/** | ||
* This function prevents double call api transaction in useEffect and package react-infinite-scroll-component | ||
*/ | ||
export function EMPTY_FUNCTION(): void { | ||
// | ||
} |
Oops, something went wrong.