Skip to content

Commit 6ff4df9

Browse files
committed
chore: hide staking banner if it is not donation period
1 parent 7a74fd1 commit 6ff4df9

File tree

3 files changed

+106
-23
lines changed

3 files changed

+106
-23
lines changed

packages/grant-explorer/src/features/round/ViewProjectDetails/components/StakingBannerAndModal/StakingBannerAndModal.tsx

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,24 @@ import { StakingModal } from "./StakingModal";
22
import { useCallback, useState } from "react";
33
import { StakingBanner } from "./StakingBanner";
44
import { useProjectDetailsParams } from "../../hooks/useProjectDetailsParams";
5-
6-
// TODO: either from metadata or from env value
7-
// ONLY GITCOIN ROUNDS OF GG23
8-
const STAKABLE_ROUNDS: Array<{ chainId: number; roundId: string }> = [
9-
{ chainId: 42161, roundId: "863" },
10-
{ chainId: 42161, roundId: "865" },
11-
{ chainId: 42161, roundId: "867" },
12-
// { chainId: 42220, roundId: "27" },
13-
// { chainId: 42220, roundId: "28" },
14-
// { chainId: 42220, roundId: "29" },
15-
// { chainId: 42220, roundId: "30" },
16-
// { chainId: 42220, roundId: "31" },
17-
// { chainId: 42220, roundId: "32" },
18-
// { chainId: 42220, roundId: "33" },
19-
// { chainId: 42220, roundId: "34" },
20-
// { chainId: 42220, roundId: "35" },
21-
];
5+
import { useIsStakable } from "./hooks/useIsStakable";
226

237
export const StakingBannerAndModal = () => {
248
const [isOpen, setIsOpen] = useState(false);
259

26-
const { chainId, roundId, applicationId } = useProjectDetailsParams();
10+
const {
11+
chainId,
12+
roundId,
13+
applicationId: paramApplicationId,
14+
} = useProjectDetailsParams();
15+
16+
const applicationId = paramApplicationId.includes("-")
17+
? paramApplicationId.split("-")[1]
18+
: paramApplicationId;
2719

2820
const stakingAppUrl = "https://staking-hub-mu.vercel.app"; // TODO: from env
2921
const stakeProjectUrl = `${stakingAppUrl}/#/staking-round/${chainId}/${roundId}?id=${applicationId}`;
3022

31-
console.log("stakeProjectUrl", stakeProjectUrl);
32-
3323
const handleCloseModal = useCallback(() => {
3424
setIsOpen(false);
3525
}, []);
@@ -45,9 +35,11 @@ export const StakingBannerAndModal = () => {
4535

4636
const chainIdNumber = chainId ? parseInt(chainId, 10) : 0;
4737

48-
const isStakable = STAKABLE_ROUNDS.some(
49-
(round) => round.chainId === chainIdNumber && round.roundId === roundId
50-
);
38+
const isStakable = useIsStakable({
39+
chainId: chainIdNumber,
40+
roundId,
41+
applicationId,
42+
});
5143

5244
if (!isStakable) {
5345
return null;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { useApplication } from "../../../../../projects/hooks/useApplication";
2+
import { useDataLayer } from "data-layer";
3+
import { isInfiniteDate } from "../../../../../api/utils";
4+
import { useMemo } from "react";
5+
6+
export const useIsDonationPeriod = ({
7+
chainId,
8+
roundId,
9+
applicationId,
10+
}: {
11+
chainId: number;
12+
roundId: string;
13+
applicationId: string;
14+
}) => {
15+
const dataLayer = useDataLayer();
16+
17+
const { data: application } = useApplication(
18+
{
19+
chainId,
20+
roundId,
21+
applicationId,
22+
},
23+
dataLayer
24+
);
25+
26+
const isDonationPeriod = useMemo<boolean | undefined>(() => {
27+
if (!application) return undefined;
28+
const { donationsStartTime, donationsEndTime } = application?.round ?? {};
29+
if (
30+
!donationsStartTime ||
31+
!donationsEndTime ||
32+
isInfiniteDate(new Date(donationsStartTime)) ||
33+
isInfiniteDate(new Date(donationsEndTime))
34+
)
35+
return false;
36+
37+
const currentTime = new Date();
38+
const donationsStartTimeDate = new Date("2025-03-02T12:00:00+00:00");
39+
const donationsEndTimeDate = new Date(donationsEndTime);
40+
return (
41+
currentTime >= donationsStartTimeDate &&
42+
currentTime <= donationsEndTimeDate
43+
);
44+
}, [application]);
45+
46+
return isDonationPeriod;
47+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { useMemo } from "react";
2+
import { useIsDonationPeriod } from "./useIsDonationPeriod";
3+
4+
// TODO: either from metadata or from env value
5+
// ONLY GITCOIN ROUNDS OF GG23
6+
const STAKABLE_ROUNDS: Array<{ chainId: number; roundId: string }> = [
7+
{ chainId: 42161, roundId: "863" },
8+
{ chainId: 42161, roundId: "865" },
9+
{ chainId: 42161, roundId: "867" },
10+
// { chainId: 42220, roundId: "27" },
11+
// { chainId: 42220, roundId: "28" },
12+
// { chainId: 42220, roundId: "29" },
13+
// { chainId: 42220, roundId: "30" },
14+
// { chainId: 42220, roundId: "31" },
15+
// { chainId: 42220, roundId: "32" },
16+
// { chainId: 42220, roundId: "33" },
17+
// { chainId: 42220, roundId: "34" },
18+
// { chainId: 42220, roundId: "35" },
19+
];
20+
21+
export const useIsStakable = ({
22+
chainId,
23+
roundId,
24+
applicationId,
25+
}: {
26+
chainId: number;
27+
roundId: string;
28+
applicationId: string;
29+
}) => {
30+
const isDonationPeriod = useIsDonationPeriod({
31+
chainId,
32+
roundId,
33+
applicationId,
34+
});
35+
36+
const isStakable = useMemo(() => {
37+
if (!isDonationPeriod) return false;
38+
return STAKABLE_ROUNDS.some(
39+
(round) => round.chainId === chainId && round.roundId === roundId
40+
);
41+
}, [isDonationPeriod, chainId, roundId]);
42+
43+
return isStakable;
44+
};

0 commit comments

Comments
 (0)