Skip to content

Commit

Permalink
fix: Filter reward tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
memoyil committed Dec 31, 2024
1 parent c0f20a1 commit ccc8a43
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions apps/web/src/hooks/useMerkl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ccc8a43

Please sign in to comment.