Skip to content

Commit

Permalink
fixed navigation for when donation is completed
Browse files Browse the repository at this point in the history
  • Loading branch information
krisbitney committed Jan 31, 2024
1 parent a07dbca commit bc1f725
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 26 deletions.
10 changes: 9 additions & 1 deletion packages/app/src/components/DonateComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { TransactionReceipt } from 'viem';
import { useToken, useTokenList } from '../hooks/useTokenList';
import { formatDecimalStringInput } from '../lib/formatDecimalStringInput';
import ThankYouModal from './modals/ThankYouModal';
import useCrossNavigate from '../routes/useCrossNavigate';

interface DonateComponentProps {
collective: IpfsCollective;
Expand All @@ -45,6 +46,12 @@ function DonateComponent({ collective }: DonateComponentProps) {
const [approveSwapModalVisible, setApproveSwapModalVisible] = useState(false);
const [thankYouModalVisible, setThankYouModalVisible] = useState(false);

const [isDonationComplete, setIsDonationComplete] = useState(false);
const { navigate } = useCrossNavigate();
if (isDonationComplete) {
navigate(`/profile/${address}`);
}

const [currency, setCurrency] = useState<string>('G$');
const [frequency, setFrequency] = useState<Frequency>(Frequency.OneTime);
const [duration, setDuration] = useState(1);
Expand Down Expand Up @@ -87,6 +94,7 @@ function DonateComponent({ collective }: DonateComponentProps) {
(error) => setErrorMessage(error),
(value: boolean) => setCompleteDonationModalVisible(value),
(value: boolean) => setThankYouModalVisible(value),
(value: boolean) => setIsDonationComplete(value),
rawMinimumAmountOut,
swapPath
);
Expand Down Expand Up @@ -482,7 +490,7 @@ function DonateComponent({ collective }: DonateComponentProps) {
<ErrorModal openModal={!!errorMessage} setOpenModal={onCloseErrorModal} message={errorMessage ?? ''} />
<ApproveSwapModal openModal={approveSwapModalVisible} setOpenModal={setApproveSwapModalVisible} />
<CompleteDonationModal openModal={completeDonationModalVisible} setOpenModal={setCompleteDonationModalVisible} />
<ThankYouModal openModal={thankYouModalVisible} setOpenModal={setThankYouModalVisible} collective={collective} />
<ThankYouModal openModal={thankYouModalVisible} address={address} collective={collective} />
</View>
);
}
Expand Down
8 changes: 5 additions & 3 deletions packages/app/src/components/modals/ThankYouModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import { InterRegular, InterSemiBold } from '../../utils/webFonts';
import { Colors } from '../../utils/colors';
import { ThankYouImg } from '../../assets';
import { IpfsCollective } from '../../models/models';
import useCrossNavigate from '../../routes/useCrossNavigate';

interface ThankYouModalProps {
openModal: boolean;
setOpenModal: (openModal: boolean) => void;
address?: `0x${string}`;
collective: IpfsCollective;
}

const ThankYouModal = ({ openModal, setOpenModal, collective }: ThankYouModalProps) => {
const onClick = () => setOpenModal(false);
const ThankYouModal = ({ openModal, address, collective }: ThankYouModalProps) => {
const { navigate } = useCrossNavigate();
const onClick = () => navigate(`/profile/${address}`);

return (
<Modal style={styles.centeredView} animationType="slide" transparent={true} visible={openModal}>
Expand Down
11 changes: 8 additions & 3 deletions packages/app/src/hooks/useContractCalls/useContractCalls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const useContractCalls = (
onError: (error: string) => void,
toggleCompleteDonationModal: (value: boolean) => void,
toggleThankYouModal: (value: boolean) => void,
toggleIsDonationComplete: (value: boolean) => void,
minReturnFromSwap?: string,
swapPath?: string
): ContractCalls => {
Expand All @@ -34,7 +35,8 @@ export const useContractCalls = (
frequency,
onError,
toggleCompleteDonationModal,
toggleThankYouModal
toggleThankYouModal,
toggleIsDonationComplete
);
const supportFlowWithSwap = useSupportFlowWithSwap(
collective,
Expand All @@ -45,6 +47,7 @@ export const useContractCalls = (
onError,
toggleCompleteDonationModal,
toggleThankYouModal,
toggleIsDonationComplete,
minReturnFromSwap,
swapPath
);
Expand All @@ -54,15 +57,17 @@ export const useContractCalls = (
decimalAmountIn,
onError,
toggleCompleteDonationModal,
toggleThankYouModal
toggleThankYouModal,
toggleIsDonationComplete
);
const supportSingleBatch = useSupportSingleBatch(
collective,
tokenIn.decimals,
decimalAmountIn,
onError,
toggleCompleteDonationModal,
toggleThankYouModal
toggleThankYouModal,
toggleIsDonationComplete
);

return {
Expand Down
10 changes: 5 additions & 5 deletions packages/app/src/hooks/useContractCalls/useSupportFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ export function useSupportFlow(
frequency: Frequency,
onError: (error: string) => void,
toggleCompleteDonationModal: (value: boolean) => void,
toggleThankYouModal: (value: boolean) => void
toggleThankYouModal: (value: boolean) => void,
toggleIsDonationComplete: (value: boolean) => void
) {
const { address: maybeAddress } = useAccount();
const { chain } = useNetwork();
const maybeSigner = useEthersSigner({ chainId: chain?.id });
const { navigate } = useCrossNavigate();

return useCallback(async () => {
const validation = validateConnection(maybeAddress, chain?.id, maybeSigner);
if (typeof validation === 'string') {
onError(validation);
return;
}
const { address, chainId, signer } = validation;
const { chainId, signer } = validation;

const flowRate = calculateFlowRate(decimalAmountIn, duration, frequency, currencyDecimals);
if (!flowRate) {
Expand All @@ -46,7 +46,7 @@ export function useSupportFlow(
toggleCompleteDonationModal(false);
toggleThankYouModal(true);
await tx.wait();
navigate(`/profile/${address}`);
toggleIsDonationComplete(true);
return;
} catch (error) {
toggleCompleteDonationModal(false);
Expand All @@ -66,6 +66,6 @@ export function useSupportFlow(
toggleCompleteDonationModal,
collective,
toggleThankYouModal,
navigate,
toggleIsDonationComplete,
]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ export function useSupportFlowWithSwap(
onError: (error: string) => void,
toggleCompleteDonationModal: (value: boolean) => void,
toggleThankYouModal: (value: boolean) => void,
toggleIsDonationComplete: (value: boolean) => void,
minReturnFromSwap?: string,
swapPath?: string
) {
const { address: maybeAddress } = useAccount();
const { chain } = useNetwork();
const maybeSigner = useEthersSigner({ chainId: chain?.id });
const { navigate } = useCrossNavigate();

return useCallback(async () => {
const validation = validateConnection(maybeAddress, chain?.id, maybeSigner);
if (typeof validation === 'string') {
onError(validation);
return;
}
const { address, chainId, signer } = validation;
const { chainId, signer } = validation;

if (!minReturnFromSwap || !swapPath) {
onError('Swap route not ready.');
Expand Down Expand Up @@ -68,7 +68,7 @@ export function useSupportFlowWithSwap(
toggleCompleteDonationModal(false);
toggleThankYouModal(true);
await tx.wait();
navigate(`/profile/${address}`);
toggleIsDonationComplete(true);
return;
} catch (error) {
toggleCompleteDonationModal(false);
Expand All @@ -91,6 +91,6 @@ export function useSupportFlowWithSwap(
toggleCompleteDonationModal,
collective,
toggleThankYouModal,
navigate,
toggleIsDonationComplete,
]);
}
10 changes: 5 additions & 5 deletions packages/app/src/hooks/useContractCalls/useSupportSingleBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ export function useSupportSingleBatch(
decimalAmountIn: number,
onError: (error: string) => void,
toggleCompleteDonationModal: (value: boolean) => void,
toggleThankYouModal: (value: boolean) => void
toggleThankYouModal: (value: boolean) => void,
toggleIsDonationComplete: (value: boolean) => void
) {
const { address: maybeAddress } = useAccount();
const { chain } = useNetwork();
const maybeSigner = useEthersSigner({ chainId: chain?.id });
const { navigate } = useCrossNavigate();

return useCallback(async () => {
const validation = validateConnection(maybeAddress, chain?.id, maybeSigner);
if (typeof validation === 'string') {
onError(validation);
return;
}
const { address, chainId, signer } = validation;
const { chainId, signer } = validation;

const chainIdString = chainId.toString() as `${SupportedNetwork}`;
const network = SupportedNetworkNames[chainId as SupportedNetwork];
Expand All @@ -44,7 +44,7 @@ export function useSupportSingleBatch(
toggleCompleteDonationModal(false);
toggleThankYouModal(true);
await tx.wait();
navigate(`/profile/${address}`);
toggleIsDonationComplete(true);
return;
} catch (error) {
toggleCompleteDonationModal(false);
Expand All @@ -62,6 +62,6 @@ export function useSupportSingleBatch(
toggleCompleteDonationModal,
collective,
toggleThankYouModal,
navigate,
toggleIsDonationComplete,
]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ export function useSupportSingleTransferAndCall(
decimalAmountIn: number,
onError: (error: string) => void,
toggleCompleteDonationModal: (value: boolean) => void,
toggleThankYouModal: (value: boolean) => void
toggleThankYouModal: (value: boolean) => void,
toggleIsDonationComplete: (value: boolean) => void
) {
const { address: maybeAddress } = useAccount();
const { chain } = useNetwork();
const maybeSigner = useEthersSigner({ chainId: chain?.id });
const { navigate } = useCrossNavigate();

return useCallback(async () => {
const validation = validateConnection(maybeAddress, chain?.id, maybeSigner);
if (typeof validation === 'string') {
onError(validation);
return;
}
const { address, chainId, signer } = validation;
const { chainId, signer } = validation;

const chainIdString = chainId.toString() as `${SupportedNetwork}`;
const network = SupportedNetworkNames[chainId as SupportedNetwork];
Expand All @@ -44,7 +44,7 @@ export function useSupportSingleTransferAndCall(
toggleCompleteDonationModal(false);
toggleThankYouModal(true);
await tx.wait();
navigate(`/profile/${address}`);
toggleIsDonationComplete(true);
return;
} catch (error) {
toggleCompleteDonationModal(false);
Expand All @@ -62,6 +62,6 @@ export function useSupportSingleTransferAndCall(
toggleCompleteDonationModal,
collective,
toggleThankYouModal,
navigate,
toggleIsDonationComplete,
]);
}

0 comments on commit bc1f725

Please sign in to comment.