Skip to content

Commit

Permalink
Merge branch 'breakout-issue/typing-dao-info' of github.com:decentdao…
Browse files Browse the repository at this point in the history
…/decent-interface into issue/2530-hierarchy-voting-schema-display
  • Loading branch information
Da-Colon committed Nov 28, 2024
2 parents dd821a1 + 41bfc90 commit a5fa7f2
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import { DAOCreateMode } from './EstablishEssentials';
export function AzoriusGovernance(props: ICreationStepProps) {
const { values, setFieldValue, isSubmitting, transactionPending, isSubDAO, mode } = props;

const { safe, subgraphInfo, daoModules } = useDaoInfoStore();
const { safe, subgraphInfo, modules } = useDaoInfoStore();

const fractalModule = useMemo(() => {
if (!daoModules) return null;
return daoModules.find(_module => _module.moduleType === FractalModuleType.FRACTAL);
}, [daoModules]);
if (!modules) return null;
return modules.find(_module => _module.moduleType === FractalModuleType.FRACTAL);
}, [modules]);

const [showCustomNonce, setShowCustomNonce] = useState<boolean>();
const { t } = useTranslation(['daoCreate', 'common']);
Expand Down
4 changes: 2 additions & 2 deletions src/components/SafeSettings/SettingsNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default function SettingsNavigation() {
const { t } = useTranslation('settings');
const { addressPrefix } = useNetworkConfig();
const { governance } = useFractal();
const { safe, daoModules } = useDaoInfoStore();
const { safe, modules } = useDaoInfoStore();
const azoriusGovernance = governance as AzoriusGovernance;

return (
Expand Down Expand Up @@ -143,7 +143,7 @@ export default function SettingsNavigation() {
textStyle="body-base"
color="neutral-7"
>
{(daoModules ?? []).length + (safe?.guard ? 1 : 0)}
{(modules ?? []).length + (safe?.guard ? 1 : 0)}
</Text>
</SettingsLink>
<SettingsLink
Expand Down
6 changes: 3 additions & 3 deletions src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function ManageDAOMenu() {
parentAddress: dao.subgraphInfo?.parentAddress,
childSafeInfo: {
daoAddress: dao.safe?.address,
daoModules: dao.daoModules,
modules: dao.modules,
},
});

Expand Down Expand Up @@ -166,7 +166,7 @@ export function ManageDAOMenu() {
guard.isFrozen &&
guard.userHasVotes
) {
const fractalModule = (dao.daoModules ?? []).find(
const fractalModule = (dao.modules ?? []).find(
module => module.moduleType === FractalModuleType.FRACTAL,
);
if (fractalModule) {
Expand Down Expand Up @@ -200,7 +200,7 @@ export function ManageDAOMenu() {
addressPrefix,
type,
freezeOption,
dao.daoModules,
dao.modules,
canUserCreateProposal,
]);

Expand Down
4 changes: 2 additions & 2 deletions src/hooks/DAO/loaders/useDecentModules.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback } from 'react';
import { getAddress } from 'viem';
import { usePublicClient } from 'wagmi';
import { FractalModuleData, FractalModuleType } from '../../../types';
import { DecentModule, FractalModuleType } from '../../../types';
import { useAddressContractType } from '../../utils/useAddressContractType';

export const useDecentModules = () => {
Expand All @@ -15,7 +15,7 @@ export const useDecentModules = () => {

const masterCopyData = await getAddressContractType(moduleAddress);

let safeModule: FractalModuleData;
let safeModule: DecentModule;

if (masterCopyData.isModuleAzorius && publicClient) {
safeModule = {
Expand Down
12 changes: 6 additions & 6 deletions src/hooks/DAO/loaders/useFractalGuardContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import { useNetworkConfig } from '../../../providers/NetworkConfig/NetworkConfig
import { useDaoInfoStore } from '../../../store/daoInfo/useDaoInfoStore';
import { FreezeGuardType, FreezeVotingType } from '../../../types';
import { useAddressContractType } from '../../utils/useAddressContractType';
import { FractalModuleData, FractalModuleType, GnosisSafe } from './../../../types/fractal';
import { DecentModule, FractalModuleType, GnosisSafe } from './../../../types/fractal';

export const useFractalGuardContracts = ({ loadOnMount = true }: { loadOnMount?: boolean }) => {
// load key for component; helps prevent unnecessary calls
const loadKey = useRef<string>();
const { action } = useFractal();

const { daoModules, safe, subgraphInfo } = useDaoInfoStore();
const { modules, safe, subgraphInfo } = useDaoInfoStore();

const safeAddress = safe?.address;

Expand All @@ -26,7 +26,7 @@ export const useFractalGuardContracts = ({ loadOnMount = true }: { loadOnMount?:
const publicClient = usePublicClient();

const loadFractalGuardContracts = useCallback(
async (_safe: GnosisSafe, _fractalModules: FractalModuleData[]) => {
async (_safe: GnosisSafe, _fractalModules: DecentModule[]) => {
if (!publicClient) {
return;
}
Expand Down Expand Up @@ -124,11 +124,11 @@ export const useFractalGuardContracts = ({ loadOnMount = true }: { loadOnMount?:
);

const setGuardContracts = useCallback(async () => {
if (!safe || daoModules === null) return;
const contracts = await loadFractalGuardContracts(safe, daoModules);
if (!safe || modules === null) return;
const contracts = await loadFractalGuardContracts(safe, modules);
if (!contracts) return;
action.dispatch({ type: GuardContractAction.SET_GUARD_CONTRACT, payload: contracts });
}, [action, safe, daoModules, loadFractalGuardContracts]);
}, [action, safe, modules, loadFractalGuardContracts]);

useEffect(() => {
if (
Expand Down
10 changes: 5 additions & 5 deletions src/hooks/DAO/loaders/useGovernanceContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export const useGovernanceContracts = () => {
const { getAddressContractType } = useAddressContractType();

const { getVotingStrategies } = useVotingStrategyAddress();
const { daoModules, safe } = node;
const { modules, safe } = node;

const safeAddress = safe?.address;

const loadGovernanceContracts = useCallback(async () => {
const azoriusModule = getAzoriusModuleFromModules(daoModules ?? []);
const azoriusModule = getAzoriusModuleFromModules(modules ?? []);

const votingStrategies = await getVotingStrategies();

Expand Down Expand Up @@ -137,15 +137,15 @@ export const useGovernanceContracts = () => {
},
});
}
}, [action, daoModules, getVotingStrategies, publicClient, getAddressContractType]);
}, [action, modules, getVotingStrategies, publicClient, getAddressContractType]);

useEffect(() => {
if (currentValidAddress.current !== safeAddress && daoModules !== null) {
if (currentValidAddress.current !== safeAddress && modules !== null) {
loadGovernanceContracts();
currentValidAddress.current = safeAddress;
}
if (!safeAddress) {
currentValidAddress.current = null;
}
}, [daoModules, loadGovernanceContracts, safeAddress]);
}, [modules, loadGovernanceContracts, safeAddress]);
};
8 changes: 4 additions & 4 deletions src/hooks/DAO/proposal/useSubmitProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ export default function useSubmitProposal() {
},
action,
} = useFractal();
const { safe, daoModules } = useDaoInfoStore();
const { safe, modules } = useDaoInfoStore();
const safeAPI = useSafeAPI();

const globalAzoriusContract = useMemo(() => {
if (!daoModules || !walletClient) {
if (!modules || !walletClient) {
return;
}
const azoriusModule = getAzoriusModuleFromModules(daoModules);
const azoriusModule = getAzoriusModuleFromModules(modules);
if (!azoriusModule) {
return;
}
Expand All @@ -94,7 +94,7 @@ export default function useSubmitProposal() {
address: azoriusModule.moduleAddress,
client: walletClient,
});
}, [daoModules, walletClient]);
}, [modules, walletClient]);

const lookupModules = useDecentModules();
const {
Expand Down
8 changes: 4 additions & 4 deletions src/hooks/DAO/useClawBack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import {
import { logError } from '../../helpers/errorLogging';
import useBalancesAPI from '../../providers/App/hooks/useBalancesAPI';
import { useSafeAPI } from '../../providers/App/hooks/useSafeAPI';
import { FractalModuleType, FractalModuleData } from '../../types';
import { FractalModuleType, DecentModule } from '../../types';
import { MOCK_MORALIS_ETH_ADDRESS } from '../../utils/address';
import { useCanUserCreateProposal } from '../utils/useCanUserSubmitProposal';
import useSubmitProposal from './proposal/useSubmitProposal';

interface IUseClawBack {
childSafeInfo: {
daoAddress?: Address;
daoModules: FractalModuleData[] | null;
modules: DecentModule[] | null;
};
parentAddress: Address | null | undefined;
}
Expand Down Expand Up @@ -51,8 +51,8 @@ export default function useClawBack({ childSafeInfo, parentAddress }: IUseClawBa
const parentSafeInfo = await safeAPI.getSafeData(parentAddress);
const canUserCreateProposal = await getCanUserCreateProposal(parentAddress);

if (canUserCreateProposal && parentAddress && parentSafeInfo && childSafeInfo.daoModules) {
const fractalModule = childSafeInfo.daoModules!.find(
if (canUserCreateProposal && parentAddress && parentSafeInfo && childSafeInfo.modules) {
const fractalModule = childSafeInfo.modules!.find(
module => module.moduleType === FractalModuleType.FRACTAL,
);

Expand Down
4 changes: 2 additions & 2 deletions src/hooks/DAO/useDeployAzorius.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from '../../types';
import { useAddressContractType } from '../utils/useAddressContractType';
import { useCanUserCreateProposal } from '../utils/useCanUserSubmitProposal';
import { FractalModuleData } from './../../types/fractal';
import { DecentModule } from './../../types/fractal';
import { useDecentModules } from './loaders/useDecentModules';
import useSubmitProposal from './proposal/useSubmitProposal';

Expand Down Expand Up @@ -98,7 +98,7 @@ const useDeployAzorius = () => {
let parentStrategyAddress: Address | undefined;
let parentStrategyType: VotingStrategyType | undefined;
let attachFractalModule = false;
let parentModules: FractalModuleData[];
let parentModules: DecentModule[];

if (subgraphInfo?.parentAddress) {
const loadedParentModule = await getParentDAOModules(subgraphInfo.parentAddress);
Expand Down
4 changes: 1 addition & 3 deletions src/hooks/utils/useUpdateSafeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import { useLocation } from 'react-router-dom';
import { Address } from 'viem';
import { useSafeAPI } from '../../providers/App/hooks/useSafeAPI';
import { useDaoInfoStore } from '../../store/daoInfo/useDaoInfoStore';
import { useDecentModules } from '../DAO/loaders/useDecentModules';

export const useUpdateSafeData = (safeAddress?: Address) => {
const safeAPI = useSafeAPI();
const location = useLocation();
const prevPathname = useRef(location.pathname);
const lookupModules = useDecentModules();
const { setSafeInfo, setDecentModules } = useDaoInfoStore();

useEffect(() => {
Expand All @@ -27,5 +25,5 @@ export const useUpdateSafeData = (safeAddress?: Address) => {
})();
prevPathname.current = location.pathname;
}
}, [safeAddress, safeAPI, location, setSafeInfo, setDecentModules, lookupModules]);
}, [safeAddress, safeAPI, location, setSafeInfo, setDecentModules]);
};
10 changes: 5 additions & 5 deletions src/hooks/utils/useVotingStrategiesAddresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { usePublicClient } from 'wagmi';
import { SENTINEL_ADDRESS } from '../../constants/common';
import { useSafeAPI } from '../../providers/App/hooks/useSafeAPI';
import { useDaoInfoStore } from '../../store/daoInfo/useDaoInfoStore';
import { FractalModuleData } from '../../types';
import { DecentModule } from '../../types';
import { getAzoriusModuleFromModules } from '../../utils';
import { useDecentModules } from '../DAO/loaders/useDecentModules';
import { useAddressContractType } from './useAddressContractType';
Expand All @@ -19,7 +19,7 @@ const useVotingStrategiesAddresses = () => {

const getVotingStrategies = useCallback(
async (safeAddress?: Address) => {
let azoriusModule: FractalModuleData | undefined;
let azoriusModule: DecentModule | undefined;

if (safeAddress) {
if (!safeAPI) {
Expand All @@ -29,10 +29,10 @@ const useVotingStrategiesAddresses = () => {
const safeModules = await lookupModules(safeInfo.modules);
azoriusModule = getAzoriusModuleFromModules(safeModules);
} else {
if (!node.daoModules) {
if (!node.modules) {
throw new Error('DAO modules not ready');
}
azoriusModule = getAzoriusModuleFromModules(node.daoModules);
azoriusModule = getAzoriusModuleFromModules(node.modules);
}

if (!azoriusModule || !publicClient) {
Expand Down Expand Up @@ -62,7 +62,7 @@ const useVotingStrategiesAddresses = () => {
);
return result;
},
[lookupModules, getAddressContractType, node.daoModules, publicClient, safeAPI],
[lookupModules, getAddressContractType, node.modules, publicClient, safeAPI],
);

return { getVotingStrategies };
Expand Down
4 changes: 2 additions & 2 deletions src/models/DaoTxBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '../types';
import { BaseTxBuilder } from './BaseTxBuilder';
import { TxBuilderFactory } from './TxBuilderFactory';
import { fractalModuleData, FractalModuleData } from './helpers/fractalModuleData';
import { fractalModuleData, DecentModule } from './helpers/fractalModuleData';

export class DaoTxBuilder extends BaseTxBuilder {
private readonly saltNum;
Expand Down Expand Up @@ -235,7 +235,7 @@ export class DaoTxBuilder extends BaseTxBuilder {
//

private setFractalModuleTxs(): void {
const { enableFractalModuleTx, deployFractalModuleTx }: FractalModuleData = fractalModuleData(
const { enableFractalModuleTx, deployFractalModuleTx }: DecentModule = fractalModuleData(
this.moduleFractalMasterCopy,
this.zodiacModuleProxyFactory,
this.safeContractAddress,
Expand Down
4 changes: 2 additions & 2 deletions src/models/helpers/fractalModuleData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { buildContractCall } from '../../helpers/crypto';
import { SafeTransaction } from '../../types';
import { generateContractByteCodeLinear, generateSalt } from './utils';

export interface FractalModuleData {
export interface DecentModule {
predictedFractalModuleAddress: string;
deployFractalModuleTx: SafeTransaction;
enableFractalModuleTx: SafeTransaction;
Expand All @@ -26,7 +26,7 @@ export const fractalModuleData = (
safeAddress: Address,
saltNum: bigint,
parentAddress?: Address | null,
): FractalModuleData => {
): DecentModule => {
const fractalModuleCalldata = encodeFunctionData({
abi: abis.FractalModule,
functionName: 'setUp',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function SafeModulesSettingsPage() {
const {
guardContracts: { freezeGuardContractAddress, freezeVotingContractAddress },
} = useFractal();
const { daoModules, safe } = useDaoInfoStore();
const { modules, safe } = useDaoInfoStore();

return (
<>
Expand All @@ -42,9 +42,9 @@ export function SafeModulesSettingsPage() {
w={{ base: 'calc(100% + 1.5rem)', md: 'calc(100% + 3rem)' }}
mx={{ base: '-0.75rem', md: '-1.5rem' }}
/>
{daoModules !== null ? (
daoModules.length > 0 ? (
daoModules.map(({ moduleAddress, moduleType }) => {
{modules !== null ? (
modules.length > 0 ? (
modules.map(({ moduleAddress, moduleType }) => {
const moduleHelper =
moduleType === FractalModuleType.AZORIUS
? ' (Azorius Module)'
Expand Down
12 changes: 6 additions & 6 deletions src/store/daoInfo/useDaoInfoStore.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { getAddress } from 'viem';
import { create } from 'zustand';
import { DAOSubgraph, FractalModuleData, IDAO, SafeWithNextNonce } from '../../types';
import { DAOSubgraph, DecentModule, IDAO, SafeWithNextNonce } from '../../types';

export const initialDaoInfoStore: IDAO = {
safe: null,
subgraphInfo: null,
daoModules: null,
modules: null,
};
export interface DaoInfoStore extends IDAO {
setSafeInfo: (safe: SafeWithNextNonce) => void;
setDaoInfo: (daoInfo: DAOSubgraph) => void;
setDecentModules: (modules: FractalModuleData[]) => void;
setDecentModules: (modules: DecentModule[]) => void;
updateDaoName: (newDaoName: string) => void;
resetDaoInfoStore: () => void;
}
Expand All @@ -22,7 +22,7 @@ export const useDaoInfoStore = create<DaoInfoStore>()(set => ({
set({
safe: {
owners: owners.map(getAddress),
modules: modules.map(getAddress),
modulesAddresses: modules.map(getAddress),
guard: getAddress(guard),
address: getAddress(address),
nextNonce,
Expand All @@ -37,8 +37,8 @@ export const useDaoInfoStore = create<DaoInfoStore>()(set => ({
set({ subgraphInfo });
},

setDecentModules: (daoModules: FractalModuleData[]) => {
set({ daoModules });
setDecentModules: (modules: DecentModule[]) => {
set({ modules });
},
updateDaoName: (newDaoName: string) => {
set(state => {
Expand Down
Loading

0 comments on commit a5fa7f2

Please sign in to comment.