diff --git a/src/components/DaoCreator/formComponents/GuardDetails.tsx b/src/components/DaoCreator/formComponents/GuardDetails.tsx index 118a74d01f..f6384b0d1a 100644 --- a/src/components/DaoCreator/formComponents/GuardDetails.tsx +++ b/src/components/DaoCreator/formComponents/GuardDetails.tsx @@ -28,10 +28,7 @@ import useStepRedirect from '../hooks/useStepRedirect'; function GuardDetails(props: ICreationStepProps) { const { values, isSubmitting, transactionPending, isSubDAO, setFieldValue, mode, errors } = props; - const { - governance, - readOnly: { dao }, - } = useFractal(); + const { governance } = useFractal(); const { safe } = useDaoInfoStore(); const { type } = governance; const [showCustomNonce, setShowCustomNonce] = useState(); @@ -47,11 +44,11 @@ function GuardDetails(props: ICreationStepProps) { ); useEffect(() => { - if (showCustomNonce === undefined && !dao?.isAzorius && isSubDAO && safe) { + if (showCustomNonce === undefined && !governance.isAzorius && isSubDAO && safe) { setFieldValue('multisig.customNonce', safe.nextNonce); setShowCustomNonce(true); } - }, [isSubDAO, type, setFieldValue, safe, dao, showCustomNonce]); + }, [isSubDAO, type, setFieldValue, safe, governance.isAzorius, showCustomNonce]); const { totalParentVotingWeight, parentVotingQuorum } = useParentSafeVotingWeight(); diff --git a/src/components/DaoCreator/hooks/useParentSafeVotingWeight.ts b/src/components/DaoCreator/hooks/useParentSafeVotingWeight.ts index a3df99d3ad..cb4fe9ce4f 100644 --- a/src/components/DaoCreator/hooks/useParentSafeVotingWeight.ts +++ b/src/components/DaoCreator/hooks/useParentSafeVotingWeight.ts @@ -5,10 +5,7 @@ import { useDaoInfoStore } from '../../../store/daoInfo/useDaoInfoStore'; import { AzoriusGovernance, GovernanceType } from '../../../types/fractal'; export const useParentSafeVotingWeight = () => { - const { - governance, - readOnly: { dao }, - } = useFractal(); + const { governance } = useFractal(); const { safe } = useDaoInfoStore(); const [parentVotingQuorum, setParentVotingQuorum] = useState(); @@ -24,7 +21,7 @@ export const useParentSafeVotingWeight = () => { case GovernanceType.AZORIUS_ERC721: const governanceAzorius = governance as AzoriusGovernance; - if (dao?.isAzorius === false || !governanceAzorius.votingStrategy) { + if (governance.isAzorius === false || !governanceAzorius.votingStrategy) { return; } @@ -68,7 +65,7 @@ export const useParentSafeVotingWeight = () => { setTotalParentVotingWeight(BigInt(safe.owners.length)); setParentVotingQuorum(BigInt(safe.threshold)); } - }, [safe, governance, dao]); + }, [safe, governance]); return { totalParentVotingWeight, diff --git a/src/components/DaoDashboard/Info/InfoGovernance.tsx b/src/components/DaoDashboard/Info/InfoGovernance.tsx index e4ebb0c15d..ded576b516 100644 --- a/src/components/DaoDashboard/Info/InfoGovernance.tsx +++ b/src/components/DaoDashboard/Info/InfoGovernance.tsx @@ -17,7 +17,6 @@ export function InfoGovernance({ showTitle = true }: { showTitle?: boolean }) { const { governance, guardContracts: { freezeGuardType, freezeGuardContractAddress }, - readOnly: { dao }, } = useFractal(); const { safe } = useDaoInfoStore(); const publicClient = usePublicClient(); @@ -25,7 +24,7 @@ export function InfoGovernance({ showTitle = true }: { showTitle?: boolean }) { const [timelockPeriod, setTimelockPeriod] = useState(); const [executionPeriod, setExecutionPeriod] = useState(); - const governanceAzorius = dao?.isAzorius ? (governance as AzoriusGovernance) : null; + const governanceAzorius = governance.isAzorius ? (governance as AzoriusGovernance) : null; useEffect(() => { const setTimelockInfo = async () => { diff --git a/src/components/ProposalBuilder/index.tsx b/src/components/ProposalBuilder/index.tsx index c33bfffae3..45860955bd 100644 --- a/src/components/ProposalBuilder/index.tsx +++ b/src/components/ProposalBuilder/index.tsx @@ -53,7 +53,7 @@ export function ProposalBuilder({ mode === ProposalBuilderMode.PROPOSAL || mode === ProposalBuilderMode.PROPOSAL_WITH_ACTIONS; const { - readOnly: { dao }, + governance: { isAzorius }, } = useFractal(); const { safe } = useDaoInfoStore(); const safeAddress = safe?.address; @@ -222,7 +222,7 @@ export function ProposalBuilder({ mode={mode} {...formikProps} /> - {!dao?.isAzorius && ( + {!isAzorius && ( vote.voter === userAccount.address), ); - } else if (dao?.isAzorius) { + } else if (isAzorius) { const azoriusProposal = proposal as AzoriusProposal; if (azoriusProposal?.votes) { setHasVoted(!!azoriusProposal?.votes.find(vote => vote.voter === userAccount.address)); @@ -96,7 +96,7 @@ export function VoteContextProvider({ ); } setHasVotedLoading(false); - }, [dao, snapshotProposal, proposal, userAccount.address, extendedSnapshotProposal]); + }, [isAzorius, snapshotProposal, proposal, userAccount.address, extendedSnapshotProposal]); const getCanVote = useCallback( async (refetchUserTokens?: boolean) => { diff --git a/src/components/ui/forms/CustomNonceInput.tsx b/src/components/ui/forms/CustomNonceInput.tsx index d8115a75af..da2a70c524 100644 --- a/src/components/ui/forms/CustomNonceInput.tsx +++ b/src/components/ui/forms/CustomNonceInput.tsx @@ -21,7 +21,7 @@ export function CustomNonceInput({ renderTrimmed?: boolean; }) { const { - readOnly: { dao }, + governance: { isAzorius }, } = useFractal(); const { safe } = useDaoInfoStore(); const { t } = useTranslation(['proposal', 'common']); @@ -29,7 +29,7 @@ export function CustomNonceInput({ nonce !== undefined && safe && nonce < safe.nonce ? t('customNonceError') : undefined; const tooltipContainer = useRef(null); - if (dao?.isAzorius) return null; + if (isAzorius) return null; return ( diff --git a/src/components/ui/proposal/useProposalCountdown.tsx b/src/components/ui/proposal/useProposalCountdown.tsx index 76be857dec..557153c9a3 100644 --- a/src/components/ui/proposal/useProposalCountdown.tsx +++ b/src/components/ui/proposal/useProposalCountdown.tsx @@ -23,7 +23,6 @@ export function useProposalCountdown(proposal: FractalProposal) { guardContracts: { freezeGuardContractAddress, freezeGuardType }, governanceContracts, action, - readOnly: { dao }, } = useFractal(); const publicClient = usePublicClient(); @@ -60,7 +59,7 @@ export function useProposalCountdown(proposal: FractalProposal) { // Wrap the updateProposalState call in an async IIFE (async () => { try { - if (dao?.isAzorius) { + if (governance.isAzorius) { await updateProposalState(Number(proposal.proposalId)); } else { await loadDAOProposals(); @@ -82,7 +81,7 @@ export function useProposalCountdown(proposal: FractalProposal) { clearInterval(updateStateInterval.current); } }; - }, [secondsLeft, loadDAOProposals, proposal, updateProposalState, governance.type, dao]); + }, [secondsLeft, loadDAOProposals, proposal, updateProposalState, governance.isAzorius]); const startCountdown = useCallback((initialTimeMs: number) => { countdownInterval.current = setInterval(() => { diff --git a/src/hooks/DAO/useBuildDAOTx.ts b/src/hooks/DAO/useBuildDAOTx.ts index 08dd067aa0..911c11fd53 100644 --- a/src/hooks/DAO/useBuildDAOTx.ts +++ b/src/hooks/DAO/useBuildDAOTx.ts @@ -39,7 +39,6 @@ const useBuildDAOTx = () => { } = useNetworkConfig(); const { - readOnly: { dao }, governance, governanceContracts: { linearVotingErc721Address }, } = useFractal(); @@ -96,7 +95,7 @@ const useBuildDAOTx = () => { let parentStrategyAddress: Address | undefined; const azoriusGovernance = governance as AzoriusGovernance; - if (dao && dao.isAzorius && azoriusGovernance.votingStrategy) { + if (governance.isAzorius && azoriusGovernance.votingStrategy) { parentStrategyType = azoriusGovernance.votingStrategy.strategyType; if (parentStrategyType === VotingStrategyType.LINEAR_ERC721 && linearVotingErc721Address) { parentStrategyAddress = linearVotingErc721Address; @@ -146,7 +145,6 @@ const useBuildDAOTx = () => { linearVotingErc20MasterCopy, linearVotingErc721MasterCopy, moduleAzoriusMasterCopy, - dao, governance, linearVotingErc721Address, ], diff --git a/src/pages/dao/proposals/[proposalId]/index.tsx b/src/pages/dao/proposals/[proposalId]/index.tsx index 01ae603852..0dae6bebdc 100644 --- a/src/pages/dao/proposals/[proposalId]/index.tsx +++ b/src/pages/dao/proposals/[proposalId]/index.tsx @@ -26,8 +26,7 @@ export function SafeProposalDetailsPage() { const { t } = useTranslation(['proposal', 'navigation', 'breadcrumbs', 'dashboard']); const { - governance: { proposals, loadingProposals, allProposalsLoaded }, - readOnly: { dao }, + governance: { proposals, loadingProposals, allProposalsLoaded, isAzorius }, } = useFractal(); const { safe } = useDaoInfoStore(); const { addressPrefix } = useNetworkConfig(); @@ -93,7 +92,7 @@ export function SafeProposalDetailsPage() { /> ) : snapshotProposal !== null ? ( - ) : dao?.isAzorius ? ( + ) : isAzorius ? ( ) : ( diff --git a/src/providers/App/governance/reducer.ts b/src/providers/App/governance/reducer.ts index b7bc5456b1..83369377f0 100644 --- a/src/providers/App/governance/reducer.ts +++ b/src/providers/App/governance/reducer.ts @@ -6,6 +6,7 @@ import { AzoriusGovernance, DecentGovernance, getVoteChoice, + GovernanceType, } from '../../../types'; import { FractalGovernanceAction, @@ -14,6 +15,7 @@ import { } from './action'; export const initialGovernanceState: FractalGovernance = { + isAzorius: false, loadingProposals: true, allProposalsLoaded: false, proposals: null, @@ -49,7 +51,13 @@ export const governanceReducer = (state: FractalGovernance, action: FractalGover case FractalGovernanceAction.SET_LOADING_FIRST_PROPOSAL: return { ...state, loadingProposals: action.payload }; case FractalGovernanceAction.SET_GOVERNANCE_TYPE: - return { ...state, type: action.payload }; + return { + ...state, + type: action.payload, + isAzorius: + action.payload === GovernanceType.AZORIUS_ERC20 || + action.payload === GovernanceType.AZORIUS_ERC721, + }; case FractalGovernanceAction.SET_PROPOSALS: { return { ...state, diff --git a/src/providers/App/useReadOnlyValues.ts b/src/providers/App/useReadOnlyValues.ts index b4743ad69e..f5b4ba7cdd 100644 --- a/src/providers/App/useReadOnlyValues.ts +++ b/src/providers/App/useReadOnlyValues.ts @@ -17,7 +17,6 @@ const INITIAL_READ_ONLY_VALUES: ReadOnlyState = { user: { votingWeight: 0n, }, - dao: null, }; /** * Sets "read only" values which are passed on to the FractalProvider. diff --git a/src/types/fractal.ts b/src/types/fractal.ts index 10b0b31cfd..26bef7620c 100644 --- a/src/types/fractal.ts +++ b/src/types/fractal.ts @@ -242,7 +242,9 @@ export interface DecentTreasury { transfers: TransferDisplayData[] | null; } -export type FractalGovernance = AzoriusGovernance | DecentGovernance | SafeMultisigGovernance; +export type FractalGovernance = (AzoriusGovernance | DecentGovernance | SafeMultisigGovernance) & { + isAzorius: boolean; +}; export interface AzoriusGovernance extends Governance { votingStrategy: VotingStrategyAzorius | undefined; @@ -303,8 +305,6 @@ export type FractalProposal = AzoriusProposal | MultisigProposal | SnapshotPropo * the app. */ export interface ReadOnlyState { - /** The currently connected DAO or null if there isn't one. */ - dao: ReadOnlyDAO | null; /** The "user", meaning the app user, wallet connected or not. */ user: ReadOnlyUser; } @@ -314,11 +314,6 @@ export interface ReadOnlyUser { votingWeight: bigint; } -export interface ReadOnlyDAO { - /** Whether the connected DAO is an Azorius DAO. */ - isAzorius: boolean; -} - export interface TransferDisplayData { eventType: TokenEventType; transferType: TransferType;