From 24fb0dfdfc4a882a390c4512eeb1d0e8055c66bd Mon Sep 17 00:00:00 2001 From: Brett <27568879+BrettCleary@users.noreply.github.com> Date: Thu, 15 Aug 2024 16:05:40 -0700 Subject: [PATCH] fix erc1155 numClaimsLeft (#1026) --- src/common/types.ts | 7 +++++-- src/frontend/hooks/useGetRewards.ts | 31 ++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/common/types.ts b/src/common/types.ts index d90705267..14e7a05e6 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -915,8 +915,11 @@ export interface Reward { name: string contract_address: `0x${string}` decimals: number | null - /* eslint-disable-next-line */ - token_ids: { amount_per_user: string; token_id: number }[] + token_ids: { + amount_per_user: string + token_id: number + numClaimsLeft: string + }[] image_url: string numClaimsLeft: string } diff --git a/src/frontend/hooks/useGetRewards.ts b/src/frontend/hooks/useGetRewards.ts index 80a4344d2..a90ae99f1 100644 --- a/src/frontend/hooks/useGetRewards.ts +++ b/src/frontend/hooks/useGetRewards.ts @@ -45,14 +45,31 @@ export function useGetRewards(questId: number | null) { ).toString() } - const questReward_i: QuestReward = { - title: reward_i.name, - imageUrl: reward_i.image_url, - chainName: getRewardCategory(reward_i, t), - numToClaim, - numOfClaimsLeft: reward_i.numClaimsLeft + if ( + reward_i.reward_type === 'ERC1155' && + reward_i.token_ids && + reward_i.token_ids.length + ) { + for (const token_i of reward_i.token_ids) { + const questReward_i: QuestReward = { + title: reward_i.name, + imageUrl: reward_i.image_url, + chainName: getRewardCategory(reward_i, t), + numToClaim: token_i.amount_per_user, + numOfClaimsLeft: token_i.numClaimsLeft + } + rewards.push(questReward_i) + } + } else { + const questReward_i: QuestReward = { + title: reward_i.name, + imageUrl: reward_i.image_url, + chainName: getRewardCategory(reward_i, t), + numToClaim, + numOfClaimsLeft: reward_i.numClaimsLeft + } + rewards.push(questReward_i) } - rewards.push(questReward_i) } return rewards },