From ccc8a43aedb3fc896cb17efa3c1a8a38d4f08ce3 Mon Sep 17 00:00:00 2001 From: memoyil <2213635+memoyil@users.noreply.github.com> Date: Tue, 31 Dec 2024 10:01:47 +0100 Subject: [PATCH] fix: Filter reward tokens --- apps/web/src/hooks/useMerkl.tsx | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/apps/web/src/hooks/useMerkl.tsx b/apps/web/src/hooks/useMerkl.tsx index 0603f98f02e78..b0c84196b01a4 100644 --- a/apps/web/src/hooks/useMerkl.tsx +++ b/apps/web/src/hooks/useMerkl.tsx @@ -57,7 +57,7 @@ export function useMerklInfo(poolAddress?: string): { const opportunities = merklDataV4?.filter( (opportunity) => - opportunity?.tokens?.[0]?.symbol?.toLowerCase().startsWith('Cake-LP') || + opportunity?.tokens?.[0]?.symbol?.toLowerCase().startsWith('cake-lp') || opportunity?.protocol?.id?.toLowerCase().startsWith('pancakeswap'), ) @@ -149,11 +149,18 @@ export function useMerklInfo(poolAddress?: string): { return hasLiveDistribution }) - const rewardsPerTokenObject = userData?.rewards?.filter((reward) => { - const { amount, claimed } = reward || {} - const unclaimed = BigInt(amount || 0) - BigInt(claimed || 0) - return unclaimed > 0 - }) + const rewardAddresses = pools + .filter((pool) => isAddressEqual(pool.identifier, poolAddress)) + .flatMap((pool) => pool.rewardsRecord.breakdowns.flatMap((breakdown) => breakdown.token.address)) + .filter((address, index, allAddresses) => allAddresses.indexOf(address) === index) + + const rewardsPerTokenObject = userData?.rewards + ?.filter((reward) => rewardAddresses.some((rewardAddress) => isAddressEqual(reward.token.address, rewardAddress))) + .filter((reward) => { + const { amount, claimed } = reward || {} + const unclaimed = BigInt(amount || 0) - BigInt(claimed || 0) + return unclaimed > 0 + }) const transactionData = rewardsPerTokenObject?.reduce((acc, reward) => { // eslint-disable-next-line no-param-reassign