diff --git a/src/components/views/donate/OnTime/DonateModal.tsx b/src/components/views/donate/OnTime/DonateModal.tsx index 6c11bb30d3..ec16eb5bb5 100644 --- a/src/components/views/donate/OnTime/DonateModal.tsx +++ b/src/components/views/donate/OnTime/DonateModal.tsx @@ -40,9 +40,7 @@ import { calcDonationShare } from '@/components/views/donate/helpers'; import { Spinner } from '@/components/Spinner'; import { FETCH_GIVETH_PROJECT_BY_ID } from '@/apollo/gql/gqlProjects'; import createGoogleTagEventPurchase from '@/helpers/googleAnalytics'; -import { isWalletSanctioned } from '@/services/donation'; import SanctionModal from '@/components/modals/SanctionedModal'; -import { ORGANIZATION } from '@/lib/constants/organizations'; interface IDonateModalProps extends IModal { token: IProjectAcceptedToken; @@ -150,38 +148,20 @@ const DonateModal: FC = props => { // this function is used to validate the token and check if the wallet is sanctioned const validateTokenThenDonate = async () => { setDonating(true); - try { - if ( - project?.organization?.label === ORGANIZATION.endaoment && - address - ) { - // We just need to check if the wallet is sanctioned for endaoment projects - const sanctioned = await isWalletSanctioned(address); - if (sanctioned) { - setIsSanctioned(true); - setDonating(false); - return; + client + .query({ + query: VALIDATE_TOKEN, + fetchPolicy: 'no-cache', + }) + .then((res: IMeGQL) => { + const _address = res.data?.me?.walletAddress; + if (compareAddresses(_address, address)) { + handleDonate(); + } else { + handleFailedValidation(); } - } - - client - .query({ - query: VALIDATE_TOKEN, - fetchPolicy: 'no-cache', - }) - .then((res: IMeGQL) => { - const _address = res.data?.me?.walletAddress; - if (compareAddresses(_address, address)) { - handleDonate(); - } else { - handleFailedValidation(); - } - }) - .catch(handleFailedValidation); - } catch (error) { - setDonating(false); - showToastError('Error validating wallet address'); - } + }) + .catch(handleFailedValidation); }; const handleFailedValidation = () => { diff --git a/src/components/views/donate/OnTime/OneTimeDonationCard.tsx b/src/components/views/donate/OnTime/OneTimeDonationCard.tsx index 21230d4729..3317519923 100644 --- a/src/components/views/donate/OnTime/OneTimeDonationCard.tsx +++ b/src/components/views/donate/OnTime/OneTimeDonationCard.tsx @@ -54,6 +54,8 @@ import { TokenIcon } from '../TokenIcon/TokenIcon'; import { SelectTokenModal } from './SelectTokenModal/SelectTokenModal'; import { Spinner } from '@/components/Spinner'; import { useSolanaBalance } from '@/hooks/useSolanaBalance'; +import { isWalletSanctioned } from '@/services/donation'; +import SanctionModal from '@/components/modals/SanctionedModal'; const CryptoDonation: FC<{ setIsQRDonation: (isQRDonation: boolean) => void; @@ -90,6 +92,7 @@ const CryptoDonation: FC<{ const [showDonateModal, setShowDonateModal] = useState(false); const [showInsufficientModal, setShowInsufficientModal] = useState(false); const [showChangeNetworkModal, setShowChangeNetworkModal] = useState(false); + const [isSanctioned, setIsSanctioned] = useState(false); const [acceptedChains, setAcceptedChains] = useState( [], ); @@ -141,6 +144,10 @@ const CryptoDonation: FC<{ address => address.chainType === ChainType.STELLAR, ); + useEffect(() => { + validateSanctions(); + }, [project, address]); + useEffect(() => { if ( (networkId || @@ -309,6 +316,17 @@ const CryptoDonation: FC<{ } }, [selectedTokenBalance, amount, selectedOneTimeToken?.address, gasfee]); + 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) { + setIsSanctioned(true); + return; + } + } + }; + const amountErrorText = useMemo(() => { const totalAmount = Number(formatUnits(gasfee, tokenDecimals)).toFixed( 10, @@ -325,13 +343,20 @@ const CryptoDonation: FC<{ return ( + {isSanctioned && ( + { + setIsSanctioned(false); + }} + /> + )} {showQFModal && ( )} - {showChangeNetworkModal && acceptedChains && ( + {!isSanctioned && showChangeNetworkModal && acceptedChains && (