From 8aa2d363175c08f0649279554e5d1ff153c0ded9 Mon Sep 17 00:00:00 2001 From: Leo Unoki Date: Mon, 23 Oct 2023 10:25:21 +0100 Subject: [PATCH 1/2] Remove onSuccess from useAddToBatchFormAction --- src/components/SendFlow/Delegation/FormPage.tsx | 3 +-- src/components/SendFlow/Undelegation/FormPage.tsx | 4 ++-- src/components/SendFlow/onSubmitFormActionHooks.tsx | 2 -- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/components/SendFlow/Delegation/FormPage.tsx b/src/components/SendFlow/Delegation/FormPage.tsx index 15c29904a0..5c03029608 100644 --- a/src/components/SendFlow/Delegation/FormPage.tsx +++ b/src/components/SendFlow/Delegation/FormPage.tsx @@ -35,7 +35,6 @@ const toOperation = (formValues: FormValues): Delegation => ({ const FormPage: React.FC> = props => { const baker = props.form?.baker; - const { onClose } = useContext(DynamicModalContext); const openSignPage = useOpenSignPageFormAction({ SignPage, @@ -45,7 +44,7 @@ const FormPage: React.FC> = props => { toOperation, }); - const addToBatch = useAddToBatchFormAction(toOperation, onClose); + const addToBatch = useAddToBatchFormAction(toOperation); const { onFormSubmitActionHandlers: [onSingleSubmit, onBatchSubmit], diff --git a/src/components/SendFlow/Undelegation/FormPage.tsx b/src/components/SendFlow/Undelegation/FormPage.tsx index b94ce0a0f2..f329d58069 100644 --- a/src/components/SendFlow/Undelegation/FormPage.tsx +++ b/src/components/SendFlow/Undelegation/FormPage.tsx @@ -37,9 +37,9 @@ const FormPage: React.FC> = props => { defaultFormPageProps: { sender }, toOperation, }); - const { onClose } = useContext(DynamicModalContext); - const addToBatch = useAddToBatchFormAction(toOperation, onClose); + + const addToBatch = useAddToBatchFormAction(toOperation); const { onFormSubmitActionHandlers: [onSingleSubmit, onBatchSubmit], diff --git a/src/components/SendFlow/onSubmitFormActionHooks.tsx b/src/components/SendFlow/onSubmitFormActionHooks.tsx index 74fc33d0c8..0029cad422 100644 --- a/src/components/SendFlow/onSubmitFormActionHooks.tsx +++ b/src/components/SendFlow/onSubmitFormActionHooks.tsx @@ -72,7 +72,6 @@ export const useOpenSignPageFormAction = < export const useAddToBatchFormAction = ( toOperation: (formValues: FormValues) => Operation, - onSuccess?: () => void ): OnSubmitFormAction => { const network = useSelectedNetwork(); const makeFormOperations = useMakeFormOperations(toOperation); @@ -83,7 +82,6 @@ export const useAddToBatchFormAction = ( const operations = makeFormOperations(formValues); await dispatch(estimateAndUpdateBatch(operations, network)); toast({ title: "Transaction added to batch!", status: "success" }); - onSuccess?.(); }; return onAddToBatchAction; From 1b029bf463f42daaf2715968e8919f0a8a359f2e Mon Sep 17 00:00:00 2001 From: Leo Unoki Date: Mon, 23 Oct 2023 10:26:39 +0100 Subject: [PATCH 2/2] Close modal on insert to batch --- src/components/SendFlow/Delegation/FormPage.tsx | 3 +-- src/components/SendFlow/Undelegation/FormPage.tsx | 4 +--- src/components/SendFlow/onSubmitFormActionHooks.tsx | 4 +++- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/components/SendFlow/Delegation/FormPage.tsx b/src/components/SendFlow/Delegation/FormPage.tsx index 5c03029608..2ffcbf75f4 100644 --- a/src/components/SendFlow/Delegation/FormPage.tsx +++ b/src/components/SendFlow/Delegation/FormPage.tsx @@ -6,7 +6,7 @@ import { ModalFooter, Text, } from "@chakra-ui/react"; -import React, { useContext } from "react"; +import React from "react"; import { FormProvider, useForm } from "react-hook-form"; import { parsePkh, RawPkh, parseImplicitPkh } from "../../../types/Address"; import { BakersAutocomplete, OwnedAccountsAutocomplete } from "../../AddressAutocomplete"; @@ -20,7 +20,6 @@ import { import { Delegation } from "../../../types/Operation"; import { FormErrorMessage } from "../../FormErrorMessage"; import { HeaderWrapper } from "../FormPageHeader"; -import { DynamicModalContext } from "../../DynamicModal"; export type FormValues = { sender: RawPkh; diff --git a/src/components/SendFlow/Undelegation/FormPage.tsx b/src/components/SendFlow/Undelegation/FormPage.tsx index f329d58069..6b8ed97cac 100644 --- a/src/components/SendFlow/Undelegation/FormPage.tsx +++ b/src/components/SendFlow/Undelegation/FormPage.tsx @@ -1,5 +1,5 @@ import { FormControl, FormLabel, ModalBody, ModalContent, ModalFooter } from "@chakra-ui/react"; -import React, { useContext } from "react"; +import React from "react"; import { FormProvider, useForm } from "react-hook-form"; import { parsePkh, RawPkh } from "../../../types/Address"; import { OwnedAccountsAutocomplete } from "../../AddressAutocomplete"; @@ -13,7 +13,6 @@ import { import { Undelegation } from "../../../types/Operation"; import FormPageHeader from "../FormPageHeader"; import { BakerSmallTile } from "../BakerSmallTile"; -import { DynamicModalContext } from "../../DynamicModal"; export type FormValues = { sender: RawPkh; @@ -38,7 +37,6 @@ const FormPage: React.FC> = props => { toOperation, }); - const addToBatch = useAddToBatchFormAction(toOperation); const { diff --git a/src/components/SendFlow/onSubmitFormActionHooks.tsx b/src/components/SendFlow/onSubmitFormActionHooks.tsx index 0029cad422..d4f7a63d6d 100644 --- a/src/components/SendFlow/onSubmitFormActionHooks.tsx +++ b/src/components/SendFlow/onSubmitFormActionHooks.tsx @@ -71,8 +71,9 @@ export const useOpenSignPageFormAction = < }; export const useAddToBatchFormAction = ( - toOperation: (formValues: FormValues) => Operation, + toOperation: (formValues: FormValues) => Operation ): OnSubmitFormAction => { + const { onClose } = useContext(DynamicModalContext); const network = useSelectedNetwork(); const makeFormOperations = useMakeFormOperations(toOperation); const dispatch = useAppDispatch(); @@ -82,6 +83,7 @@ export const useAddToBatchFormAction = ( const operations = makeFormOperations(formValues); await dispatch(estimateAndUpdateBatch(operations, network)); toast({ title: "Transaction added to batch!", status: "success" }); + onClose(); }; return onAddToBatchAction;