Skip to content

Commit

Permalink
Split SAP claim and redeem into two functions
Browse files Browse the repository at this point in the history
  • Loading branch information
usame-algan committed Dec 2, 2024
1 parent 45536ab commit 453aa5a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 16 deletions.
47 changes: 31 additions & 16 deletions src/components/Points/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { formatEther } from 'ethers/lib/utils'
import Spotlight from '@/public/images/spotlight.svg'
import Star from '@/public/images/star.svg'
import Star1 from '@/public/images/star1.svg'
import { createSAPClaimTxs } from '@/utils/claim'
import { createSAPClaimTxs, createSAPRedeemTxs } from '@/utils/claim'
import { useSafeTokenAllocation } from '@/hooks/useSafeTokenAllocation'
import { useSafeAppsSDK } from '@safe-global/safe-apps-react-sdk'
import { FingerprintJSPro } from '@fingerprintjs/fingerprintjs-pro-react'
Expand Down Expand Up @@ -53,6 +53,23 @@ const Points = () => {
// Something went wrong with fetching the eligibility for this user so we don't let them redeem
if (!eligibility) return

const txs = createSAPRedeemTxs({
vestingData: allocation?.vestingData ?? [],
sapBoostedClaimable: eligibility.isAllowed ? sapBoosted.inVesting : '0',
sapUnboostedClaimable: sapUnboosted.inVesting,
})

try {
await sdk.txs.send({ txs })
} catch (error) {
console.error(error)
}
}

const claimSAP = async () => {
// Something went wrong with fetching the eligibility for this user so we don't let them redeem
if (!eligibility) return

const txs = createSAPClaimTxs({
vestingData: allocation?.vestingData ?? [],
sapBoostedClaimable: eligibility.isAllowed ? sapBoosted.inVesting : '0',
Expand Down Expand Up @@ -149,7 +166,7 @@ const Points = () => {
Redeem successful! You will be able to claim your tokens starting from {SAP_LOCK_DATE}.
</Alert>
) : hasSAPStarted ? (
<ClaimButton startClaiming={startClaiming} text="Claim" />
<ClaimButton startClaiming={claimSAP} text="Claim" />
) : !loading ? (
<ClaimButton startClaiming={startClaiming} text="Start claiming" />
) : null}
Expand Down Expand Up @@ -213,20 +230,18 @@ const Points = () => {

{globalRank && (
<Grid container pt={3} spacing={3}>
<Grid item xs={12} lg={4}>
<PaperContainer>
<Stack alignItems="center">
{aggregateRank && (
<>
<PointsCounter value={aggregateRank.totalPoints} variant="h2" fontWeight={700} fontSize="44px" />
<Typography color="text.secondary" mt={1}>
{`Campaign${aggregateRank.totalPoints > 1 ? 's' : ''} completed`}
</Typography>
</>
)}
</Stack>
</PaperContainer>
</Grid>
{aggregateRank && (
<Grid item xs={12} lg={4}>
<PaperContainer>
<Stack alignItems="center">
<PointsCounter value={aggregateRank.totalPoints} variant="h2" fontWeight={700} fontSize="44px" />
<Typography color="text.secondary" mt={1}>
{`Campaign${aggregateRank.totalPoints > 1 ? 's' : ''} completed`}
</Typography>
</Stack>
</PaperContainer>
</Grid>
)}

<Grid item xs={12} lg={4}>
<PaperContainer>
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useTaggedAllocations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export const useTaggedAllocations = (
const [sapBoostedClaimable, sapBoostedInVesting] = useAmounts(sapBoostedVesting)
const [sapUnboostedClaimable, sapUnboostedInVesting] = useAmounts(sapUnboostedVesting)

console.log({ sapBoostedClaimable, sapBoostedInVesting })

// Calculate total of claimable vs. vested amounts
const totalAmountClaimable = getTotal(sep5Claimable, userClaimable, ecosystemClaimable, investorClaimable)

Expand Down
34 changes: 34 additions & 0 deletions src/utils/claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,40 @@ export const createClaimTxs = ({
return txs
}

export const createSAPRedeemTxs = ({
vestingData,
sapBoostedClaimable,
sapUnboostedClaimable,
}: {
vestingData: Vesting[]
sapBoostedClaimable: string
sapUnboostedClaimable: string
}) => {
const txs: BaseTransaction[] = []

const { sapBoostedVesting, sapUnboostedVesting } = getVestingTypes(vestingData)

if (sapBoostedVesting && BigNumber.from(sapBoostedClaimable).gt(0) && !sapBoostedVesting.isRedeemed) {
const redeemTx = createRedeemTx({
vestingClaim: sapBoostedVesting,
airdropAddress: sapBoostedVesting.contract,
})

txs.push(redeemTx)
}

if (sapUnboostedVesting && BigNumber.from(sapUnboostedClaimable).gt(0) && !sapUnboostedVesting.isRedeemed) {
const redeemTx = createRedeemTx({
vestingClaim: sapUnboostedVesting,
airdropAddress: sapUnboostedVesting.contract,
})

txs.push(redeemTx)
}

return txs
}

export const createSAPClaimTxs = ({
vestingData,
sapBoostedClaimable,
Expand Down

0 comments on commit 453aa5a

Please sign in to comment.