Skip to content

Commit

Permalink
Remove "daoNetwork" from Fractal state, use value from useNetworkConf…
Browse files Browse the repository at this point in the history
…ig everywhere
  • Loading branch information
adamgall committed Mar 28, 2024
1 parent 751d045 commit 2c7f7de
Show file tree
Hide file tree
Showing 37 changed files with 246 additions and 221 deletions.
8 changes: 5 additions & 3 deletions src/components/DaoCreator/StepWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useNavigate } from 'react-router-dom';
import { BACKGROUND_SEMI_TRANSPARENT } from '../../constants/common';
import { BASE_ROUTES, DAO_ROUTES } from '../../constants/routes';
import { useFractal } from '../../providers/App/AppProvider';
import { useNetworkConfig } from '../../providers/NetworkConfig/NetworkConfigProvider';
import PageHeader from '../ui/page/Header/PageHeader';
import { DAOCreateMode } from './formComponents/EstablishEssentials';

Expand All @@ -27,8 +28,9 @@ export function StepWrapper({
shouldWrapChildren = true,
}: IStepWrapper) {
const {
node: { daoAddress, daoNetwork },
node: { daoAddress },
} = useFractal();
const { addressPrefix } = useNetworkConfig();
const { t } = useTranslation(['daoCreate']);
const navigate = useNavigate();

Expand Down Expand Up @@ -64,9 +66,9 @@ export function StepWrapper({
isButtonDisabled={isFormSubmitting}
buttonClick={() =>
navigate(
!isSubDAO || !daoAddress || !daoNetwork
!isSubDAO || !daoAddress
? BASE_ROUTES.landing
: DAO_ROUTES.dao.relative(daoNetwork, daoAddress),
: DAO_ROUTES.dao.relative(addressPrefix, daoAddress),
)
}
/>
Expand Down
10 changes: 6 additions & 4 deletions src/components/ProposalTemplates/ProposalTemplateCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DAO_ROUTES } from '../../constants/routes';
import useRemoveProposalTemplate from '../../hooks/DAO/proposal/useRemoveProposalTemplate';
import useSubmitProposal from '../../hooks/DAO/proposal/useSubmitProposal';
import { useFractal } from '../../providers/App/AppProvider';
import { useNetworkConfig } from '../../providers/NetworkConfig/NetworkConfigProvider';
import { ProposalTemplate } from '../../types/createProposalTemplate';
import ContentBox from '../ui/containers/ContentBox';
import { OptionMenu } from '../ui/menus/OptionMenu';
Expand All @@ -26,8 +27,9 @@ export default function ProposalTemplateCard({
const navigate = useNavigate();
const { t } = useTranslation('proposalTemplate');
const {
node: { safe, daoAddress, daoNetwork },
node: { safe, daoAddress },
} = useFractal();
const { addressPrefix } = useNetworkConfig();

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

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

const nonce = safe?.nonce;
const handleRemoveTemplate = useCallback(async () => {
Expand Down
8 changes: 5 additions & 3 deletions src/components/ProposalTemplates/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ import { Link } from 'react-router-dom';
import { DAO_ROUTES } from '../../constants/routes';
import useSubmitProposal from '../../hooks/DAO/proposal/useSubmitProposal';
import { useFractal } from '../../providers/App/AppProvider';
import { useNetworkConfig } from '../../providers/NetworkConfig/NetworkConfigProvider';
import { EmptyBox } from '../ui/containers/EmptyBox';
import { InfoBoxLoader } from '../ui/loaders/InfoBoxLoader';
import ProposalTemplateCard from './ProposalTemplateCard';

export default function ProposalTemplates() {
const { t } = useTranslation('proposalTemplate');
const {
node: { daoAddress, daoNetwork },
node: { daoAddress },
governance: { proposalTemplates },
} = useFractal();
const { addressPrefix } = useNetworkConfig();
const { canUserCreateProposal } = useSubmitProposal();

return (
Expand All @@ -36,8 +38,8 @@ export default function ProposalTemplates() {
))
) : (
<EmptyBox emptyText={t('emptyProposalTemplates')}>
{canUserCreateProposal && daoNetwork && daoAddress && (
<Link to={DAO_ROUTES.proposalTemplateNew.relative(daoNetwork, daoAddress)}>
{canUserCreateProposal && daoAddress && (
<Link to={DAO_ROUTES.proposalTemplateNew.relative(addressPrefix, daoAddress)}>
<Button
variant="text"
textStyle="text-xl-mono-bold"
Expand Down
8 changes: 5 additions & 3 deletions src/components/Proposals/ProposalCard/ProposalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';
import { Link } from 'react-router-dom';
import { DAO_ROUTES } from '../../../constants/routes';
import { useFractal } from '../../../providers/App/AppProvider';
import { useNetworkConfig } from '../../../providers/NetworkConfig/NetworkConfigProvider';
import { ActivityEventType, FractalProposal, SnapshotProposal } from '../../../types';
import { DEFAULT_DATE_FORMAT } from '../../../utils';
import { ActivityDescription } from '../../Activity/ActivityDescription';
Expand All @@ -12,8 +13,9 @@ import QuorumBadge from '../../ui/badges/QuorumBadge';

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

const eventDateLabel = t(
Expand All @@ -26,12 +28,12 @@ function ProposalCard({ proposal }: { proposal: FractalProposal }) {

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

if (!daoNetwork || !daoAddress) {
if (!daoAddress) {
return null;
}

return (
<Link to={DAO_ROUTES.proposal.relative(daoNetwork, daoAddress, proposal.proposalId)}>
<Link to={DAO_ROUTES.proposal.relative(addressPrefix, daoAddress, proposal.proposalId)}>
<Box
minHeight="6.25rem"
bg="chocolate.900"
Expand Down
8 changes: 5 additions & 3 deletions src/components/Proposals/ProposalsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import { Link } from 'react-router-dom';
import { DAO_ROUTES } from '../../constants/routes';
import useSubmitProposal from '../../hooks/DAO/proposal/useSubmitProposal';
import { useFractal } from '../../providers/App/AppProvider';
import { useNetworkConfig } from '../../providers/NetworkConfig/NetworkConfigProvider';
import { FractalProposal } from '../../types';
import { EmptyBox } from '../ui/containers/EmptyBox';
import { InfoBoxLoader } from '../ui/loaders/InfoBoxLoader';
import ProposalCard from './ProposalCard/ProposalCard';

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

const { t } = useTranslation('proposal');
Expand All @@ -34,8 +36,8 @@ export function ProposalsList({ proposals }: { proposals: FractalProposal[] }) {
))
) : (
<EmptyBox emptyText={t('emptyProposals')}>
{canUserCreateProposal && daoNetwork && daoAddress && (
<Link to={DAO_ROUTES.proposalNew.relative(daoNetwork, daoAddress)}>
{canUserCreateProposal && daoAddress && (
<Link to={DAO_ROUTES.proposalNew.relative(addressPrefix, daoAddress)}>
<Button
variant="text"
textStyle="text-xl-mono-bold"
Expand Down
8 changes: 5 additions & 3 deletions src/components/pages/DaoDashboard/Info/ParentLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,28 @@ import { useTranslation } from 'react-i18next';
import { Link as RouterLink } from 'react-router-dom';
import { DAO_ROUTES } from '../../../../constants/routes';
import { useFractal } from '../../../../providers/App/AppProvider';
import { useNetworkConfig } from '../../../../providers/NetworkConfig/NetworkConfigProvider';

/**
* Displays a link to the current DAO's parent, if it has one.
*/
export function ParentLink() {
const {
node: { nodeHierarchy, daoNetwork },
node: { nodeHierarchy },
action,
} = useFractal();
const { addressPrefix } = useNetworkConfig();
const { t } = useTranslation('breadcrumbs');

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

return (
<Link
color="gold.500"
_hover={{ textDecoration: 'none', color: 'gold.500-hover' }}
href={DAO_ROUTES.dao.relative(daoNetwork, nodeHierarchy.parentAddress)}
href={DAO_ROUTES.dao.relative(addressPrefix, nodeHierarchy.parentAddress)}
onClick={action.resetDAO}
marginBottom="1rem"
as={RouterLink}
Expand Down
12 changes: 7 additions & 5 deletions src/components/pages/DaoDashboard/Info/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Box, Flex, Text } from '@chakra-ui/react';
import { DAO_ROUTES } from '../../../../constants/routes';
import useDAOMetadata from '../../../../hooks/DAO/useDAOMetadata';
import { useFractal } from '../../../../providers/App/AppProvider';
import { useNetworkConfig } from '../../../../providers/NetworkConfig/NetworkConfigProvider';
import { InfoBox } from '../../../ui/containers/InfoBox';
import ExternalLink from '../../../ui/links/ExternalLink';
import { InfoDAO } from './InfoDAO';
Expand All @@ -12,8 +13,9 @@ import { ParentLink } from './ParentLink';

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

// using this gap method instead of 'gap' to make width percentages more precise, since they
Expand Down Expand Up @@ -135,8 +137,8 @@ export function Info() {
pb={{ sm: PAD, md: NONE }}
pt={{ sm: PAD, lg: NONE }}
>
{daoNetwork && daoAddress && (
<InfoBox to={DAO_ROUTES.proposals.relative(daoNetwork, daoAddress)}>
{daoAddress && (
<InfoBox to={DAO_ROUTES.proposals.relative(addressPrefix, daoAddress)}>
<InfoProposals />
</InfoBox>
)}
Expand All @@ -146,8 +148,8 @@ export function Info() {
ps={{ base: NONE, md: PAD }}
pt={{ sm: PAD, lg: NONE }}
>
{daoNetwork && daoAddress && (
<InfoBox to={DAO_ROUTES.treasury.relative(daoNetwork, daoAddress)}>
{daoAddress && (
<InfoBox to={DAO_ROUTES.treasury.relative(addressPrefix, daoAddress)}>
<InfoTreasury />
</InfoBox>
)}
Expand Down
12 changes: 5 additions & 7 deletions src/components/pages/DaoHierarchy/DaoNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useEffect, useState } from 'react';
import { useLoadDAONode } from '../../../hooks/DAO/loaders/useLoadDAONode';
import { useLoadDAOData } from '../../../hooks/DAO/useDAOData';
import { useFractal } from '../../../providers/App/AppProvider';
import { useNetworkConfig } from '../../../providers/NetworkConfig/NetworkConfigProvider';
import { FractalNode, WithError } from '../../../types';
import { DAONodeRow } from '../../ui/cards/DAONodeRow';
import { NodeLineVertical } from './NodeLines';
Expand All @@ -20,12 +21,10 @@ import { NodeLineVertical } from './NodeLines';
export function DaoNode({
parentAddress,
daoAddress,
daoNetwork,
depth,
}: {
parentAddress?: string;
daoAddress?: string;
daoNetwork?: string;
depth: number;
}) {
const [fractalNode, setNode] = useState<FractalNode>();
Expand All @@ -36,12 +35,13 @@ export function DaoNode({
const {
node: { daoAddress: currentDAOAddress }, // used ONLY to determine if we're on the current DAO
} = useFractal();
const { addressPrefix } = useNetworkConfig();

const isCurrentDAO = daoAddress === currentDAOAddress;

useEffect(() => {
if (daoAddress && daoNetwork && !fractalNode) {
loadDao(daoNetwork, utils.getAddress(daoAddress)).then(_node => {
if (daoAddress && !fractalNode) {
loadDao(utils.getAddress(daoAddress)).then(_node => {
const errorNode = _node as WithError;
if (!errorNode.error) {
// calculates the total number of descendants below the given node
Expand Down Expand Up @@ -72,7 +72,6 @@ export function DaoNode({
setNode({
daoName: null,
daoAddress,
daoNetwork,
safe: null,
fractalModules: [],
nodeHierarchy: {
Expand All @@ -83,7 +82,7 @@ export function DaoNode({
}
});
}
}, [loadDao, daoAddress, fractalNode, depth, daoNetwork]);
}, [loadDao, daoAddress, fractalNode, depth, addressPrefix]);

return (
<Box position="relative">
Expand All @@ -109,7 +108,6 @@ export function DaoNode({
<DaoNode
parentAddress={daoAddress}
daoAddress={childNode.daoAddress || undefined}
daoNetwork={daoNetwork}
depth={depth + 1}
/>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { DAO_ROUTES } from '../../../../../constants/routes';
import useSubmitProposal from '../../../../../hooks/DAO/proposal/useSubmitProposal';
import { createAccountSubstring } from '../../../../../hooks/utils/useDisplayName';
import { useFractal } from '../../../../../providers/App/AppProvider';
import { useNetworkConfig } from '../../../../../providers/NetworkConfig/NetworkConfigProvider';
import { ProposalExecuteData } from '../../../../../types';
import { couldBeENS } from '../../../../../utils/url';
import { InputComponent } from '../../../../ui/forms/InputComponent';
Expand All @@ -22,11 +23,12 @@ export default function MetadataContainer() {
const { canUserCreateProposal, submitProposal } = useSubmitProposal();
const {
baseContracts,
node: { daoName, daoSnapshotURL, daoAddress, safe, daoNetwork },
node: { daoName, daoSnapshotURL, daoAddress, safe },
readOnly: {
user: { votingWeight },
},
} = useFractal();
const { addressPrefix } = useNetworkConfig();

useEffect(() => {
if (daoName && daoAddress && createAccountSubstring(daoAddress) !== daoName) {
Expand All @@ -51,8 +53,8 @@ export default function MetadataContainer() {
const userHasVotingWeight = votingWeight.gt(0);

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

Expand Down
8 changes: 5 additions & 3 deletions src/components/ui/cards/DAOInfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Link as RouterLink } from 'react-router-dom';
import { DAO_ROUTES } from '../../../constants/routes';
import useDisplayName from '../../../hooks/utils/useDisplayName';
import { useFractal } from '../../../providers/App/AppProvider';
import { useNetworkConfig } from '../../../providers/NetworkConfig/NetworkConfigProvider';
import { FreezeGuard, FractalGuardContracts, FractalNode } from '../../../types';
import Snapshot from '../badges/Snapshot';
import FavoriteIcon from '../icons/FavoriteIcon';
Expand Down Expand Up @@ -42,11 +43,12 @@ export function DAOInfoCard({
action,
readOnly: { user },
} = useFractal();
const { addressPrefix } = useNetworkConfig();
// for non Fractal Safes
const { displayName } = useDisplayName(node?.daoAddress);

// node hasn't loaded yet
if (!node || !node.daoAddress || !node.daoNetwork) {
if (!node || !node.daoAddress) {
return (
<Flex
w="full"
Expand Down Expand Up @@ -77,7 +79,7 @@ export function DAOInfoCard({
<Link
as={RouterLink}
pointerEvents={isCurrentDAO ? 'none' : undefined}
to={DAO_ROUTES.dao.relative(node.daoNetwork, displayedAddress)}
to={DAO_ROUTES.dao.relative(addressPrefix, displayedAddress)}
_hover={{ textDecoration: 'none' }}
onClick={() => {
// if we're not on the current DAO, reset
Expand All @@ -104,7 +106,7 @@ export function DAOInfoCard({
/>
{childCount && childCount > 0 && (
<Link
to={DAO_ROUTES.hierarchy.relative(node.daoNetwork, displayedAddress)}
to={DAO_ROUTES.hierarchy.relative(addressPrefix, displayedAddress)}
as={RouterLink}
>
<Box
Expand Down
Loading

0 comments on commit 2c7f7de

Please sign in to comment.