Skip to content

Commit

Permalink
feat: refetch logic in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
aziolek committed Sep 27, 2024
1 parent 7538d88 commit ee446fc
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,53 @@
import React, { FC, useState } from 'react';
import React, { FC, useEffect, useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { useAccount } from 'wagmi';

import BoxRounded from 'components/ui/BoxRounded';
import Button from 'components/ui/Button';
import InputCheckbox from 'components/ui/InputCheckbox';
import { ROOT_ROUTES } from 'routes/RootRoutes/routes';
import { GITCOIN_PASSPORT_CUSTOM_OCTANT_DASHBOARD } from 'constants/urls';
import useRefreshAntisybilStatus from 'hooks/mutations/useRefreshAntisybilStatus';
import useCurrentEpoch from 'hooks/queries/useCurrentEpoch';
import useUqScore from 'hooks/queries/useUqScore';

import styles from './AllocationLowUqScore.module.scss';
import AllocationLowUqScoreProps from './types';

const AllocationLowUqScore: FC<AllocationLowUqScoreProps> = ({ onAllocate }) => {
const { t } = useTranslation('translation', { keyPrefix: 'views.allocation.lowUQScoreModal' });
const [isChecked, setIsChecked] = useState(false);
const navigate = useNavigate();

const { address } = useAccount();

const { data: currentEpoch } = useCurrentEpoch();
const { refetch: refetchUqScore, isFetching: isFetchingUqScore } = useUqScore(currentEpoch!);
const { mutateAsync: refreshAntisybilStatus, isPending: isPendingRefreshAntisybilStatus } =
useRefreshAntisybilStatus();

const windowOnFocus = () => {
if (!address) {
return;
}
refreshAntisybilStatus(address).then(() => {
refetchUqScore();
// And then what? Discussion in Linear.
});
};

const windowOnBlur = () => setInterval(() => {});

useEffect(() => {
window.addEventListener('focus', windowOnFocus);
window.addEventListener('blur', windowOnBlur);

return () => {
window.removeEventListener('focus', windowOnFocus);
window.removeEventListener('blur', windowOnBlur);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const isFetching = isFetchingUqScore || isPendingRefreshAntisybilStatus;

return (
<>
Expand All @@ -31,12 +65,12 @@ const AllocationLowUqScore: FC<AllocationLowUqScoreProps> = ({ onAllocate }) =>
<label className={styles.checkboxLabel}>{t('checkboxLabel')}</label>
</BoxRounded>
<div className={styles.buttonsContainer}>
<Button className={styles.button} onClick={() => navigate(ROOT_ROUTES.settings.absolute)}>
{t('goToUQSettings')}
<Button className={styles.button} to={GITCOIN_PASSPORT_CUSTOM_OCTANT_DASHBOARD}>
{t('goToGitcoinPassportCustomOctantDashboard')}
</Button>
<Button
className={styles.button}
isDisabled={!isChecked}
isDisabled={!isChecked || isFetching}
onClick={onAllocate}
variant="cta"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ const AllocationTipTiles: FC<AllocationTipTilesProps> = ({ className }) => {
!!isDecisionWindowOpen &&
!isPendingRefreshAntisybilStatus &&
!isFetchingUqScore &&
uqScore === 20n &&
!!uqScore &&
uqScore < 100n &&
!wasUqTooLowAlreadyClosed;

const isRewardsTipVisible =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ const EarnRewardsCalculator: FC = () => {
showCryptoSuffix: true,
valueCrypto:
(parseUnitsBigInt(calculateRewards.matchedFunding, 'wei') *
(formik.values.isUQScoreGivingMultiplier1 ? 100n : 20n)) /
// With QF, multiplier UQ multiplier 0.01 gives the real MR multiplier 0.1
(formik.values.isUQScoreGivingMultiplier1 ? 100n : 10n)) /
100n,
})
: undefined;
Expand Down
10 changes: 5 additions & 5 deletions client/src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,11 @@
"views": {
"allocation": {
"lowUQScoreModal": {
"header": "Your UQ score is too low!",
"text": "If you allocate with this UQ score, you will receive <0>80% less match funding</0> than if you are verified. You cannot change this after allocation. Are you sure you want to proceed?",
"checkboxLabel": "I understand I will receive 20% of the maximum match funding",
"goToUQSettings": "Go to UQ Settings",
"proceedToAllocate": "Proceed to allocate"
"header": "Your UQ score is below 15",
"text": "A Gitcoin Passport score of 15 or over will boost your match funding by 10x. To increase your score, visit the custom GP dashboard below to add more stamps before you allocate.",
"checkboxLabel": "I understand I will only receive 10% of the max. match funding",
"goToGitcoinPassportCustomOctantDashboard": "Go to GP dashboard",
"proceedToAllocate": "Allocate anyway"
},
"multisigSignatureToast": {
"title": "Multi-sig: signature needed",
Expand Down
8 changes: 5 additions & 3 deletions client/src/views/AllocationView/AllocationView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const AllocationView = (): ReactElement => {
isFetching: isFetchingUserNonce,
refetch: refetchUserAllocationNonce,
} = useUserAllocationNonce();
const { data: uqScore } = useUqScore(currentEpoch!);
const { data: uqScore, isFetching: isFetchingUqScore } = useUqScore(currentEpoch!);
const { refetch: refetchMatchedProjectRewards } = useMatchedProjectRewards();
const [showLowUQScoreModal, setShowLowUQScoreModal] = useState(false);
const { refetch: refetchEpochAllocations } = useEpochAllocations(
Expand Down Expand Up @@ -283,7 +283,8 @@ const AllocationView = (): ReactElement => {

if (
!userAllocations?.hasUserAlreadyDoneAllocation &&
uqScore === 20n &&
uqScore &&
uqScore < 100n &&
!isProceedingToAllocateWithLowUQScore
) {
setShowLowUQScoreModal(true);
Expand All @@ -295,7 +296,7 @@ const AllocationView = (): ReactElement => {
}

// this condition must always be last due to ModalAllocationLowUqScore
// if uqScore == 20n, the signature request is triggered in ModalAllocationLowUqScore
// if uqScore == 1n, the signature request is triggered in ModalAllocationLowUqScore
if (isContract) {
setIsWaitingForFirstMultisigSignature(true);
toastService.showToast({
Expand Down Expand Up @@ -429,6 +430,7 @@ const AllocationView = (): ReactElement => {
allocationValues === undefined ||
(isConnected && isFetchingUserNonce) ||
(isConnected && isFetchingUserAllocation) ||
(isConnected && isFetchingUqScore) ||
(isFetchingUpcomingBudget && !isRefetchingUpcomingBudget);

const areAllocationsAvailableOrAlreadyDone =
Expand Down

0 comments on commit ee446fc

Please sign in to comment.