Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: network modal showing while the page is loading #4711

Merged
merged 20 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a39b561
fix: network modal showing while the page is loading
HrithikSampson Sep 10, 2024
d305aaa
keep the sanctions modal until the page has redirected to all pages
HrithikSampson Sep 10, 2024
7d78930
fix: run linter
HrithikSampson Sep 10, 2024
db131da
Merge branch 'develop' of github.com:Giveth/giveth-dapps-v2 into fix_…
HrithikSampson Sep 12, 2024
69eaf28
fix: multiple donation modal shown together
HrithikSampson Sep 12, 2024
ff6405e
add OFAC Sanction Modal
HrithikSampson Sep 12, 2024
d502cec
fix; Donate Modals glitching effect
HrithikSampson Sep 21, 2024
edaa8a5
chore: fix build errors
HrithikSampson Sep 21, 2024
34829fe
fix: OFAC Sanction Modal Check
HrithikSampson Sep 21, 2024
3c6e005
fix: coderabbitai suggestions
HrithikSampson Sep 23, 2024
76c0908
Merge branch 'develop' of github.com:Giveth/giveth-dapps-v2 into fix_…
HrithikSampson Sep 23, 2024
f1fe063
manually revet coderabbit suggestions as it is causing glitching again
HrithikSampson Sep 23, 2024
a842504
run linter
HrithikSampson Sep 23, 2024
e803c77
fix: timeout to add check of the modals later
HrithikSampson Sep 24, 2024
73c22b4
Merge branch 'develop' of github.com:Giveth/giveth-dapps-v2 into fix_…
HrithikSampson Sep 26, 2024
d0ba7ce
Merge branch 'develop' of github.com:Giveth/giveth-dapps-v2 into fix_…
HrithikSampson Sep 26, 2024
969417a
run linter:
HrithikSampson Sep 26, 2024
593d3d4
fix: for non-endaoment project modal
HrithikSampson Sep 26, 2024
c7854e2
run linter
HrithikSampson Sep 26, 2024
3b90b81
Merge branch 'develop' of github.com:Giveth/giveth-dapps-v2 into fix_…
HrithikSampson Sep 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions lang/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,6 @@
"label.qf_eligibility": "Actualment en ronda de QF",
"label.qf_no_donations": "No hi ha hagut donacions en aquesta ronda.",
"label.qf_round_projects": "Projectes de la ronda QF",
"label.qr_code_error": "S'ha produït un error en generar el codi QR. Torneu-ho a provar.",
"label.qr_code_expired": "El codi QR ha caducat, sol·licita un nou codi QR!",
"label.quadratic_funding": "Finançament quadràtic",
"label.questions_contact_support": "Preguntes? Contacta amb el Suport",
Expand Down Expand Up @@ -1135,7 +1134,6 @@
"label.to_participate_for_real_claim_your_giv": "Per participar de veritat, reclama el teu GIV.",
"label.to_see_your_givpower_please_connect": "Per veure el teu GIVpower, si us plau connecta la teva cartera.",
"label.traceable_project": "Projecte Traçable",
"label.transaction_detail": "Detall de la transacció",
"label.transaction_link": "Enllaç de la transacció",
"label.transaction_status": "Estat de la transacció",
"label.trust_that_your_donations_will_make": "Confia que les teves donacions en cripto tindran un impacte amb el nostre sistema de verificació.",
Expand Down Expand Up @@ -1358,14 +1356,10 @@
"page.donate.passport_toast.description.not_connected": "Obtén el teu emparellament de donació amb finançament quadràtic!\nVerifica el teu Gitcoin Passport abans de",
"page.donate.passport_toast.title.eligible": "Finançament Quadràtic",
"page.donate.passport_toast.title.non_eligible": "No et perdis l'emparellament!",
"page.donate.title": "Donar",
"page.donate.zero_fees": "Sense Comissions",
"page.donate.makes_you_eligible_for_givbacks": "${value} et fan elegible per a GIVbacks",
"page.donate.unlocks_matching_funds": "${value} desbloquegen fons coincidents",
"page.donate.donations_will_be_matched": "La donació serà igualada",
"page.donate.project_not_eligible_for_qf": "El projecte no és elegible per a la concordança QF.",
"page.donate.network_not_eligible_for_qf": "Les donacions de {network} no són aptes per coincidir",
"page.donate.givbacks_eligible": "GIVbacks elegibles",
"page.donate.project_not_givbacks_eligible": "El projecte no és elegible per a GIVbacks",
"page.donate.title": "Donar",
"page.donate.token_not_givbacks_eligible": "{token} no és apte per a GIVbacks",
Expand Down Expand Up @@ -1669,9 +1663,7 @@
"project.givback_toast.description.non_verified_public": "Actualment, els GIVbacks només s'atorguen per donacions fetes a projectes elegibles per a GIVbacks a Ethereum. La teva contribució segueix sent important, fins i tot si no genera GIVbacks!",
"project.givback_toast.description.verified_owner": "Potencia el teu projecte per augmentar el seu percentatge de GIVbacks i ajudar-lo a aparèixer més amunt a la pàgina de projectes!",
"project.givback_toast.description.verified_public": "Les donacions a Ethereum a projectes elegibles per a GIVbacks són recompensades amb GIV. Impulsa aquest projecte per augmentar el seu percentatge de recompenses i fer-lo més visible a la pàgina de projectes!", "project.givback_toast.title.non_verified_owner": "El teu projecte està creant o donant suport a béns públics?",
"project.givback_toast.description.verified_public": "Les donacions de ${value} o més són elegibles per a GIVback. Potencia aquest projecte per augmentar el seu percentatge de recompenses i la seva visibilitat a la pàgina de projectes!",
"project.givback_toast.description.verified_owner_not_eligible": "El teu projecte ha estat avalat pels Verificadors de Giveth i ara pot beneficiar-se de GIVpower. Fes stake i bloqueja els teus tokens GIV per impulsar aquest projecte i fer-lo més visible a la pàgina de projectes. No obstant això, donar a aquest projecte no generarà GIVbacks per als donants.",
"project.givback_toast.title.non_verified_owner": "El teu projecte està creant o donant suport a béns públics?",
"project.givback_toast.title.non_verified_owner_cancelled": "Estat Cancel·lat",
"project.givback_toast.title.non_verified_owner_deactive": "Mode Desactivat",
"project.givback_toast.title.non_verified_owner_draft": "Publica el teu projecte avui!",
Expand Down
8 changes: 0 additions & 8 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -890,9 +890,6 @@
"label.runout_info": "Stream Balance will run out funds on ",
"label.runout_info_topup": "Top-up before then!",
"label.runs_out_in": "Runs out in",
"label.sanctioned_wallet": "Sanctioned Address Detected !!",
"label.sanctioned_wallet_message_part1": "This address has been found on the USA",
"label.sanctioned_wallet_message_part2": "sanctioned list.\nUnfortunately, Endaoment does not permit addresses on the\nOFAC sanction list to donate to projects delivered by\nEndaoment. Check out another project to donate to. ",
"label.save": "Save",
"label.save_changes": "Save Changes",
"label.save_on_gas_fees": "Save on gas fees, switch network.",
Expand Down Expand Up @@ -1188,7 +1185,6 @@
"label.verify_your_project.modal.three": "GIVbacks eligibility process ",
"label.verify_your_project.modal.two": "This simple ",
"label.view": "View",
"label.view_all_projects": "View all projects",
"label.view_details": "View details",
"label.view_more": "View more",
"label.view_on_block_explorer": "View on block explorer",
Expand Down Expand Up @@ -1349,8 +1345,6 @@
"page.donate.bank_fees": "Bank Fees",
"page.donate.donate_$_to_be_eligible": "Donate ${value} to be eligible for GIVbacks",
"page.donate.donate_$_to_get_matched": "Donate ${value} to get your donation matched",
"page.donate.donations_will_be_matched": "Donation will be matched",
"page.donate.givbacks_eligible": "GIVbacks eligible",
"page.donate.matching_toast.bottom_invalid_p1": "Only donations more than",
"page.donate.matching_toast.bottom_invalid_p2": "are eligible for matching.",
"page.donate.matching_toast.bottom_valid": "Matching funds will be sent to the selected project after the round ends. Donate to more projects to receive higher matching!",
Expand All @@ -1360,8 +1354,6 @@
"page.donate.passport_toast.description.not_connected": "Get your donation matched with quadratic funding!\nVerify your Gitcoin Passport before",
"page.donate.passport_toast.title.eligible": "Quadratic Funding",
"page.donate.passport_toast.title.non_eligible": "Don’t miss out on matching!",
"page.donate.title": "Donate",
"page.donate.zero_fees": "Zero Fees",
"page.donate.makes_you_eligible_for_givbacks": "${value} makes you eligible for GIVbacks",
"page.donate.unlocks_matching_funds": "${value} unlocks matching funds",
"page.donate.donations_will_be_matched": "Donation will be matched",
Expand Down
4 changes: 0 additions & 4 deletions lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1345,8 +1345,6 @@
"page.donate.bank_fees": "Comisiones Bancarias",
"page.donate.donate_$_to_be_eligible": "Dona ${value} para ser elegible para GIVbacks",
"page.donate.donate_$_to_get_matched": "Dona ${value} para que tu donación sea igualada",
"page.donate.donations_will_be_matched": "La donación será igualada",
"page.donate.givbacks_eligible": "Elegibles para GIVbacks",
"page.donate.matching_toast.bottom_invalid_p1": "Sólo las donaciones superiores a",
"page.donate.matching_toast.bottom_invalid_p2": "son subvencionables.",
"page.donate.matching_toast.bottom_valid": "Los fondos de emparejamiento se enviarán al proyecto seleccionado después de que termine la ronda. ¡Dona a más proyectos para recibir un mayor emparejamiento!",
Expand All @@ -1356,9 +1354,7 @@
"page.donate.passport_toast.description.not_connected": "¡Haz que tu donación sea complementada con financiamiento cuadrático! Verifica tu Gitcoin Passport antes de",
"page.donate.passport_toast.title.eligible": "Financiamiento Cuadrático",
"page.donate.passport_toast.title.non_eligible": "¡No te pierdas la oportunidad!",
"page.donate.project_not_givbacks_eligible": "El proyecto no es elegible para GIVbacks",
"page.donate.title": "Donar",
"page.donate.token_not_givbacks_eligible": "{token} no es elegible para GIVbacks",
"page.donate.zero_fees": "Sin Comisiones",
"page.donate.makes_you_eligible_for_givbacks": "${value} te hacen elegible para recibir GIVbacks",
"page.donate.unlocks_matching_funds": "${value} desbloquean fondos equivalentes",
Expand Down
26 changes: 18 additions & 8 deletions src/components/modals/DonationByProjectOwner.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import {
brandColors,
Button,
Expand All @@ -12,27 +12,37 @@ import { useRouter } from 'next/router';
import { Modal } from '@/components/modals/Modal';
import Routes from '@/lib/constants/Routes';
import { mediaQueries } from '@/lib/constants/constants';
import { useModalAnimation } from '@/hooks/useModalAnimation';

// Define the props interface
interface DonationByProjectOwnerProps {
setShowDonationByProjectOwner: (
showDonationByProjectOwner: boolean,
) => void;
closeModal: () => void;
}

export const DonationByProjectOwner: React.FC<DonationByProjectOwnerProps> = ({
setShowDonationByProjectOwner,
closeModal,
}) => {
const { formatMessage } = useIntl();
const router = useRouter();
const { closeModal } = useModalAnimation(setShowDonationByProjectOwner);
const [isRedirecting, setIsRedirecting] = useState(false);

const navigateToAllProjects = () => {
setIsRedirecting(true);
router.push(Routes.AllProjects);
closeModal();
};

useEffect(() => {
const handleRouteChangeComplete = () => {
closeModal();
setIsRedirecting(false);
};
if (isRedirecting) {
router.events.on('routeChangeComplete', handleRouteChangeComplete);
}
return () => {
router.events.off('routeChangeComplete', handleRouteChangeComplete);
};
}, [isRedirecting]);

return (
<Modal
closeModal={closeModal}
Expand Down
18 changes: 16 additions & 2 deletions src/components/modals/SanctionedModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import {
brandColors,
Button,
Expand All @@ -21,12 +21,26 @@ interface SanctionModalProps {

export const SanctionModal: React.FC<SanctionModalProps> = ({ closeModal }) => {
const { formatMessage } = useIntl();
const [isRedirecting, setIsRedirecting] = useState(false);
const router = useRouter();
const navigateToAllProjects = () => {
setIsRedirecting(true);
router.push(Routes.AllProjects);
closeModal();
};

useEffect(() => {
const handleRouteChangeComplete = () => {
closeModal();
setIsRedirecting(false);
};
if (isRedirecting) {
router.events.on('routeChangeComplete', handleRouteChangeComplete);
}
return () => {
router.events.off('routeChangeComplete', handleRouteChangeComplete);
};
}, [isRedirecting]);

return (
<Modal
closeModal={closeModal}
Expand Down
89 changes: 71 additions & 18 deletions src/components/views/donate/DonateIndex.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, useEffect, useState } from 'react';
import React, { FC, useEffect } from 'react';
import styled from 'styled-components';
import {
Col,
Expand All @@ -20,7 +20,10 @@ import SocialBox from '../../DonateSocialBox';
import NiceBanner from './NiceBanner';
import useDetectDevice from '@/hooks/useDetectDevice';
import { useIsSafeEnvironment } from '@/hooks/useSafeAutoConnect';
import { useDonateData } from '@/context/donate.context';
import {
DonateModalPriorityValues,
useDonateData,
} from '@/context/donate.context';
import { EContentType } from '@/lib/constants/shareContent';
import { useAlreadyDonatedToProject } from '@/hooks/useAlreadyDonatedToProject';
import { Shadow } from '@/components/styled-components/Shadow';
Expand All @@ -45,6 +48,8 @@ import EndaomentProjectsInfo from '@/components/views/project/EndaomentProjectsI
import { IDraftDonation } from '@/apollo/types/gqlTypes';
import StorageLabel from '@/lib/localStorage';
import DonationByProjectOwner from '@/components/modals/DonationByProjectOwner';
import { isWalletSanctioned } from '@/services/donation';
import SanctionModal from '@/components/modals/SanctionedModal';
import { PassportBanner } from '@/components/PassportBanner';
import QFEligibleNetworks from '@/components/views/donate/QFEligibleNetworks';
import { GIVBACKS_DONATION_QUALIFICATION_VALUE_USD } from '@/lib/constants/constants';
Expand All @@ -58,21 +63,23 @@ const DonateIndex: FC = () => {
qrDonationStatus,
draftDonationData,
hasActiveQFRound,
shouldRenderModal,
setSuccessDonation,
setQRDonationStatus,
setDraftDonationData,
setPendingDonationExists,
activeStartedRound,
startTimer,
setDonateModalByPriority,
setIsModalPriorityChecked,
} = useDonateData();
const { renewExpirationDate, retrieveDraftDonation } =
useQRCodeDonation(project);
const { isSignedIn, isEnabled } = useAppSelector(state => state.user);

const alreadyDonated = useAlreadyDonatedToProject(project);
const { userData } = useAppSelector(state => state.user);
const [showDonationByProjectOwner, setShowDonationByProjectOwner] =
useState<boolean | undefined>(false);

const dispatch = useAppDispatch();
const isSafeEnv = useIsSafeEnvironment();
const { isOnSolana } = useGeneralWallet();
Expand All @@ -81,6 +88,7 @@ const DonateIndex: FC = () => {
const [showQRCode, setShowQRCode] = React.useState(
!!router.query.draft_donation,
);
const { walletAddress: address } = useGeneralWallet();
const [stopTimer, setStopTimer] = React.useState<void | (() => void)>();

const isQRDonation = router.query.chain === ChainType.STELLAR.toLowerCase();
Expand All @@ -96,9 +104,37 @@ const DonateIndex: FC = () => {
};
}, [dispatch]);

const validateSanctions = async () => {
if (project.organization?.label === 'endaoment' && address) {
// We just need to check if the wallet is sanctioned for endaoment projects
const sanctioned = await isWalletSanctioned(address);
if (sanctioned) {
setDonateModalByPriority(
DonateModalPriorityValues.OFACSanctionListModal,
);
return;
}
}
setIsModalPriorityChecked(
DonateModalPriorityValues.OFACSanctionListModal,
);
};

Comment on lines +107 to +121
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle potential errors from isWalletSanctioned API call

In the validateSanctions function, the asynchronous call to isWalletSanctioned(address) may fail due to network errors or other issues. To ensure the application remains stable, consider wrapping the API call in a try-catch block to handle any potential exceptions.

Apply this diff to enhance error handling:

const validateSanctions = async () => {
  if (project.organization?.label === 'endaoment' && address) {
+   try {
      // We just need to check if the wallet is sanctioned for endaoment projects
      const sanctioned = await isWalletSanctioned(address);
      if (sanctioned) {
        setDonateModalByPriority(
          DonateModalPriorityValues.OFACSanctionListModal,
        );
        return;
      }
+   } catch (error) {
+     console.error('Error checking wallet sanctions:', error);
+     // Optionally, set an error state or display an error message to the user
+   }
  }
  setIsModalPriorityChecked(
    DonateModalPriorityValues.OFACSanctionListModal,
  );
};
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const validateSanctions = async () => {
if (project.organization?.label === 'endaoment' && address) {
// We just need to check if the wallet is sanctioned for endaoment projects
const sanctioned = await isWalletSanctioned(address);
if (sanctioned) {
setDonateModalByPriority(
DonateModalPriorityValues.OFACSanctionListModal,
);
return;
}
}
setIsModalPriorityChecked(
DonateModalPriorityValues.OFACSanctionListModal,
);
};
const validateSanctions = async () => {
if (project.organization?.label === 'endaoment' && address) {
try {
// We just need to check if the wallet is sanctioned for endaoment projects
const sanctioned = await isWalletSanctioned(address);
if (sanctioned) {
setDonateModalByPriority(
DonateModalPriorityValues.OFACSanctionListModal,
);
return;
}
} catch (error) {
console.error('Error checking wallet sanctions:', error);
// Optionally, set an error state or display an error message to the user
}
}
setIsModalPriorityChecked(
DonateModalPriorityValues.OFACSanctionListModal,
);
};

useEffect(() => {
validateSanctions();
}, [project, address]);

useEffect(() => {
setShowDonationByProjectOwner(
userData?.id !== undefined && userData?.id === project.adminUser.id,
if (
userData?.id !== undefined &&
userData?.id === project.adminUser.id
) {
setDonateModalByPriority(
DonateModalPriorityValues.DonationByProjectOwner,
);
}
setIsModalPriorityChecked(
DonateModalPriorityValues.DonationByProjectOwner,
);
}, [userData?.id, project.adminUser]);

Expand Down Expand Up @@ -136,7 +172,7 @@ const DonateIndex: FC = () => {
excludeFromQF: !includeInQF,
givBackEligible:
isTokenEligibleForGivback &&
project.isGivbackEligible &&
project.verified &&
isSignedIn &&
isEnabled &&
getDonationById.amount >=
Expand Down Expand Up @@ -239,21 +275,31 @@ const DonateIndex: FC = () => {
<>
<DonateHeader />
<Wrapper>
{!isSafeEnv &&
hasActiveQFRound &&
!isOnSolana &&
(!isQRDonation ||
(isQRDonation && isStellarIncludedInQF)) && (
<PassportBanner />
)}
<DonateContainer>
{showDonationByProjectOwner && (
{shouldRenderModal(
DonateModalPriorityValues.DonationByProjectOwner,
) && (
<DonationByProjectOwner
setShowDonationByProjectOwner={
setShowDonationByProjectOwner
}
closeModal={() => {
setDonateModalByPriority(
DonateModalPriorityValues.None,
);
}}
/>
)}

{shouldRenderModal(
DonateModalPriorityValues.OFACSanctionListModal,
) && (
<SanctionModal
closeModal={() => {
setDonateModalByPriority(
DonateModalPriorityValues.None,
);
}}
/>
)}

{showAlreadyDonatedWrapper && (
<AlreadyDonatedWrapper>
<IconDonation24 />
Expand All @@ -264,6 +310,13 @@ const DonateIndex: FC = () => {
</SublineBold>
</AlreadyDonatedWrapper>
)}
{!isSafeEnv &&
hasActiveQFRound &&
!isOnSolana &&
(!isQRDonation ||
(isQRDonation && isStellarIncludedInQF)) && (
<PassportBanner />
)}
<NiceBanner />
<Row>
<Col xs={12} lg={6}>
Expand Down
1 change: 0 additions & 1 deletion src/components/views/donate/DonationCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export const DonationCard: FC<IDonationCardProps> = ({
address.networkId === config.OPTIMISM_NETWORK_NUMBER,
);
const isEndaomentProject = project?.organization?.label === 'endaoment';

const isOwnerOnEVM =
project?.adminUser?.walletAddress &&
isAddress(project.adminUser?.walletAddress);
Expand Down
Loading
Loading