Skip to content

Commit 671d698

Browse files
authored
OCT-1779 Allocation tip tiles - refresh antisybil status before showing tip tiles (#319)
2 parents 84e3831 + 3f679e4 commit 671d698

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

client/src/components/Allocation/AllocationTipTiles/AllocationTipTiles.tsx

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import React, { FC, Fragment } from 'react';
1+
import React, { FC, Fragment, useEffect } from 'react';
22
import { Trans, useTranslation } from 'react-i18next';
33
import { useNavigate } from 'react-router-dom';
44
import { useAccount } from 'wagmi';
55

66
import TipTile from 'components/shared/TipTile';
77
import useMediaQuery from 'hooks/helpers/useMediaQuery';
8+
import useRefreshAntisybilStatus from 'hooks/mutations/useRefreshAntisybilStatus';
89
import useCurrentEpoch from 'hooks/queries/useCurrentEpoch';
910
import useIndividualReward from 'hooks/queries/useIndividualReward';
1011
import useIsDecisionWindowOpen from 'hooks/queries/useIsDecisionWindowOpen';
@@ -20,12 +21,26 @@ const AllocationTipTiles: FC<AllocationTipTilesProps> = ({ className }) => {
2021
const { t, i18n } = useTranslation('translation', { keyPrefix: 'views.allocation.tip' });
2122
const navigate = useNavigate();
2223
const { isDesktop } = useMediaQuery();
23-
const { isConnected } = useAccount();
24+
const { address, isConnected } = useAccount();
25+
const {
26+
mutateAsync: refreshAntisybilStatus,
27+
isPending: isPendingRefreshAntisybilStatus,
28+
isSuccess: isSuccessRefreshAntisybilStatus,
29+
error: refreshAntisybilStatusError,
30+
} = useRefreshAntisybilStatus();
2431
const { data: currentEpoch } = useCurrentEpoch();
2532
const { data: isDecisionWindowOpen } = useIsDecisionWindowOpen();
2633
const { data: individualReward, isFetching: isFetchingIndividualReward } = useIndividualReward();
2734
const { data: userAllocations, isFetching: isFetchingUserAllocation } = useUserAllocations();
28-
const { data: uqScore } = useUqScore(isDecisionWindowOpen ? currentEpoch! - 1 : currentEpoch!);
35+
const { data: uqScore, isFetching: isFetchingUqScore } = useUqScore(
36+
isDecisionWindowOpen ? currentEpoch! - 1 : currentEpoch!,
37+
{
38+
enabled:
39+
isSuccessRefreshAntisybilStatus ||
40+
(refreshAntisybilStatusError as null | { message: string })?.message ===
41+
'Address is already used for delegation',
42+
},
43+
);
2944
const {
3045
wasRewardsAlreadyClosed,
3146
setWasRewardsAlreadyClosed,
@@ -40,10 +55,29 @@ const AllocationTipTiles: FC<AllocationTipTilesProps> = ({ className }) => {
4055
wasUqTooLowAlreadyClosed: state.data.wasUqTooLowAlreadyClosed,
4156
}));
4257

58+
useEffect(() => {
59+
if (!address) {
60+
return;
61+
}
62+
/**
63+
* The initial value of UQ for every user is 0.2.
64+
* It does not update automatically after delegation nor after change in Gitcoin Passport itself.
65+
*
66+
* We need to refreshAntisybilStatus to force BE to refetch current values from Gitcoin Passport
67+
* and return true value.
68+
*/
69+
refreshAntisybilStatus(address!);
70+
// eslint-disable-next-line react-hooks/exhaustive-deps
71+
}, []);
72+
4373
const isEpoch1 = currentEpoch === 1;
4474

4575
const isUqTooLowTipVisible =
46-
!!isDecisionWindowOpen && uqScore === 20n && !wasUqTooLowAlreadyClosed;
76+
!!isDecisionWindowOpen &&
77+
!isPendingRefreshAntisybilStatus &&
78+
!isFetchingUqScore &&
79+
uqScore === 20n &&
80+
!wasUqTooLowAlreadyClosed;
4781

4882
const isRewardsTipVisible =
4983
!isEpoch1 &&

0 commit comments

Comments
 (0)