Skip to content

Commit

Permalink
fix: Add null check
Browse files Browse the repository at this point in the history
  • Loading branch information
memoyil committed Dec 31, 2024
1 parent ccc8a43 commit 65c2333
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions apps/web/src/hooks/useMerkl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,17 @@ export function useMerklInfo(poolAddress?: string): {

if (!opportunities || !opportunities.length) return undefined

const pools = await Promise.all(
opportunities.map(async (opportunity) => {
const responseCampaignV4 = await fetch(`${MERKL_API_V4}/opportunities/${opportunity.id}/campaigns`)
if (!responseCampaignV4.ok) {
throw responseCampaignV4
}
const campaignV4 = await responseCampaignV4.json()
return { ...opportunity, campaigns: campaignV4?.campaigns }
}),
)
const pools =
(await Promise.all(
opportunities.map(async (opportunity) => {
const responseCampaignV4 = await fetch(`${MERKL_API_V4}/opportunities/${opportunity.id}/campaigns`)
if (!responseCampaignV4.ok) {
throw responseCampaignV4
}
const campaignV4 = await responseCampaignV4.json()
return { ...opportunity, campaigns: campaignV4?.campaigns }
}),
)) ?? []

return { pools }
},
Expand Down Expand Up @@ -151,7 +152,7 @@ export function useMerklInfo(poolAddress?: string): {

const rewardAddresses = pools
.filter((pool) => isAddressEqual(pool.identifier, poolAddress))
.flatMap((pool) => pool.rewardsRecord.breakdowns.flatMap((breakdown) => breakdown.token.address))
.flatMap((pool) => pool.rewardsRecord?.breakdowns?.flatMap((breakdown) => breakdown.token.address) || [])
.filter((address, index, allAddresses) => allAddresses.indexOf(address) === index)

const rewardsPerTokenObject = userData?.rewards
Expand Down

0 comments on commit 65c2333

Please sign in to comment.