diff --git a/components/rewards/Claim.tsx b/components/rewards/Claim.tsx index 1f746a7c..b605b081 100644 --- a/components/rewards/Claim.tsx +++ b/components/rewards/Claim.tsx @@ -177,24 +177,31 @@ const ClaimPage = () => { const transactionInstructions: TransactionInstructionWithType[] = [] // Create claim account if it doesn't exist if (claimed === undefined) { - transactionInstructions.push({ - instructionsSet: [ - new TransactionInstructionWithSigners( - await rewardsClient.program.methods - .claimAccountCreate() - .accounts({ - distribution: distribution.publicKey, - claimAccount: distribution.findClaimAccountAddress(publicKey!), - claimant: publicKey!, - payer: publicKey!, - systemProgram: web3.SystemProgram.programId, - rent: web3.SYSVAR_RENT_PUBKEY, - }) - .instruction(), - ), - ], - sequenceType: SequenceType.Sequential, - }) + const claimAccountPk = distribution.findClaimAccountAddress(publicKey!) + const isCreated = (await connection.getBalance(claimAccountPk)) > 1 + + if (!isCreated) { + transactionInstructions.push({ + instructionsSet: [ + new TransactionInstructionWithSigners( + await rewardsClient.program.methods + .claimAccountCreate() + .accounts({ + distribution: distribution.publicKey, + claimAccount: distribution.findClaimAccountAddress( + publicKey!, + ), + claimant: publicKey!, + payer: publicKey!, + systemProgram: web3.SystemProgram.programId, + rent: web3.SYSVAR_RENT_PUBKEY, + }) + .instruction(), + ), + ], + sequenceType: SequenceType.Sequential, + }) + } } try { diff --git a/hooks/useRewards.ts b/hooks/useRewards.ts index 8a862a3d..e16147aa 100644 --- a/hooks/useRewards.ts +++ b/hooks/useRewards.ts @@ -116,6 +116,5 @@ export const useIsAllClaimed = ( setShowClaim(false) } }, [distributionData, walletPk, isAllClaimed]) - return { isAllClaimed, showClaim } }