Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1568 nonce page refresh #1969

Merged
merged 3 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/hooks/utils/useUpdateSafeData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useRef, useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import { useFractal } from '../../providers/App/AppProvider';
import { useSafeAPI } from '../../providers/App/hooks/useSafeAPI';
import { NodeAction } from '../../providers/App/node/action';

export const useUpdateSafeData = () => {
const {
action,
node: { daoAddress },
} = useFractal();
const safeAPI = useSafeAPI();
const location = useLocation();
const prevPathname = useRef(location.pathname);

useEffect(() => {
if (!safeAPI || !daoAddress) {
return;
}

if (prevPathname.current !== location.pathname) {
(async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me self-calling function makes it little bit harder to read - I'd suggest changing this to named function and then call it.

So something like async function setSafeInfo () { blah } and then setSafeInfo()

const safeInfo = await safeAPI.getSafeData(daoAddress);
action.dispatch({
type: NodeAction.SET_SAFE_INFO,
payload: safeInfo,
});
})();
prevPathname.current = location.pathname;
}
}, [action, daoAddress, safeAPI, location]);
};
2 changes: 2 additions & 0 deletions src/pages/DAOController.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useEffect } from 'react';
import { Outlet } from 'react-router-dom';
import useDAOController from '../hooks/DAO/useDAOController';
import { useUpdateSafeData } from '../hooks/utils/useUpdateSafeData';
import { useFractal } from '../providers/App/AppProvider';
import LoadingProblem from './LoadingProblem';

export default function DAOController() {
const { errorLoading, wrongNetwork, invalidQuery } = useDAOController();
useUpdateSafeData();
const {
node: { daoName },
} = useFractal();
Expand Down
22 changes: 0 additions & 22 deletions src/pages/daos/[daoAddress]/proposals/new/index.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,21 @@
import { Center } from '@chakra-ui/react';
import { useRef, useEffect } from 'react';
import { ProposalBuilder } from '../../../../../components/ProposalBuilder';
import { DEFAULT_PROPOSAL } from '../../../../../components/ProposalBuilder/constants';
import { BarLoader } from '../../../../../components/ui/loaders/BarLoader';
import { useHeaderHeight } from '../../../../../constants/common';
import { usePrepareProposal } from '../../../../../hooks/DAO/proposal/usePrepareProposal';
import { useFractal } from '../../../../../providers/App/AppProvider';
import { useSafeAPI } from '../../../../../providers/App/hooks/useSafeAPI';
import { NodeAction } from '../../../../../providers/App/node/action';
import { ProposalBuilderMode } from '../../../../../types';

export default function CreateProposalPage() {
const {
action,
node: { daoAddress, safe },
governance: { type },
} = useFractal();
const safeAPI = useSafeAPI();
const { prepareProposal } = usePrepareProposal();

const HEADER_HEIGHT = useHeaderHeight();

const isMounted = useRef(false);
useEffect(() => {
if (!safeAPI || !daoAddress || isMounted.current) {
return;
}

(async () => {
const safeInfo = await safeAPI.getSafeData(daoAddress);
action.dispatch({
type: NodeAction.SET_SAFE_INFO,
payload: safeInfo,
});
})();

isMounted.current = true;
}, [action, daoAddress, safeAPI]);

if (!type || !daoAddress || !safe) {
return (
<Center minH={`calc(100vh - ${HEADER_HEIGHT})`}>
Expand Down