From 3580c2bf8d1fa047b2e659ed03f7ade6bfd8742f Mon Sep 17 00:00:00 2001 From: Usame Algan Date: Thu, 21 Nov 2024 14:34:46 +0100 Subject: [PATCH] feat: Implement eligibility checks --- src/components/Points/index.tsx | 130 +++++++++++++++++------------- src/hooks/useTaggedAllocations.ts | 13 ++- 2 files changed, 82 insertions(+), 61 deletions(-) diff --git a/src/components/Points/index.tsx b/src/components/Points/index.tsx index 96ace6b..51de253 100644 --- a/src/components/Points/index.tsx +++ b/src/components/Points/index.tsx @@ -1,4 +1,4 @@ -import { Grid, Typography, Stack, Box, Button, SvgIcon } from '@mui/material' +import { Grid, Typography, Stack, Box, Button, SvgIcon, Alert, Skeleton } from '@mui/material' import { ExternalLink } from '../ExternalLink' import PaperContainer from '../PaperContainer' import SafePassDisclaimer from '../SafePassDisclaimer' @@ -30,7 +30,7 @@ const Points = () => { const globalCampaignId = useGlobalCampaignId() const { data: globalRank } = useOwnCampaignRank(globalCampaignId) const { data: allocation } = useSafeTokenAllocation() - const { sapBoosted, sapUnboosted, totalSAP } = useTaggedAllocations() + const { sapBoosted, sapUnboosted, totalSAP } = useTaggedAllocations(eligibility?.isAllowed) const particlesRef = useCoolMode('./images/token.svg') useEffect(() => { @@ -48,21 +48,12 @@ const Points = () => { }, []) const startClaiming = async () => { - console.log({ eligibility }) // Something went wrong with fetching the eligibility for this user so we don't let them redeem if (!eligibility) return - if (eligibility.isVpn) { - // TODO: User has a VPN, show them an error and ask to turn it off for the claim process - } - - if (!eligibility.isAllowed) { - // TODO: Only redeem from the unboosted contract - } - const txs = createSAPClaimTxs({ vestingData: allocation?.vestingData ?? [], - sapBoostedClaimable: sapBoosted.inVesting, + sapBoostedClaimable: eligibility.isAllowed ? sapBoosted.inVesting : '0', sapUnboostedClaimable: sapUnboosted.inVesting, }) @@ -115,58 +106,83 @@ const Points = () => { you've earned are just the beginning. It’s time to get SAFE tokens your way. - - - + {eligibility?.isVpn ? ( + + We detected that you are using a VPN. Please turn it off in order to start the claiming process. + + + + + ) : ( + + + + )} - - - - Reward tokens - - - - - - - - - - SAFE + {!eligibility?.isVpn && ( + + + + Reward tokens + + + + + + + + + + SAFE + + + Available from {SAP_LOCK_DATE} - Available from 01.01.2025 - + )} diff --git a/src/hooks/useTaggedAllocations.ts b/src/hooks/useTaggedAllocations.ts index 916bb41..0c71081 100644 --- a/src/hooks/useTaggedAllocations.ts +++ b/src/hooks/useTaggedAllocations.ts @@ -13,7 +13,9 @@ const getTotal = (...amounts: string[]) => { return total.toString() } -export const useTaggedAllocations = (): { +export const useTaggedAllocations = ( + isEligibleForBoostedSAP?: boolean, +): { sep5: { claimable: string inVesting: string @@ -75,9 +77,12 @@ export const useTaggedAllocations = (): { investorVesting?.amount || '0', ) - const totalSAPClaimable = getTotal(sapBoostedClaimable, sapUnboostedClaimable) - const totalSAPInVesting = getTotal(sapBoostedInVesting, sapUnboostedInVesting) - const totalSAP = getTotal(sapBoostedVesting?.amount || '0', sapUnboostedVesting?.amount || '0') + const totalSAPClaimable = getTotal(isEligibleForBoostedSAP ? sapBoostedClaimable : '0', sapUnboostedClaimable) + const totalSAPInVesting = getTotal(isEligibleForBoostedSAP ? sapBoostedInVesting : '0', sapUnboostedInVesting) + const totalSAP = getTotal( + isEligibleForBoostedSAP ? sapBoostedVesting?.amount || '0' : '0', + sapUnboostedVesting?.amount || '0', + ) return { sep5: {