Skip to content

Commit

Permalink
Merge pull request #628 from subquery/fix/collect-wait
Browse files Browse the repository at this point in the history
fix: collect cache
  • Loading branch information
HuberTRoy authored Jan 2, 2024
2 parents 7bf64a3 + ae43ae6 commit 4a1903a
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/hooks/useRewardCollectStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2020-2022 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { cachedResult, limitContract, limitQueue, makeCacheKey } from '@utils/limitation';
import { limitContract, makeCacheKey } from '@utils/limitation';

import { useWeb3Store } from 'src/stores';

Expand All @@ -15,22 +15,20 @@ export function useRewardCollectStatus(indexer: string): AsyncMemoReturn<{ hasCl

return useAsyncMemo(async () => {
if (!contracts) return;
const lastClaimedEra =
cachedResult.get(lastClaimedKey) ||
(await limitQueue.add(() => contracts.rewardsDistributor.getRewardInfo(indexer)));
const lastSettledEra =
cachedResult.get(lastSettledKey) ||
(await limitQueue.add(() => contracts.rewardsStaking.getLastSettledEra(indexer)));

cachedResult.set(lastClaimedKey, lastClaimedEra);
cachedResult.set(lastSettledKey, lastSettledEra);
const lastClaimedEra = await limitContract(
() => contracts.rewardsDistributor.getRewardInfo(indexer),
lastClaimedKey,
);
const lastSettledEra = await limitContract(
() => contracts.rewardsStaking.getLastSettledEra(indexer),
lastSettledKey,
);

const currentEra = await limitContract(() => contracts.eraManager.eraNumber(), makeCacheKey('eraNumber'));

if (lastClaimedEra && lastSettledEra && currentEra) {
const rewardClaimStatus =
currentEra.eq(lastClaimedEra.lastClaimEra.add(1)) && lastSettledEra.lte(lastClaimedEra.lastClaimEra);

return { hasClaimedRewards: rewardClaimStatus };
}
}, [contracts]);
Expand Down

0 comments on commit 4a1903a

Please sign in to comment.