From 04e20581abfe44d14e05071647d4814c3b118b95 Mon Sep 17 00:00:00 2001 From: Adam Gall Date: Tue, 26 Mar 2024 14:04:40 -0400 Subject: [PATCH 1/9] Remove `as ProposalVote`, wtf is going on here?! --- src/utils/azorius.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/azorius.ts b/src/utils/azorius.ts index a2f1c81466..1061d44e8e 100644 --- a/src/utils/azorius.ts +++ b/src/utils/azorius.ts @@ -103,7 +103,7 @@ export const getProposalVotes = async ( ...rest, voter, choice: VOTE_CHOICES[voteType], - } as ProposalVote; // This bypasses the type check, but it's fine + }; }); }; From 024b62151b86557cab7a50265ccb9a16c8160592 Mon Sep 17 00:00:00 2001 From: Adam Gall Date: Tue, 26 Mar 2024 10:35:58 -0400 Subject: [PATCH 2/9] Remove unneeded slash from route path --- src/router.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/router.tsx b/src/router.tsx index 0779767930..40809e46d5 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -34,7 +34,7 @@ export const router = createBrowserRouter([ element: , }, { - path: '/create', + path: 'create', element: , }, { From 291fbb9b272ab4091e1a261f9624d4b7a668eaa6 Mon Sep 17 00:00:00 2001 From: Adam Gall Date: Tue, 26 Mar 2024 12:46:03 -0400 Subject: [PATCH 3/9] Remove the initial `/daos` path from routing --- src/pages/DAOController.tsx | 11 ++--- src/router.tsx | 86 ++++++++++++++++++------------------- 2 files changed, 44 insertions(+), 53 deletions(-) diff --git a/src/pages/DAOController.tsx b/src/pages/DAOController.tsx index 50e41d5421..bcf37ebe6c 100644 --- a/src/pages/DAOController.tsx +++ b/src/pages/DAOController.tsx @@ -2,7 +2,6 @@ import { Button, Center, Text, VStack, ChakraProvider, extendTheme } from '@chak import { theme } from '@decent-org/fractal-ui'; import { useMemo } from 'react'; import { useTranslation } from 'react-i18next'; -import { Outlet } from 'react-router-dom'; import useDAOController from '../hooks/DAO/useDAOController'; import useDAOMetadata from '../hooks/DAO/useDAOMetadata'; import { useFractal } from '../providers/App/AppProvider'; @@ -32,7 +31,7 @@ function InvalidSafe() { ); } -export default function DAOController() { +export default function DAOController({ children }: { children: React.ReactNode }) { const { node } = useFractal(); const { nodeLoading, errorLoading } = useDAOController(); const daoMetadata = useDAOMetadata(); @@ -63,13 +62,9 @@ export default function DAOController() { let display; if (import.meta.env.VITE_APP_TESTING_ENVIRONMENT) { - display = ( - - - - ); + display = {children}; } else if (nodeLoading || validSafe || !errorLoading) { - display = ; + display = <>{children}; } else { display = ; } diff --git a/src/router.tsx b/src/router.tsx index 40809e46d5..29d2a68b80 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -25,7 +25,9 @@ export const router = createBrowserRouter([ // within underlying modals. Otherwise - trying to invoke routing-related hooks would lead to crash. // Not the best place to have this provider here but also more reasonalbe than putting that into - + + + ), children: [ @@ -38,65 +40,59 @@ export const router = createBrowserRouter([ element: , }, { - path: 'daos/:daoAddress', - element: , + path: ':daoAddress', + element: , + }, + { + path: ':daoAddress/edit/governance', + element: , + }, + { + path: ':daoAddress/hierarchy', + element: , + }, + { + path: ':daoAddress/new', + element: , + }, + { + path: ':daoAddress/proposal-templates', children: [ { index: true, - element: , - }, - { - path: 'edit/governance', - element: , - }, - { - path: 'hierarchy', - element: , + element: , }, { path: 'new', - element: , - }, - { - path: 'proposal-templates', - children: [ - { - index: true, - element: , - }, - { - path: 'new', - element: , - }, - ], + element: , }, + ], + }, + { + path: ':daoAddress/proposals', + children: [ { - path: 'proposals', - children: [ - { - index: true, - element: , - }, - { - path: ':proposalId', - element: , - }, - { - path: 'new', - element: , - }, - ], + index: true, + element: , }, { - path: 'settings', - element: , + path: ':proposalId', + element: , }, { - path: 'treasury', - element: , + path: 'new', + element: , }, ], }, + { + path: ':daoAddress/settings', + element: , + }, + { + path: ':daoAddress/treasury', + element: , + }, { path: '*', // 404 element: , From bb7e8b58f153da387a8783c2f46419dc4b462329 Mon Sep 17 00:00:00 2001 From: Adam Gall Date: Tue, 26 Mar 2024 13:16:32 -0400 Subject: [PATCH 4/9] Fix routes to not include `daos` prefix --- src/constants/routes.ts | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/constants/routes.ts b/src/constants/routes.ts index deac5e2508..97ac5777af 100644 --- a/src/constants/routes.ts +++ b/src/constants/routes.ts @@ -7,7 +7,6 @@ type RouteInfo = { relative: (...args: any) => string; path: string }; type RouteIndex = { [key: string]: RouteInfo }; export interface DAORoutes extends RouteIndex { dao: RouteInfo; - daos: RouteInfo; newSubDao: RouteInfo; modifyGovernance: RouteInfo; hierarchy: RouteInfo; @@ -22,58 +21,53 @@ export interface DAORoutes extends RouteIndex { } export const DAO_ROUTES: DAORoutes = { - daos: { - relative: () => '/daos', - path: 'daos/:address/*', - }, dao: { - relative: (daoAddress: string) => `/daos/${daoAddress}`, + relative: (daoAddress: string) => `/${daoAddress}`, path: '*', }, newSubDao: { - relative: (daoAddress: string) => `/daos/${daoAddress}/new`, + relative: (daoAddress: string) => `/${daoAddress}/new`, path: 'new', }, modifyGovernance: { - relative: (daoAddress: string) => `/daos/${daoAddress}/edit/governance`, + relative: (daoAddress: string) => `/${daoAddress}/edit/governance`, path: 'edit/governance', }, hierarchy: { - relative: (daoAddress: string) => `/daos/${daoAddress}/hierarchy`, + relative: (daoAddress: string) => `/${daoAddress}/hierarchy`, path: 'hierarchy', }, treasury: { - relative: (daoAddress: string) => `/daos/${daoAddress}/treasury`, + relative: (daoAddress: string) => `/${daoAddress}/treasury`, path: 'treasury', }, proposals: { - relative: (daoAddress: string) => `/daos/${daoAddress}/proposals`, + relative: (daoAddress: string) => `/${daoAddress}/proposals`, path: 'proposals', }, proposal: { - relative: (daoAddress: string, proposalId: string) => - `/daos/${daoAddress}/proposals/${proposalId}`, + relative: (daoAddress: string, proposalId: string) => `/${daoAddress}/proposals/${proposalId}`, path: 'proposals/:proposalId', }, proposalNew: { - relative: (daoAddress: string) => `/daos/${daoAddress}/proposals/new`, + relative: (daoAddress: string) => `/${daoAddress}/proposals/new`, path: 'proposals/new', }, settings: { - relative: (daoAddress: string) => `/daos/${daoAddress}/settings`, + relative: (daoAddress: string) => `/${daoAddress}/settings`, path: 'settings', }, proposalTemplates: { - relative: (daoAddress: string) => `/daos/${daoAddress}/proposal-templates`, + relative: (daoAddress: string) => `/${daoAddress}/proposal-templates`, path: 'proposal-templates', }, proposalTemplate: { relative: (daoAddress: string, proposalTemplateKey: string) => - `/daos/${daoAddress}/proposal-templates/${proposalTemplateKey}`, + `/${daoAddress}/proposal-templates/${proposalTemplateKey}`, path: 'proposal-templates/:proposalTemplateKey', }, proposalTemplateNew: { - relative: (daoAddress: string) => `/daos/${daoAddress}/proposal-templates/new`, + relative: (daoAddress: string) => `/${daoAddress}/proposal-templates/new`, path: 'proposal-templates/new', }, }; From 3d2e9f73a165080d3fefd511cd3a149ac2ddf679 Mon Sep 17 00:00:00 2001 From: Adam Gall Date: Tue, 26 Mar 2024 13:29:06 -0400 Subject: [PATCH 5/9] Add redirection route so as to not break old links --- src/router.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/router.tsx b/src/router.tsx index 29d2a68b80..920542a75f 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -1,4 +1,4 @@ -import { createBrowserRouter } from 'react-router-dom'; +import { createBrowserRouter, redirect } from 'react-router-dom'; import { ModalProvider } from './components/ui/modals/ModalProvider'; import Layout from './components/ui/page/Layout'; import FourOhFourPage from './pages/404'; @@ -93,6 +93,17 @@ export const router = createBrowserRouter([ path: ':daoAddress/treasury', element: , }, + { + path: 'daos', + children: [ + { + // this exists to keep old links working + // /daos/0x0123/* will redirect to /0x0123 + path: ':daoAddress/*', + loader: ({ params: { daoAddress } }) => redirect(`/${daoAddress}`), + }, + ], + }, { path: '*', // 404 element: , From 809c1b354144f45ccde1efe0b48283793670b0d7 Mon Sep 17 00:00:00 2001 From: Adam Gall Date: Tue, 26 Mar 2024 14:06:19 -0400 Subject: [PATCH 6/9] Move the DAO address identifier from path to query param --- src/hooks/DAO/useDAOController.ts | 8 +++++--- src/router.tsx | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/hooks/DAO/useDAOController.ts b/src/hooks/DAO/useDAOController.ts index 568f4e92b6..6c9593f561 100644 --- a/src/hooks/DAO/useDAOController.ts +++ b/src/hooks/DAO/useDAOController.ts @@ -1,5 +1,5 @@ import { useEffect } from 'react'; -import { useParams } from 'react-router-dom'; +import { useSearchParams } from 'react-router-dom'; import { useFractal } from '../../providers/App/AppProvider'; import { useERC20Claim } from './loaders/governance/useERC20Claim'; import { useSnapshotProposals } from './loaders/snapshot/useSnapshotProposals'; @@ -11,7 +11,9 @@ import { useFractalTreasury } from './loaders/useFractalTreasury'; import { useGovernanceContracts } from './loaders/useGovernanceContracts'; export default function useDAOController() { - const { daoAddress } = useParams(); + const [searchParams] = useSearchParams(); + const daoAddress = searchParams.get('dao'); + const { node: { nodeHierarchy: { parentAddress }, @@ -24,7 +26,7 @@ export default function useDAOController() { } }, [action, daoAddress]); - const { nodeLoading, errorLoading } = useFractalNode({ daoAddress }); + const { nodeLoading, errorLoading } = useFractalNode({ daoAddress: daoAddress || undefined }); useGovernanceContracts(); useFractalGuardContracts({}); useFractalFreeze({ parentSafeAddress: parentAddress }); diff --git a/src/router.tsx b/src/router.tsx index 920542a75f..959317527e 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -40,23 +40,23 @@ export const router = createBrowserRouter([ element: , }, { - path: ':daoAddress', + path: 'home', element: , }, { - path: ':daoAddress/edit/governance', + path: 'edit/governance', element: , }, { - path: ':daoAddress/hierarchy', + path: 'hierarchy', element: , }, { - path: ':daoAddress/new', + path: 'new', element: , }, { - path: ':daoAddress/proposal-templates', + path: 'proposal-templates', children: [ { index: true, @@ -69,7 +69,7 @@ export const router = createBrowserRouter([ ], }, { - path: ':daoAddress/proposals', + path: 'proposals', children: [ { index: true, @@ -86,11 +86,11 @@ export const router = createBrowserRouter([ ], }, { - path: ':daoAddress/settings', + path: 'settings', element: , }, { - path: ':daoAddress/treasury', + path: 'treasury', element: , }, { @@ -98,9 +98,9 @@ export const router = createBrowserRouter([ children: [ { // this exists to keep old links working - // /daos/0x0123/* will redirect to /0x0123 + // /daos/0x0123/* will redirect to /home?dao=0x0123 path: ':daoAddress/*', - loader: ({ params: { daoAddress } }) => redirect(`/${daoAddress}`), + loader: ({ params: { daoAddress } }) => redirect(`/home?dao=${daoAddress}`), }, ], }, From 8983e9dd9db0bb739d619d4ddafe77dccf3e98b0 Mon Sep 17 00:00:00 2001 From: Adam Gall Date: Tue, 26 Mar 2024 14:06:46 -0400 Subject: [PATCH 7/9] Fix links --- src/constants/routes.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/constants/routes.ts b/src/constants/routes.ts index 97ac5777af..b277ac1bcb 100644 --- a/src/constants/routes.ts +++ b/src/constants/routes.ts @@ -22,52 +22,53 @@ export interface DAORoutes extends RouteIndex { export const DAO_ROUTES: DAORoutes = { dao: { - relative: (daoAddress: string) => `/${daoAddress}`, + relative: (daoAddress: string) => `/home?dao=${daoAddress}`, path: '*', }, newSubDao: { - relative: (daoAddress: string) => `/${daoAddress}/new`, + relative: (daoAddress: string) => `/new?dao=${daoAddress}`, path: 'new', }, modifyGovernance: { - relative: (daoAddress: string) => `/${daoAddress}/edit/governance`, + relative: (daoAddress: string) => `/edit/governance?dao=${daoAddress}`, path: 'edit/governance', }, hierarchy: { - relative: (daoAddress: string) => `/${daoAddress}/hierarchy`, + relative: (daoAddress: string) => `/hierarchy?dao=${daoAddress}`, path: 'hierarchy', }, treasury: { - relative: (daoAddress: string) => `/${daoAddress}/treasury`, + relative: (daoAddress: string) => `/treasury?dao=${daoAddress}`, path: 'treasury', }, proposals: { - relative: (daoAddress: string) => `/${daoAddress}/proposals`, + relative: (daoAddress: string) => `/proposals?dao=${daoAddress}`, path: 'proposals', }, proposal: { - relative: (daoAddress: string, proposalId: string) => `/${daoAddress}/proposals/${proposalId}`, + relative: (daoAddress: string, proposalId: string) => + `/proposals/${proposalId}?dao=${daoAddress}`, path: 'proposals/:proposalId', }, proposalNew: { - relative: (daoAddress: string) => `/${daoAddress}/proposals/new`, + relative: (daoAddress: string) => `/proposals/new?dao=${daoAddress}`, path: 'proposals/new', }, settings: { - relative: (daoAddress: string) => `/${daoAddress}/settings`, + relative: (daoAddress: string) => `/settings?dao=${daoAddress}`, path: 'settings', }, proposalTemplates: { - relative: (daoAddress: string) => `/${daoAddress}/proposal-templates`, + relative: (daoAddress: string) => `/proposal-templates?dao=${daoAddress}`, path: 'proposal-templates', }, proposalTemplate: { relative: (daoAddress: string, proposalTemplateKey: string) => - `/${daoAddress}/proposal-templates/${proposalTemplateKey}`, + `/proposal-templates/${proposalTemplateKey}?dao=${daoAddress}`, path: 'proposal-templates/:proposalTemplateKey', }, proposalTemplateNew: { - relative: (daoAddress: string) => `/${daoAddress}/proposal-templates/new`, + relative: (daoAddress: string) => `/proposal-templates/new?dao=${daoAddress}`, path: 'proposal-templates/new', }, }; From 782e2880b681da349202eda0f3c91f2d8cd95dd1 Mon Sep 17 00:00:00 2001 From: Adam Gall Date: Tue, 26 Mar 2024 14:52:41 -0400 Subject: [PATCH 8/9] Don't need to nest the maintained redirection path --- src/router.tsx | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/router.tsx b/src/router.tsx index 959317527e..3897d8b602 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -94,15 +94,10 @@ export const router = createBrowserRouter([ element: , }, { - path: 'daos', - children: [ - { - // this exists to keep old links working - // /daos/0x0123/* will redirect to /home?dao=0x0123 - path: ':daoAddress/*', - loader: ({ params: { daoAddress } }) => redirect(`/home?dao=${daoAddress}`), - }, - ], + // this exists to keep old links working + // /daos/0x0123/* will redirect to /home?dao=0x0123 + path: 'daos/:daoAddress/*', + loader: ({ params: { daoAddress } }) => redirect(`/home?dao=${daoAddress}`), }, { path: '*', // 404 From 4f5d0e8f3cd80911e9e0ff24d3096b0c28e611eb Mon Sep 17 00:00:00 2001 From: Adam Gall Date: Tue, 26 Mar 2024 18:38:22 -0400 Subject: [PATCH 9/9] DAOController can be empty-path parent --- src/pages/DAOController.tsx | 11 +++-- src/router.tsx | 88 +++++++++++++++++++------------------ 2 files changed, 54 insertions(+), 45 deletions(-) diff --git a/src/pages/DAOController.tsx b/src/pages/DAOController.tsx index bcf37ebe6c..50e41d5421 100644 --- a/src/pages/DAOController.tsx +++ b/src/pages/DAOController.tsx @@ -2,6 +2,7 @@ import { Button, Center, Text, VStack, ChakraProvider, extendTheme } from '@chak import { theme } from '@decent-org/fractal-ui'; import { useMemo } from 'react'; import { useTranslation } from 'react-i18next'; +import { Outlet } from 'react-router-dom'; import useDAOController from '../hooks/DAO/useDAOController'; import useDAOMetadata from '../hooks/DAO/useDAOMetadata'; import { useFractal } from '../providers/App/AppProvider'; @@ -31,7 +32,7 @@ function InvalidSafe() { ); } -export default function DAOController({ children }: { children: React.ReactNode }) { +export default function DAOController() { const { node } = useFractal(); const { nodeLoading, errorLoading } = useDAOController(); const daoMetadata = useDAOMetadata(); @@ -62,9 +63,13 @@ export default function DAOController({ children }: { children: React.ReactNode let display; if (import.meta.env.VITE_APP_TESTING_ENVIRONMENT) { - display = {children}; + display = ( + + + + ); } else if (nodeLoading || validSafe || !errorLoading) { - display = <>{children}; + display = ; } else { display = ; } diff --git a/src/router.tsx b/src/router.tsx index 3897d8b602..79c0f4dd29 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -25,9 +25,7 @@ export const router = createBrowserRouter([ // within underlying modals. Otherwise - trying to invoke routing-related hooks would lead to crash. // Not the best place to have this provider here but also more reasonalbe than putting that into - - - + ), children: [ @@ -40,59 +38,65 @@ export const router = createBrowserRouter([ element: , }, { - path: 'home', - element: , - }, - { - path: 'edit/governance', - element: , - }, - { - path: 'hierarchy', - element: , - }, - { - path: 'new', - element: , - }, - { - path: 'proposal-templates', + path: '/', + element: , children: [ { - index: true, - element: , + path: 'home', + element: , + }, + { + path: 'edit/governance', + element: , + }, + { + path: 'hierarchy', + element: , }, { path: 'new', - element: , + element: , }, - ], - }, - { - path: 'proposals', - children: [ { - index: true, - element: , + path: 'proposal-templates', + children: [ + { + index: true, + element: , + }, + { + path: 'new', + element: , + }, + ], }, { - path: ':proposalId', - element: , + path: 'proposals', + children: [ + { + index: true, + element: , + }, + { + path: ':proposalId', + element: , + }, + { + path: 'new', + element: , + }, + ], }, { - path: 'new', - element: , + path: 'settings', + element: , + }, + { + path: 'treasury', + element: , }, ], }, - { - path: 'settings', - element: , - }, - { - path: 'treasury', - element: , - }, { // this exists to keep old links working // /daos/0x0123/* will redirect to /home?dao=0x0123