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 { 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(
|
||||||
() =>
|
() =>
|
||||||
|
iterateContractQuery(() =>
|
||||||
client.userUnclaimedRewards({
|
client.userUnclaimedRewards({
|
||||||
user,
|
user: ENV.ADDRESS_CREDIT_MANAGER,
|
||||||
accountId,
|
accountId,
|
||||||
limit: 100,
|
|
||||||
}),
|
}),
|
||||||
|
),
|
||||||
unclaimedRewardsCache,
|
unclaimedRewardsCache,
|
||||||
`incentives/${accountId}`,
|
`incentives/${accountId}`,
|
||||||
60,
|
60,
|
||||||
|
@ -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'}
|
||||||
|
@ -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}`,
|
|
||||||
() => getUnclaimedRewards(user ?? '', account?.id ?? ''),
|
|
||||||
{
|
|
||||||
fallbackData: [] as BNCoin[],
|
fallbackData: [] as BNCoin[],
|
||||||
refreshInterval: 10_000,
|
isPaused: () => !accountId,
|
||||||
isPaused: () => !account?.id || !user,
|
|
||||||
revalidateOnFocus: false,
|
revalidateOnFocus: false,
|
||||||
},
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user