Skip to content

Commit

Permalink
Fixes for rewards and staking (#235)
Browse files Browse the repository at this point in the history
* Claim rewards for tokens that have pending rewards / Refetch queries on wallet address change

* Remove logs

* dollarValue -> tokenAmount change in useClaimRewards
  • Loading branch information
sashimi36 authored Jun 11, 2022
1 parent 782e68a commit a3e94e0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions features/liquidity/hooks/usePoolTokensDollarValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion features/liquidity/hooks/useStakingClaims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const useStakingClaims = ({ poolId }) => {

const { data = {} as StakingClaimsType, isLoading } =
useQuery<StakingClaimsType>(
`@staking-claims/${poolId}`,
`@staking-claims/${poolId}/${address}`,
async () => {
const claims = await getClaims(address, pool.staking_address, client)

Expand Down
19 changes: 14 additions & 5 deletions hooks/useRewardsQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit a3e94e0

Please sign in to comment.