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

Don't Merge Only for testing issue 4449 #4590

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
46 changes: 13 additions & 33 deletions src/components/views/donate/OnTime/DonateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -150,38 +148,20 @@ const DonateModal: FC<IDonateModalProps> = 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 = () => {
Expand Down
27 changes: 26 additions & 1 deletion src/components/views/donate/OnTime/OneTimeDonationCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<boolean>(false);
const [acceptedChains, setAcceptedChains] = useState<INetworkIdWithChain[]>(
[],
);
Expand Down Expand Up @@ -141,6 +144,10 @@ const CryptoDonation: FC<{
address => address.chainType === ChainType.STELLAR,
);

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

useEffect(() => {
if (
(networkId ||
Expand Down Expand Up @@ -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,
Expand All @@ -325,13 +343,20 @@ const CryptoDonation: FC<{

return (
<MainContainer>
{isSanctioned && (
<SanctionModal
closeModal={() => {
setIsSanctioned(false);
}}
/>
)}
{showQFModal && (
<QFModal
donateWithoutMatching={donateWithoutMatching}
setShowModal={setShowQFModal}
/>
)}
{showChangeNetworkModal && acceptedChains && (
{!isSanctioned && showChangeNetworkModal && acceptedChains && (
<DonateWrongNetwork
setShowModal={setShowChangeNetworkModal}
acceptedChains={acceptedChains.filter(
Expand Down
2 changes: 1 addition & 1 deletion src/services/donation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ export async function isWalletSanctioned(

// Check the response and determine if the address is sanctioned
const result = data && data[0];
return Boolean(result && result.isSanctioned);
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hardcoded return value in isWalletSanctioned.

The function now always returns true, indicating that every wallet is sanctioned. This change is suitable for testing purposes but should be reverted before merging to ensure correct functionality.

-		return true;
+		return result?.isSanctioned || false;
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
return true;
return result?.isSanctioned || false;

} catch (error) {
console.error('Error checking wallet sanction status:', error);
return false;
Expand Down
Loading