From 2d362fb9dd9161acef8e67a52431d22abba2c614 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Fri, 20 Dec 2024 10:22:49 -0500 Subject: [PATCH 1/2] remove network switching useEffect from establish essentials form --- .../DaoCreator/formComponents/EstablishEssentials.tsx | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/components/DaoCreator/formComponents/EstablishEssentials.tsx b/src/components/DaoCreator/formComponents/EstablishEssentials.tsx index 1ac5af67a..82d707045 100644 --- a/src/components/DaoCreator/formComponents/EstablishEssentials.tsx +++ b/src/components/DaoCreator/formComponents/EstablishEssentials.tsx @@ -108,13 +108,6 @@ export function EstablishEssentials(props: ICreationStepProps) { }, }); - useEffect(() => { - if (chain.id !== walletChainID) { - const chainId = getChainIdFromPrefix(addressPrefix); - switchChain({ chainId }); - } - }, [chain.id, walletChainID, addressPrefix, switchChain]); - return ( <> Date: Fri, 20 Dec 2024 10:23:12 -0500 Subject: [PATCH 2/2] control network switching in DAOController --- src/components/DaoCreator/index.tsx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/components/DaoCreator/index.tsx b/src/components/DaoCreator/index.tsx index a46831e37..dc25f473e 100644 --- a/src/components/DaoCreator/index.tsx +++ b/src/components/DaoCreator/index.tsx @@ -1,6 +1,9 @@ import { Box } from '@chakra-ui/react'; import { Formik } from 'formik'; +import { useEffect } from 'react'; +import { useChainId, useSwitchChain } from 'wagmi'; import { useDAOCreateSchema } from '../../hooks/schemas/DAOCreate/useDAOCreateSchema'; +import { useNetworkConfigStore } from '../../providers/NetworkConfig/useNetworkConfigStore'; import { AzoriusERC20DAO, AzoriusERC721DAO, @@ -28,6 +31,8 @@ function DaoCreator({ mode: DAOCreateMode; }) { const { totalParentVotingWeight } = useParentSafeVotingWeight(); + const walletChainID = useChainId(); + const { chain } = useNetworkConfigStore(); const { createDAOValidation } = useDAOCreateSchema({ isSubDAO: !!isSubDAO, @@ -37,6 +42,21 @@ function DaoCreator({ const { prepareMultisigFormData, prepareAzoriusERC20FormData, prepareAzoriusERC721FormData } = usePrepareFormData(); + const { switchChain } = useSwitchChain({ + mutation: { + onError: () => { + if (chain.id !== walletChainID && !isSubDAO) { + switchChain({ chainId: chain.id }); + } + }, + }, + }); + useEffect(() => { + if (chain.id !== walletChainID && !isSubDAO) { + switchChain({ chainId: chain.id }); + } + }, [chain.id, walletChainID, switchChain, isSubDAO]); + return (