Skip to content

Commit

Permalink
Merge pull request #521 from trilitech/close-modal-on-insert-batch
Browse files Browse the repository at this point in the history
Close modal on insert batch
  • Loading branch information
ryutamago authored Oct 24, 2023
2 parents 53591c2 + 71930f5 commit 672e6a6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
6 changes: 2 additions & 4 deletions src/components/SendFlow/Delegation/FormPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand All @@ -35,7 +34,6 @@ const toOperation = (formValues: FormValues): Delegation => ({

const FormPage: React.FC<FormPageProps<FormValues>> = props => {
const baker = props.form?.baker;
const { onClose } = useContext(DynamicModalContext);

const openSignPage = useOpenSignPageFormAction({
SignPage,
Expand All @@ -45,7 +43,7 @@ const FormPage: React.FC<FormPageProps<FormValues>> = props => {
toOperation,
});

const addToBatch = useAddToBatchFormAction(toOperation, onClose);
const addToBatch = useAddToBatchFormAction(toOperation);

const {
onFormSubmitActionHandlers: [onSingleSubmit, onBatchSubmit],
Expand Down
6 changes: 2 additions & 4 deletions src/components/SendFlow/Undelegation/FormPage.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
Expand All @@ -37,9 +36,8 @@ const FormPage: React.FC<FormPagePropsWithSender<FormValues>> = props => {
defaultFormPageProps: { sender },
toOperation,
});
const { onClose } = useContext(DynamicModalContext);

const addToBatch = useAddToBatchFormAction(toOperation, onClose);
const addToBatch = useAddToBatchFormAction(toOperation);

const {
onFormSubmitActionHandlers: [onSingleSubmit, onBatchSubmit],
Expand Down
6 changes: 3 additions & 3 deletions src/components/SendFlow/onSubmitFormActionHooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ export const useOpenSignPageFormAction = <
};

export const useAddToBatchFormAction = <FormValues extends BaseFormValues>(
toOperation: (formValues: FormValues) => Operation,
onSuccess?: () => void
toOperation: (formValues: FormValues) => Operation
): OnSubmitFormAction<FormValues> => {
const { onClose } = useContext(DynamicModalContext);
const network = useSelectedNetwork();
const makeFormOperations = useMakeFormOperations(toOperation);
const dispatch = useAppDispatch();
Expand All @@ -83,7 +83,7 @@ export const useAddToBatchFormAction = <FormValues extends BaseFormValues>(
const operations = makeFormOperations(formValues);
await dispatch(estimateAndUpdateBatch(operations, network));
toast({ title: "Transaction added to batch!", status: "success" });
onSuccess?.();
onClose();
};

return onAddToBatchAction;
Expand Down

0 comments on commit 672e6a6

Please sign in to comment.