Skip to content

Commit

Permalink
Update DAO_ROUTES.relative to take network prefix, fix all errors
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgall committed Mar 27, 2024
1 parent 14a927f commit 789573e
Show file tree
Hide file tree
Showing 35 changed files with 204 additions and 127 deletions.
6 changes: 4 additions & 2 deletions src/components/DaoCreator/StepWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function StepWrapper({
shouldWrapChildren = true,
}: IStepWrapper) {
const {
node: { daoAddress },
node: { daoAddress, daoNetwork },
} = useFractal();
const { t } = useTranslation(['daoCreate']);
const navigate = useNavigate();
Expand Down Expand Up @@ -64,7 +64,9 @@ export function StepWrapper({
isButtonDisabled={isFormSubmitting}
buttonClick={() =>
navigate(
!isSubDAO || !daoAddress ? BASE_ROUTES.landing : DAO_ROUTES.dao.relative(daoAddress),
!isSubDAO || !daoAddress || !daoNetwork
? BASE_ROUTES.landing
: DAO_ROUTES.dao.relative(daoNetwork, daoAddress),
)
}
/>
Expand Down
8 changes: 4 additions & 4 deletions src/components/ProposalTemplates/ProposalTemplateCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function ProposalTemplateCard({
const navigate = useNavigate();
const { t } = useTranslation('proposalTemplate');
const {
node: { safe, daoAddress },
node: { safe, daoAddress, daoNetwork },
} = useFractal();

const { prepareRemoveProposalTemplateProposal } = useRemoveProposalTemplate();
Expand All @@ -42,11 +42,11 @@ export default function ProposalTemplateCard({
});

const successCallback = useCallback(() => {
if (daoAddress) {
if (daoAddress && daoNetwork) {
// Redirecting to proposals page so that user will see Proposal for Proposal Template creation
navigate(DAO_ROUTES.proposals.relative(daoAddress));
navigate(DAO_ROUTES.proposals.relative(daoNetwork, daoAddress));
}
}, [navigate, daoAddress]);
}, [navigate, daoAddress, daoNetwork]);

const nonce = safe?.nonce;
const handleRemoveTemplate = useCallback(async () => {
Expand Down
6 changes: 3 additions & 3 deletions src/components/ProposalTemplates/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ProposalTemplateCard from './ProposalTemplateCard';
export default function ProposalTemplates() {
const { t } = useTranslation('proposalTemplate');
const {
node: { daoAddress },
node: { daoAddress, daoNetwork },
governance: { proposalTemplates },
} = useFractal();
const { canUserCreateProposal } = useSubmitProposal();
Expand All @@ -36,8 +36,8 @@ export default function ProposalTemplates() {
))
) : (
<EmptyBox emptyText={t('emptyProposalTemplates')}>
{canUserCreateProposal && (
<Link to={DAO_ROUTES.proposalTemplateNew.relative(daoAddress)}>
{canUserCreateProposal && daoNetwork && daoAddress && (
<Link to={DAO_ROUTES.proposalTemplateNew.relative(daoNetwork, daoAddress)}>
<Button
variant="text"
textStyle="text-xl-mono-bold"
Expand Down
8 changes: 6 additions & 2 deletions src/components/Proposals/ProposalCard/ProposalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import QuorumBadge from '../../ui/badges/QuorumBadge';

function ProposalCard({ proposal }: { proposal: FractalProposal }) {
const {
node: { daoAddress },
node: { daoAddress, daoNetwork },
} = useFractal();
const { t } = useTranslation('common');

Expand All @@ -26,8 +26,12 @@ function ProposalCard({ proposal }: { proposal: FractalProposal }) {

const isSnapshotProposal = !!(proposal as SnapshotProposal).snapshotProposalId;

if (!daoNetwork || !daoAddress) {
return <></>;
}

return (
<Link to={DAO_ROUTES.proposal.relative(daoAddress, proposal.proposalId)}>
<Link to={DAO_ROUTES.proposal.relative(daoNetwork, daoAddress, proposal.proposalId)}>
<Box
minHeight="6.25rem"
bg="chocolate.900"
Expand Down
6 changes: 3 additions & 3 deletions src/components/Proposals/ProposalsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ProposalCard from './ProposalCard/ProposalCard';

export function ProposalsList({ proposals }: { proposals: FractalProposal[] }) {
const {
node: { daoAddress },
node: { daoAddress, daoNetwork },
} = useFractal();
const { canUserCreateProposal } = useSubmitProposal();

Expand All @@ -34,8 +34,8 @@ export function ProposalsList({ proposals }: { proposals: FractalProposal[] }) {
))
) : (
<EmptyBox emptyText={t('emptyProposals')}>
{canUserCreateProposal && (
<Link to={DAO_ROUTES.proposalNew.relative(daoAddress)}>
{canUserCreateProposal && daoNetwork && daoAddress && (
<Link to={DAO_ROUTES.proposalNew.relative(daoNetwork, daoAddress)}>
<Button
variant="text"
textStyle="text-xl-mono-bold"
Expand Down
4 changes: 3 additions & 1 deletion src/components/pages/AppHome/FeaturedDAOCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ interface DAOFeatureProps extends BoxProps {
iconSrc: string;
title: string;
desc: string;
network: string;
address: string;
}

export default function FeaturedDAOCard({
iconSrc,
title,
desc,
network,
address,
...rest
}: DAOFeatureProps) {
Expand Down Expand Up @@ -57,7 +59,7 @@ export default function FeaturedDAOCard({
_hover={{ color: 'gold.500-hover' }}
alignSelf="end"
textStyle="text-lg-mono-bold"
to={DAO_ROUTES.dao.relative(address)}
to={DAO_ROUTES.dao.relative(network, address)}
>
{t('featureLink')}
</Link>
Expand Down
6 changes: 3 additions & 3 deletions src/components/pages/DaoDashboard/Info/ParentLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import { useFractal } from '../../../../providers/App/AppProvider';
*/
export function ParentLink() {
const {
node: { nodeHierarchy },
node: { nodeHierarchy, daoNetwork },
action,
} = useFractal();
const { t } = useTranslation('breadcrumbs');

if (!nodeHierarchy.parentAddress) {
if (!nodeHierarchy.parentAddress || !daoNetwork) {
return null;
}

return (
<Link
color="gold.500"
_hover={{ textDecoration: 'none', color: 'gold.500-hover' }}
href={DAO_ROUTES.dao.relative(nodeHierarchy.parentAddress)}
href={DAO_ROUTES.dao.relative(daoNetwork, nodeHierarchy.parentAddress)}
onClick={action.resetDAO}
marginBottom="1rem"
as={RouterLink}
Expand Down
18 changes: 11 additions & 7 deletions src/components/pages/DaoDashboard/Info/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ParentLink } from './ParentLink';

export function Info() {
const {
node: { daoAddress },
node: { daoAddress, daoNetwork },
} = useFractal();
const daoMetadata = useDAOMetadata();

Expand Down Expand Up @@ -135,18 +135,22 @@ export function Info() {
pb={{ sm: PAD, md: NONE }}
pt={{ sm: PAD, lg: NONE }}
>
<InfoBox to={DAO_ROUTES.proposals.relative(daoAddress)}>
<InfoProposals />
</InfoBox>
{daoNetwork && daoAddress && (
<InfoBox to={DAO_ROUTES.proposals.relative(daoNetwork, daoAddress)}>
<InfoProposals />
</InfoBox>
)}
</Box>
<Box
width={{ base: '100%', md: '33.3%', lg: '23%', xl: '20%' }}
ps={{ base: NONE, md: PAD }}
pt={{ sm: PAD, lg: NONE }}
>
<InfoBox to={DAO_ROUTES.treasury.relative(daoAddress)}>
<InfoTreasury />
</InfoBox>
{daoNetwork && daoAddress && (
<InfoBox to={DAO_ROUTES.treasury.relative(daoNetwork, daoAddress)}>
<InfoTreasury />
</InfoBox>
)}
</Box>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function MetadataContainer() {
const { canUserCreateProposal, submitProposal } = useSubmitProposal();
const {
baseContracts,
node: { daoName, daoSnapshotURL, daoAddress, safe },
node: { daoName, daoSnapshotURL, daoAddress, safe, daoNetwork },
readOnly: {
user: { votingWeight },
},
Expand Down Expand Up @@ -50,7 +50,11 @@ export default function MetadataContainer() {

const userHasVotingWeight = votingWeight.gt(0);

const submitProposalSuccessCallback = () => navigate(DAO_ROUTES.proposals.relative(daoAddress));
const submitProposalSuccessCallback = () => {
if (daoNetwork && daoAddress) {
navigate(DAO_ROUTES.proposals.relative(daoNetwork, daoAddress));
}
};

const handleEditDAOName = () => {
if (!baseContracts) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/ui/cards/DAOInfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function DAOInfoCard({
const { displayName } = useDisplayName(node?.daoAddress);

// node hasn't loaded yet
if (!node || !node.daoAddress) {
if (!node || !node.daoAddress || !node.daoNetwork) {
return (
<Flex
w="full"
Expand Down Expand Up @@ -77,7 +77,7 @@ export function DAOInfoCard({
<Link
as={RouterLink}
pointerEvents={isCurrentDAO ? 'none' : undefined}
to={DAO_ROUTES.dao.relative(displayedAddress)}
to={DAO_ROUTES.dao.relative(node.daoNetwork, displayedAddress)}
_hover={{ textDecoration: 'none' }}
onClick={() => {
// if we're not on the current DAO, reset
Expand All @@ -104,7 +104,7 @@ export function DAOInfoCard({
/>
{childCount && childCount > 0 && (
<Link
to={DAO_ROUTES.hierarchy.relative(displayedAddress)}
to={DAO_ROUTES.hierarchy.relative(node.daoNetwork, displayedAddress)}
as={RouterLink}
>
<Box
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/menus/DAOSearch/SearchDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function SearchDisplay({
onClickView();
if (closeDrawer) closeDrawer();
action.resetDAO();
navigate(DAO_ROUTES.dao.relative(`${addressPrefix}:${address}`));
navigate(DAO_ROUTES.dao.relative(addressPrefix, address));
}}
>
{t('labelViewDAO')}
Expand Down
5 changes: 3 additions & 2 deletions src/components/ui/menus/FavoritesMenu/Favorite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import useDAOName from '../../../../hooks/DAO/useDAOName';
import { useFractal } from '../../../../providers/App/AppProvider';

interface IFavorite {
network: string;
address: string;
}
export function Favorite({ address }: IFavorite) {
export function Favorite({ network, address }: IFavorite) {
const { daoRegistryName } = useDAOName({ address });
const { action } = useFractal();
const navigate = useNavigate();

const onClickNav = () => {
action.resetDAO();
navigate(DAO_ROUTES.dao.relative(address));
navigate(DAO_ROUTES.dao.relative(network, address));
};

return (
Expand Down
3 changes: 3 additions & 0 deletions src/components/ui/menus/FavoritesMenu/FavoritesList.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Box, MenuList } from '@chakra-ui/react';
import { useTranslation } from 'react-i18next';
import { useAccountFavorites } from '../../../../hooks/DAO/loaders/useFavorites';
import { useNetworkConfig } from '../../../../providers/NetworkConfig/NetworkConfigProvider';
import { Favorite } from './Favorite';

export function FavoritesList() {
const { favoritesList } = useAccountFavorites();
const { addressPrefix } = useNetworkConfig();

const { t } = useTranslation('dashboard');
return (
Expand Down Expand Up @@ -45,6 +47,7 @@ export function FavoritesList() {
{favoritesList.map(favorite => (
<Favorite
key={favorite}
network={addressPrefix}
address={favorite}
/>
))}
Expand Down
33 changes: 19 additions & 14 deletions src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,33 @@ export function ManageDAOMenu({
const [canUserCreateProposal, setCanUserCreateProposal] = useState(false);
const [governanceType, setGovernanceType] = useState(GovernanceType.MULTISIG);
const {
node: { safe },
node: { safe, daoNetwork, daoAddress },
governance: { type },
baseContracts,
} = useFractal();
const currentTime = BigNumber.from(useBlockTimestamp());
const navigate = useNavigate();
const safeAddress = fractalNode?.daoAddress;
const { getZodiacModuleProxyMasterCopyData } = useMasterCopy();
const { getCanUserCreateProposal } = useSubmitProposal();
const { getUserERC721VotingTokens } = useUserERC721VotingTokens(undefined, safeAddress, false);
const { getUserERC721VotingTokens } = useUserERC721VotingTokens(undefined, daoAddress, false);
const { handleClawBack } = useClawBack({
parentAddress,
childSafeInfo: fractalNode,
});

useEffect(() => {
const loadCanUserCreateProposal = async () => {
if (safeAddress) {
setCanUserCreateProposal(await getCanUserCreateProposal(safeAddress));
if (daoAddress) {
setCanUserCreateProposal(await getCanUserCreateProposal(daoAddress));
}
};

loadCanUserCreateProposal();
}, [safeAddress, getCanUserCreateProposal]);
}, [daoAddress, getCanUserCreateProposal]);

useEffect(() => {
const loadGovernanceType = async () => {
if (safe && safe.address && safe.address === safeAddress && type) {
if (safe && safe.address && safe.address === daoAddress && type) {
// Since safe.address (global scope DAO address) and safeAddress(Node provided to this component via props)
// are the same - we can simply grab governance type from global scope and avoid double-fetching
setGovernanceType(type);
Expand Down Expand Up @@ -124,19 +123,24 @@ export function ManageDAOMenu({
};

loadGovernanceType();
}, [fractalNode, safe, safeAddress, type, getZodiacModuleProxyMasterCopyData, baseContracts]);
}, [fractalNode, safe, daoAddress, type, getZodiacModuleProxyMasterCopyData, baseContracts]);

const handleNavigateToSettings = useCallback(
() => navigate(DAO_ROUTES.settings.relative(safeAddress)),
[navigate, safeAddress],
);
const handleNavigateToSettings = useCallback(() => {
if (daoNetwork && daoAddress) {
navigate(DAO_ROUTES.settings.relative(daoNetwork, daoAddress));
}
}, [navigate, daoAddress, daoNetwork]);

const handleModifyGovernance = useFractalModal(ModalType.CONFIRM_MODIFY_GOVERNANCE);

const options = useMemo(() => {
const createSubDAOOption = {
optionKey: 'optionCreateSubDAO',
onClick: () => navigate(DAO_ROUTES.newSubDao.relative(safeAddress)),
onClick: () => {
if (daoNetwork && daoAddress) {
navigate(DAO_ROUTES.newSubDao.relative(daoNetwork, daoAddress));
}
},
};

const freezeOption = {
Expand Down Expand Up @@ -226,7 +230,7 @@ export function ManageDAOMenu({
freezeGuard,
currentTime,
navigate,
safeAddress,
daoAddress,
parentAddress,
governanceType,
guardContracts?.freezeVotingContract?.asSigner,
Expand All @@ -236,6 +240,7 @@ export function ManageDAOMenu({
handleModifyGovernance,
handleNavigateToSettings,
getUserERC721VotingTokens,
daoNetwork,
]);

return (
Expand Down
Loading

0 comments on commit 789573e

Please sign in to comment.