diff --git a/src/components/Points/index.tsx b/src/components/Points/index.tsx index 599957d..263f6a0 100644 --- a/src/components/Points/index.tsx +++ b/src/components/Points/index.tsx @@ -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' @@ -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', @@ -149,7 +166,7 @@ const Points = () => { Redeem successful! You will be able to claim your tokens starting from {SAP_LOCK_DATE}. ) : hasSAPStarted ? ( - + ) : !loading ? ( ) : null} @@ -213,20 +230,18 @@ const Points = () => { {globalRank && ( - - - - {aggregateRank && ( - <> - - - {`Campaign${aggregateRank.totalPoints > 1 ? 's' : ''} completed`} - - - )} - - - + {aggregateRank && ( + + + + + + {`Campaign${aggregateRank.totalPoints > 1 ? 's' : ''} completed`} + + + + + )} diff --git a/src/hooks/useTaggedAllocations.ts b/src/hooks/useTaggedAllocations.ts index 0c71081..4df7a6c 100644 --- a/src/hooks/useTaggedAllocations.ts +++ b/src/hooks/useTaggedAllocations.ts @@ -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) diff --git a/src/utils/claim.ts b/src/utils/claim.ts index fd598ae..7796c12 100644 --- a/src/utils/claim.ts +++ b/src/utils/claim.ts @@ -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,