fix: fixed the rewards center (#524)
This commit is contained in:
parent
7864b579cf
commit
8a71f4664a
@ -1,20 +1,20 @@
|
||||
import { cacheFn, unclaimedRewardsCache } from 'api/cache'
|
||||
import { getIncentivesQueryClient } from 'api/cosmwasm-client'
|
||||
import { ENV } from 'constants/env'
|
||||
import { BNCoin } from 'types/classes/BNCoin'
|
||||
import iterateContractQuery from 'utils/iterateContractQuery'
|
||||
|
||||
export default async function getUnclaimedRewards(
|
||||
user: string,
|
||||
accountId: string,
|
||||
): Promise<BNCoin[]> {
|
||||
export default async function getUnclaimedRewards(accountId: string): Promise<BNCoin[]> {
|
||||
try {
|
||||
const client = await getIncentivesQueryClient()
|
||||
const unclaimedRewards = await cacheFn(
|
||||
() =>
|
||||
client.userUnclaimedRewards({
|
||||
user,
|
||||
accountId,
|
||||
limit: 100,
|
||||
}),
|
||||
iterateContractQuery(() =>
|
||||
client.userUnclaimedRewards({
|
||||
user: ENV.ADDRESS_CREDIT_MANAGER,
|
||||
accountId,
|
||||
}),
|
||||
),
|
||||
unclaimedRewardsCache,
|
||||
`incentives/${accountId}`,
|
||||
60,
|
||||
|
@ -31,10 +31,10 @@ const renderIncentives = (unclaimedRewards: BNCoin[]) => {
|
||||
const asset = ASSETS.find(byDenom(reward.denom))
|
||||
if (!asset) return null
|
||||
return (
|
||||
<>
|
||||
<div className='w-full' key={index}>
|
||||
{index !== 0 && <Divider />}
|
||||
<AssetBalanceRow key={reward.denom} coin={reward} asset={asset} />
|
||||
</>
|
||||
</div>
|
||||
)
|
||||
})
|
||||
}
|
||||
@ -109,7 +109,7 @@ export default function RewardsCenter() {
|
||||
<>
|
||||
<Button
|
||||
variant='solid'
|
||||
color='secondary'
|
||||
color='tertiary'
|
||||
className='w-full py-2'
|
||||
showProgressIndicator={isConfirming}
|
||||
text={'Claim total account rewards'}
|
||||
|
@ -1,22 +1,15 @@
|
||||
import useSWR from 'swr'
|
||||
|
||||
import getUnclaimedRewards from 'api/incentives/getUnclaimedRewards'
|
||||
import useCurrentAccount from 'hooks/useCurrentAccount'
|
||||
import useStore from 'store'
|
||||
import useAccountId from 'hooks/useAccountId'
|
||||
import { BNCoin } from 'types/classes/BNCoin'
|
||||
|
||||
export default function useUserUnclaimedRewards() {
|
||||
const user = useStore((s) => s.address)
|
||||
const account = useCurrentAccount()
|
||||
const accountId = useAccountId()
|
||||
|
||||
return useSWR(
|
||||
`userUnclaimedRewards-${account?.id}`,
|
||||
() => getUnclaimedRewards(user ?? '', account?.id ?? ''),
|
||||
{
|
||||
fallbackData: [] as BNCoin[],
|
||||
refreshInterval: 10_000,
|
||||
isPaused: () => !account?.id || !user,
|
||||
revalidateOnFocus: false,
|
||||
},
|
||||
)
|
||||
return useSWR(`userUnclaimedRewards-${accountId}`, () => getUnclaimedRewards(accountId ?? ''), {
|
||||
fallbackData: [] as BNCoin[],
|
||||
isPaused: () => !accountId,
|
||||
revalidateOnFocus: false,
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user