Skip to content

Commit

Permalink
feat: get current bid (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
quangdz1704 authored Jan 23, 2024
1 parent 72be076 commit 171ff88
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/pages/CoHarvest/hooks/useGetBidRound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,32 @@ export const useGetRound = () => {
const [round, setRound] = useState(0);

const queryRoundBid = async () => {
const data = await fetchRoundBid();
setRound(data as number);
const currentRound = await fetchRoundBid();

const prevRound = Number(currentRound) - 1;
const coHavestBidPool = new CoharvestBidPoolQueryClient(window.client, network.bid_pool);
const currentBid = await coHavestBidPool.biddingInfo({
round: +currentRound
});

const now = Date.now();

if (
!(prevRound >= 0 && currentBid?.bid_info?.round && now < currentBid?.bid_info?.start_time * TIMER.MILLISECOND)
) {
setRound(currentRound as number);
return;
}

const prevBid = await coHavestBidPool.biddingInfo({
round: prevRound
});

if (prevBid?.bid_info?.end_time * TIMER.MILLISECOND >= now) {
setRound(prevRound);
return;
}
setRound(currentRound as number);
};

useEffect(() => {
Expand Down

0 comments on commit 171ff88

Please sign in to comment.