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 small donation amount #4578

Merged
merged 3 commits into from
Aug 30, 2024
Merged
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
8 changes: 8 additions & 0 deletions src/components/views/donate/DonateToGiveth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import CheckBox from '@/components/Checkbox';

interface IDonateToGiveth {
donationToGiveth: number;
givethDonationAmount?: number;
setDonationToGiveth: (donationToGiveth: number) => void;
title: string;
}
Expand All @@ -26,6 +27,7 @@ const givethDonationOptions = [5, 10, 15, 20];

const DonateToGiveth: FC<IDonateToGiveth> = ({
donationToGiveth,
givethDonationAmount,
setDonationToGiveth,
title,
}) => {
Expand All @@ -42,6 +44,12 @@ const DonateToGiveth: FC<IDonateToGiveth> = ({
setDonationToGiveth(e ? 0 : 5);
};

// If givethDonationAmount props provided check if it's 0 and set donationToGiveth to 0
// because we disabled percetange amount for minimal allowed main donation amount
if (givethDonationAmount !== undefined) {
donationToGiveth = givethDonationAmount === 0 ? 0 : donationToGiveth;
}

return (
<Container>
<Flex $alignItems='center' gap='4px'>
Expand Down
4 changes: 3 additions & 1 deletion src/components/views/donate/OnTime/DonateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface IDonateModalProps extends IModal {
token: IProjectAcceptedToken;
amount: bigint;
donationToGiveth: number;
givethDonationAmount: number;
tokenPrice?: number;
anonymous?: boolean;
givBackEligible?: boolean;
Expand All @@ -59,6 +60,7 @@ const DonateModal: FC<IDonateModalProps> = props => {
amount,
setShowModal,
donationToGiveth,
givethDonationAmount,
anonymous,
givBackEligible,
} = props;
Expand Down Expand Up @@ -86,7 +88,7 @@ const DonateModal: FC<IDonateModalProps> = props => {
const chainName = (chain as Chain)?.name;
const dispatch = useAppDispatch();
const { isAnimating, closeModal } = useModalAnimation(setShowModal);
const isDonatingToGiveth = donationToGiveth > 0;
const isDonatingToGiveth = donationToGiveth > 0 && givethDonationAmount > 0;
const { formatMessage } = useIntl();
const { setSuccessDonation, project } = useDonateData();

Expand Down
16 changes: 15 additions & 1 deletion src/components/views/donate/OnTime/OneTimeDonationCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import InlineToast, { EToastType } from '@/components/toasts/InlineToast';
import { EProjectStatus } from '@/apollo/types/gqlEnums';
import { truncateToDecimalPlaces } from '@/lib/helpers';
import { IProjectAcceptedToken } from '@/apollo/types/gqlTypes';
import { prepareTokenList } from '@/components/views/donate/helpers';
import {
calcDonationShare,
prepareTokenList,
} from '@/components/views/donate/helpers';
import GIVBackToast from '@/components/views/donate/GIVBackToast';
import { DonateWrongNetwork } from '@/components/modals/DonateWrongNetwork';
import { useAppDispatch, useAppSelector } from '@/features/hooks';
Expand Down Expand Up @@ -315,6 +318,15 @@ const CryptoDonation: FC<{
);
}, [gasfee, tokenDecimals, selectedOneTimeToken?.symbol, formatMessage]);

// We need givethDonationAmount here because we need to calculate the donation share
// for Giveth. If user want to donate minimal amount to projecct, the donation share for Giveth
// has to be 0, disabled in UI and DonationModal
const { givethDonation: givethDonationAmount } = calcDonationShare(
amount,
donationToGiveth,
selectedOneTimeToken?.decimals ?? 18,
);

return (
<MainContainer>
{showQFModal && (
Expand Down Expand Up @@ -342,6 +354,7 @@ const CryptoDonation: FC<{
token={selectedOneTimeToken}
amount={amount}
donationToGiveth={donationToGiveth}
givethDonationAmount={givethDonationAmount}
anonymous={anonymous}
givBackEligible={
projectIsGivBackEligible &&
Expand Down Expand Up @@ -442,6 +455,7 @@ const CryptoDonation: FC<{
<DonateToGiveth
setDonationToGiveth={setDonationToGiveth}
donationToGiveth={donationToGiveth}
givethDonationAmount={givethDonationAmount}
title={
formatMessage({ id: 'label.donation_to' }) + ' Giveth'
}
Expand Down
Loading