From f2047172ee3c97e66e4cede9b8006d2d14b605fc Mon Sep 17 00:00:00 2001 From: Kyrylo Klymenko Date: Fri, 27 Sep 2024 20:17:09 +0200 Subject: [PATCH 1/3] Attempt switching chain automatically when on wrong network --- src/hooks/DAO/useDAOController.ts | 2 +- src/pages/DAOController.tsx | 16 +++++++++++++++- src/router.tsx | 6 ++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/hooks/DAO/useDAOController.ts b/src/hooks/DAO/useDAOController.ts index 8190b77168..4c04d18c97 100644 --- a/src/hooks/DAO/useDAOController.ts +++ b/src/hooks/DAO/useDAOController.ts @@ -56,5 +56,5 @@ export default function useDAOController() { useKeyValuePairs(); useHatsTree(); - return { invalidQuery, wrongNetwork, errorLoading }; + return { invalidQuery, wrongNetwork, errorLoading, urlAddressPrefix: addressPrefix }; } diff --git a/src/pages/DAOController.tsx b/src/pages/DAOController.tsx index ada7836697..4c6a780123 100644 --- a/src/pages/DAOController.tsx +++ b/src/pages/DAOController.tsx @@ -2,9 +2,12 @@ import { useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { Outlet } from 'react-router-dom'; import { toast } from 'react-toastify'; +import { useSwitchChain } from 'wagmi'; +import { logError } from '../helpers/errorLogging'; import useDAOController from '../hooks/DAO/useDAOController'; import { useUpdateSafeData } from '../hooks/utils/useUpdateSafeData'; import { useFractal } from '../providers/App/AppProvider'; +import { getChainIdFromPrefix } from '../utils/url'; import LoadingProblem from './LoadingProblem'; const useTemporaryProposals = () => { @@ -32,7 +35,8 @@ const useTemporaryProposals = () => { }; export default function DAOController() { - const { errorLoading, wrongNetwork, invalidQuery } = useDAOController(); + const { switchChain } = useSwitchChain(); + const { errorLoading, wrongNetwork, invalidQuery, urlAddressPrefix } = useDAOController(); useUpdateSafeData(); const { node: { daoName }, @@ -40,6 +44,16 @@ export default function DAOController() { useTemporaryProposals(); + useEffect(() => { + if (urlAddressPrefix && wrongNetwork) { + try { + switchChain({ chainId: getChainIdFromPrefix(urlAddressPrefix) }); + } catch (e) { + logError(e); + } + } + }, [wrongNetwork, switchChain, urlAddressPrefix]); + useEffect(() => { if (daoName) { document.title = `${import.meta.env.VITE_APP_NAME} | ${daoName}`; diff --git a/src/router.tsx b/src/router.tsx index 16f4987e3e..c68e167657 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -67,6 +67,7 @@ export const router = (addressPrefix: string) => // @ts-ignore:next-line loader: ({ params: { daoAddress } }) => redirect(DAO_ROUTES.modifyGovernance.relative(addressPrefix, daoAddress)), + // @todo - this redirect doesn't work anymore for some reason }, { path: DAO_ROUTES.hierarchy.path, @@ -105,6 +106,7 @@ export const router = (addressPrefix: string) => // @ts-ignore:next-line loader: ({ params: { daoAddress } }) => redirect(DAO_ROUTES.newSubDao.relative(addressPrefix, daoAddress)), + // @todo - this redirect doesn't work anymore for some reason }, { path: 'proposal-templates', @@ -122,6 +124,7 @@ export const router = (addressPrefix: string) => // @ts-ignore:next-line loader: ({ params: { daoAddress } }) => redirect(DAO_ROUTES.proposalTemplateNew.relative(addressPrefix, daoAddress)), + // @todo - this redirect doesn't work anymore for some reason }, ], }, @@ -145,6 +148,7 @@ export const router = (addressPrefix: string) => // @ts-ignore:next-line loader: ({ params: { daoAddress } }) => redirect(DAO_ROUTES.proposalNew.relative(addressPrefix, daoAddress)), + // @todo - this redirect doesn't work anymore for some reason }, { path: 'new/sablier/*', @@ -158,6 +162,7 @@ export const router = (addressPrefix: string) => DAO_ROUTES.proposalNew .relative(addressPrefix, daoAddress) .replace('new', 'new/sablier'), + // @todo - this redirect doesn't work anymore for some reason ), }, ], @@ -179,6 +184,7 @@ export const router = (addressPrefix: string) => // @ts-ignore:next-line loader: ({ params: { daoAddress } }) => redirect(DAO_ROUTES.dao.relative(addressPrefix, daoAddress)), + // @todo - this redirect doesn't work anymore for some reason }, { path: '*', // 404 From d5681c77b70bf830b7e76c8157550168569d9958 Mon Sep 17 00:00:00 2001 From: Kyrylo Klymenko Date: Fri, 27 Sep 2024 20:32:32 +0200 Subject: [PATCH 2/3] Reload da page --- src/pages/DAOController.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/DAOController.tsx b/src/pages/DAOController.tsx index 4c6a780123..e5cc59b5e9 100644 --- a/src/pages/DAOController.tsx +++ b/src/pages/DAOController.tsx @@ -48,6 +48,7 @@ export default function DAOController() { if (urlAddressPrefix && wrongNetwork) { try { switchChain({ chainId: getChainIdFromPrefix(urlAddressPrefix) }); + window.location.reload(); } catch (e) { logError(e); } From 5d1c3f0c8a203b786b31e793b9799255db0af3f9 Mon Sep 17 00:00:00 2001 From: Adam Gall Date: Fri, 27 Sep 2024 16:19:40 -0400 Subject: [PATCH 3/3] bump version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 525752a1e9..e2a5085431 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "decent-interface", - "version": "0.3.3", + "version": "0.3.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "decent-interface", - "version": "0.3.3", + "version": "0.3.4", "hasInstallScript": true, "dependencies": { "@amplitude/analytics-browser": "^2.11.1", diff --git a/package.json b/package.json index f57709457c..833dbc71e9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "decent-interface", - "version": "0.3.3", + "version": "0.3.4", "private": true, "dependencies": { "@amplitude/analytics-browser": "^2.11.1",