fix: fixed the rewards center (#524)

This commit is contained in:
Linkie Link 2023-10-03 15:54:22 +02:00 committed by GitHub
parent 7864b579cf
commit 8a71f4664a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 26 deletions

View File

@ -1,20 +1,20 @@
import { cacheFn, unclaimedRewardsCache } from 'api/cache' import { cacheFn, unclaimedRewardsCache } from 'api/cache'
import { getIncentivesQueryClient } from 'api/cosmwasm-client' import { getIncentivesQueryClient } from 'api/cosmwasm-client'
import { ENV } from 'constants/env'
import { BNCoin } from 'types/classes/BNCoin' import { BNCoin } from 'types/classes/BNCoin'
import iterateContractQuery from 'utils/iterateContractQuery'
export default async function getUnclaimedRewards( export default async function getUnclaimedRewards(accountId: string): Promise<BNCoin[]> {
user: string,
accountId: string,
): Promise<BNCoin[]> {
try { try {
const client = await getIncentivesQueryClient() const client = await getIncentivesQueryClient()
const unclaimedRewards = await cacheFn( const unclaimedRewards = await cacheFn(
() => () =>
client.userUnclaimedRewards({ iterateContractQuery(() =>
user, client.userUnclaimedRewards({
accountId, user: ENV.ADDRESS_CREDIT_MANAGER,
limit: 100, accountId,
}), }),
),
unclaimedRewardsCache, unclaimedRewardsCache,
`incentives/${accountId}`, `incentives/${accountId}`,
60, 60,

View File

@ -31,10 +31,10 @@ const renderIncentives = (unclaimedRewards: BNCoin[]) => {
const asset = ASSETS.find(byDenom(reward.denom)) const asset = ASSETS.find(byDenom(reward.denom))
if (!asset) return null if (!asset) return null
return ( return (
<> <div className='w-full' key={index}>
{index !== 0 && <Divider />} {index !== 0 && <Divider />}
<AssetBalanceRow key={reward.denom} coin={reward} asset={asset} /> <AssetBalanceRow key={reward.denom} coin={reward} asset={asset} />
</> </div>
) )
}) })
} }
@ -109,7 +109,7 @@ export default function RewardsCenter() {
<> <>
<Button <Button
variant='solid' variant='solid'
color='secondary' color='tertiary'
className='w-full py-2' className='w-full py-2'
showProgressIndicator={isConfirming} showProgressIndicator={isConfirming}
text={'Claim total account rewards'} text={'Claim total account rewards'}

View File

@ -1,22 +1,15 @@
import useSWR from 'swr' import useSWR from 'swr'
import getUnclaimedRewards from 'api/incentives/getUnclaimedRewards' import getUnclaimedRewards from 'api/incentives/getUnclaimedRewards'
import useCurrentAccount from 'hooks/useCurrentAccount' import useAccountId from 'hooks/useAccountId'
import useStore from 'store'
import { BNCoin } from 'types/classes/BNCoin' import { BNCoin } from 'types/classes/BNCoin'
export default function useUserUnclaimedRewards() { export default function useUserUnclaimedRewards() {
const user = useStore((s) => s.address) const accountId = useAccountId()
const account = useCurrentAccount()
return useSWR( return useSWR(`userUnclaimedRewards-${accountId}`, () => getUnclaimedRewards(accountId ?? ''), {
`userUnclaimedRewards-${account?.id}`, fallbackData: [] as BNCoin[],
() => getUnclaimedRewards(user ?? '', account?.id ?? ''), isPaused: () => !accountId,
{ revalidateOnFocus: false,
fallbackData: [] as BNCoin[], })
refreshInterval: 10_000,
isPaused: () => !account?.id || !user,
revalidateOnFocus: false,
},
)
} }