From a3e94e072e19ddaeeea9047fcddd89c2bc35ca86 Mon Sep 17 00:00:00 2001 From: Sashimi <93623541+sashimi36@users.noreply.github.com> Date: Fri, 10 Jun 2022 23:14:58 -0500 Subject: [PATCH] Fixes for rewards and staking (#235) * Claim rewards for tokens that have pending rewards / Refetch queries on wallet address change * Remove logs * dollarValue -> tokenAmount change in useClaimRewards --- .../hooks/usePoolTokensDollarValue.ts | 4 ++-- features/liquidity/hooks/useStakingClaims.ts | 2 +- hooks/useRewardsQueries.ts | 19 ++++++++++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/features/liquidity/hooks/usePoolTokensDollarValue.ts b/features/liquidity/hooks/usePoolTokensDollarValue.ts index f6f34ec5..dbd30393 100644 --- a/features/liquidity/hooks/usePoolTokensDollarValue.ts +++ b/features/liquidity/hooks/usePoolTokensDollarValue.ts @@ -62,8 +62,8 @@ export const usePoolTokensDollarValue = ({ return [ getPoolTokensDollarValue({ swapInfo, tokenAmountInMicroDenom }), isLoading || !enabled, - ] + ] as const } - return [0, isLoading || !enabled] + return [0, isLoading || !enabled] as const } diff --git a/features/liquidity/hooks/useStakingClaims.ts b/features/liquidity/hooks/useStakingClaims.ts index 1c8ddfd0..fd82e4ac 100644 --- a/features/liquidity/hooks/useStakingClaims.ts +++ b/features/liquidity/hooks/useStakingClaims.ts @@ -19,7 +19,7 @@ export const useStakingClaims = ({ poolId }) => { const { data = {} as StakingClaimsType, isLoading } = useQuery( - `@staking-claims/${poolId}`, + `@staking-claims/${poolId}/${address}`, async () => { const claims = await getClaims(address, pool.staking_address, client) diff --git a/hooks/useRewardsQueries.ts b/hooks/useRewardsQueries.ts index 2f3de77f..0500c397 100644 --- a/hooks/useRewardsQueries.ts +++ b/hooks/useRewardsQueries.ts @@ -28,7 +28,7 @@ export const usePendingRewards = ({ pool }: UsePendingRewardsArgs) => { pool?.rewards_tokens?.length > 0 && pool?.staking_address const { data: rewards, isLoading } = useQuery( - `pendingRewards/${pool?.pool_id}`, + `pendingRewards/${pool?.pool_id}/${address}/${shouldQueryRewards}`, async () => { if (shouldQueryRewards) { return await Promise.all( @@ -90,14 +90,23 @@ export const useClaimRewards = ({ pool, ...options }: UseClaimRewardsArgs) => { async () => { const hasPendingRewards = __POOL_REWARDS_ENABLED__ && - pendingRewards?.find(({ dollarValue }) => dollarValue > 0) + pendingRewards?.find(({ tokenAmount }) => tokenAmount > 0) const shouldBeAbleToClaimRewards = pool && client && hasPendingRewards if (shouldBeAbleToClaimRewards) { - const rewardsAddresses = pool.rewards_tokens?.map( - ({ rewards_address }) => rewards_address - ) + const rewardsAddresses = pool.rewards_tokens + /* + * filter out rewards contracts that don't have pending rewards accumulated just yet. + * */ + .filter((token) => { + const pendingRewardsForToken = pendingRewards.find( + ({ tokenInfo }) => token.symbol === tokenInfo.symbol + ) + + return pendingRewardsForToken.tokenAmount > 0 + }) + .map(({ rewards_address }) => rewards_address) return await claimRewards(address, rewardsAddresses, client) }