-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathStakingBannerAndModal.tsx
More file actions
145 lines (125 loc) · 4.38 KB
/
StakingBannerAndModal.tsx
File metadata and controls
145 lines (125 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { StakingModal } from "./StakingModal";
import { useCallback, useState } from "react";
import { StakingBanner } from "./StakingBanner";
import { useProjectDetailsParams } from "../../hooks/useProjectDetailsParams";
import { useIsStakable } from "./hooks/useIsStakable";
import { useDonationPeriod } from "./hooks/useDonationPeriod";
import { StakingButton } from "./StakingButton";
import { StakingCountDownLabel } from "./StakingCountDownLabel";
import { Button } from "../../../../collections/CollectionDetails";
import { ArrowTopRightOnSquareIcon } from "@heroicons/react/20/solid";
const STAKING_APP_URL = process.env.REACT_APP_STAKING_APP;
const COUNTDOWN_LABEL = "Staking begins in";
const COUNTDOWN_LIMIT_MINUTES = 3;
export const StakingBannerAndModal = ({
isRoundView,
}: {
isRoundView?: boolean;
}) => {
const [isOpen, setIsOpen] = useState(false);
const {
chainId,
roundId,
applicationId: paramApplicationId,
} = useProjectDetailsParams();
const applicationId = paramApplicationId?.includes("-")
? paramApplicationId.split("-")[1]
: paramApplicationId;
const stakeProjectUrl = `${STAKING_APP_URL}/#/staking-round/${chainId}/${roundId}?id=${applicationId}`;
const stakeRoundUrl = `${STAKING_APP_URL}/#/staking-round/${chainId}/${roundId}`;
const claimRewardsUrl = `${STAKING_APP_URL}/#/claim-rewards`;
const handleCloseModal = useCallback(() => {
setIsOpen(false);
}, []);
const handleOpenModal = useCallback(() => {
setIsOpen(true);
}, []);
const handleStake = useCallback(() => {
window.open(stakeProjectUrl, "_blank");
handleCloseModal();
}, [handleCloseModal, stakeProjectUrl]);
const handleStakeRound = useCallback(() => {
window.open(stakeRoundUrl, "_blank");
handleCloseModal();
}, [handleCloseModal, stakeRoundUrl]);
const handleClaimRewards = useCallback(() => {
window.open(claimRewardsUrl, "_blank");
}, [claimRewardsUrl]);
const chainIdNumber = chainId ? parseInt(chainId, 10) : 0;
const isStakable = useIsStakable({
chainId: chainIdNumber,
roundId,
});
const { isDonationPeriod, timeToDonationStart, timeToDonationEnd } =
useDonationPeriod({
chainId: chainIdNumber,
roundId,
refreshInterval: 60 * 1000, // 1 minute
});
const isCountDownToStartPeriod =
timeToDonationStart && timeToDonationStart.totalMilliseconds > 0;
const isRoundEnded =
timeToDonationEnd && timeToDonationEnd.totalMilliseconds < 0;
if (isStakable && isRoundEnded) {
return (
<div className="mt-2 items-center justify-center">
<StakingBanner isRoundView={isRoundView} isClaimPeriod={true}>
<StakingButton
onClick={handleClaimRewards}
isRoundView={isRoundView}
isClaimPeriod={true}
/>
</StakingBanner>
</div>
);
}
if (isStakable && isCountDownToStartPeriod) {
return (
<div className="mt-2 mb-6">
<StakingBanner isRoundView={isRoundView}>
<StakingCountDownLabel
timeLeft={timeToDonationStart}
label={COUNTDOWN_LABEL}
limitMinutes={COUNTDOWN_LIMIT_MINUTES}
isRoundView={isRoundView}
/>
</StakingBanner>
</div>
);
}
if (isStakable && isDonationPeriod) {
return (
<div className="mt-2 mb-6">
<StakingBanner isRoundView={isRoundView}>
<div className="flex items-center gap-2">
<StakingButton
onClick={handleOpenModal}
isRoundView={isRoundView}
/>
{isRoundView && (
<Button
onClick={() => {
window.open(
"https://dashboard.boost.explorer.gitcoin.co/about-explorer-boost",
"_blank"
);
}}
className="text-black text-sm font-mono font-medium px-4 py-2 leading-normal rounded-lg inline-flex justify-center items-center gap-2 bg-transparent hover:bg-transparent"
>
Learn more
<ArrowTopRightOnSquareIcon className="w-4 h-4" />
</Button>
)}
</div>
</StakingBanner>
<StakingModal
isOpen={isOpen}
onClose={handleCloseModal}
onStake={isRoundView ? handleStakeRound : handleStake}
isRoundView={isRoundView ?? false}
/>
</div>
);
}
return null;
};