Skip to content

Commit

Permalink
Move "isAzorius" from Read Only Values to "governance" state
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgall committed Nov 18, 2024
1 parent 2a99faa commit c72b7a3
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 52 deletions.
9 changes: 3 additions & 6 deletions src/components/DaoCreator/formComponents/GuardDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>();
Expand All @@ -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();

Expand Down
9 changes: 3 additions & 6 deletions src/components/DaoCreator/hooks/useParentSafeVotingWeight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<bigint>();
Expand All @@ -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;
}

Expand Down Expand Up @@ -68,7 +65,7 @@ export const useParentSafeVotingWeight = () => {
setTotalParentVotingWeight(BigInt(safe.owners.length));
setParentVotingQuorum(BigInt(safe.threshold));
}
}, [safe, governance, dao]);
}, [safe, governance]);

return {
totalParentVotingWeight,
Expand Down
3 changes: 1 addition & 2 deletions src/components/DaoDashboard/Info/InfoGovernance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ export function InfoGovernance({ showTitle = true }: { showTitle?: boolean }) {
const {
governance,
guardContracts: { freezeGuardType, freezeGuardContractAddress },
readOnly: { dao },
} = useFractal();
const { safe } = useDaoInfoStore();
const publicClient = usePublicClient();
const { getTimeDuration } = useTimeHelpers();
const [timelockPeriod, setTimelockPeriod] = useState<string>();
const [executionPeriod, setExecutionPeriod] = useState<string>();

const governanceAzorius = dao?.isAzorius ? (governance as AzoriusGovernance) : null;
const governanceAzorius = governance.isAzorius ? (governance as AzoriusGovernance) : null;

useEffect(() => {
const setTimelockInfo = async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/ProposalBuilder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -222,7 +222,7 @@ export function ProposalBuilder({
mode={mode}
{...formikProps}
/>
{!dao?.isAzorius && (
{!isAzorius && (
<Flex
alignItems="center"
justifyContent="space-between"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function AzoriusOrSnapshotProposalAction({
expandedView?: boolean;
}) {
const {
readOnly: { dao },
governance: { isAzorius },
} = useFractal();
const { t } = useTranslation();
const { snapshotProposal } = useSnapshotProposal(proposal);
Expand All @@ -55,10 +55,10 @@ export function AzoriusOrSnapshotProposalAction({
if (!canVote) {
return t('details');
}
return t(dao?.isAzorius ? 'vote' : 'sign');
return t(isAzorius ? 'vote' : 'sign');
}
return t('details');
}, [snapshotProposal, t, canVote, dao, isActiveProposal]);
}, [snapshotProposal, t, canVote, isAzorius, isActiveProposal]);

if (!showActionButton) {
if (!expandedView) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export function VoteContextProvider({
const [hasVotedLoading, setHasVotedLoading] = useState(false);
const [proposalVotesLength, setProposalVotesLength] = useState(0);
const {
readOnly: { user, dao },
governance: { type },
readOnly: { user },
governance: { type, isAzorius },
} = useFractal();
const userAccount = useAccount();
const { safe } = useDaoInfoStore();
Expand All @@ -82,7 +82,7 @@ export function VoteContextProvider({
!!extendedSnapshotProposal &&
!!extendedSnapshotProposal.votes.find(vote => 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));
Expand All @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/forms/CustomNonceInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ export function CustomNonceInput({
renderTrimmed?: boolean;
}) {
const {
readOnly: { dao },
governance: { isAzorius },
} = useFractal();
const { safe } = useDaoInfoStore();
const { t } = useTranslation(['proposal', 'common']);
const errorMessage =
nonce !== undefined && safe && nonce < safe.nonce ? t('customNonceError') : undefined;

const tooltipContainer = useRef<HTMLDivElement>(null);
if (dao?.isAzorius) return null;
if (isAzorius) return null;

return (
<VStack alignItems={align}>
Expand Down
5 changes: 2 additions & 3 deletions src/components/ui/proposal/useProposalCountdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export function useProposalCountdown(proposal: FractalProposal) {
guardContracts: { freezeGuardContractAddress, freezeGuardType },
governanceContracts,
action,
readOnly: { dao },
} = useFractal();
const publicClient = usePublicClient();

Expand Down Expand Up @@ -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();
Expand All @@ -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(() => {
Expand Down
4 changes: 1 addition & 3 deletions src/hooks/DAO/useBuildDAOTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const useBuildDAOTx = () => {
} = useNetworkConfig();

const {
readOnly: { dao },
governance,
governanceContracts: { linearVotingErc721Address },
} = useFractal();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -146,7 +145,6 @@ const useBuildDAOTx = () => {
linearVotingErc20MasterCopy,
linearVotingErc721MasterCopy,
moduleAzoriusMasterCopy,
dao,
governance,
linearVotingErc721Address,
],
Expand Down
5 changes: 2 additions & 3 deletions src/pages/dao/proposals/[proposalId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -93,7 +92,7 @@ export function SafeProposalDetailsPage() {
/>
) : snapshotProposal !== null ? (
<SnapshotProposalDetails proposal={snapshotProposal} />
) : dao?.isAzorius ? (
) : isAzorius ? (
<AzoriusProposalDetails proposal={contextProposal as AzoriusProposal} />
) : (
<MultisigProposalDetails proposal={contextProposal} />
Expand Down
1 change: 0 additions & 1 deletion src/providers/App/combinedReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const initialState = {
guardContracts: initialGuardContractsState,
guard: initialGuardState,
readOnly: {
dao: null,
user: {
votingWeight: 0n,
},
Expand Down
10 changes: 9 additions & 1 deletion src/providers/App/governance/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
AzoriusGovernance,
DecentGovernance,
getVoteChoice,
GovernanceType,
} from '../../../types';
import {
FractalGovernanceAction,
Expand All @@ -14,6 +15,7 @@ import {
} from './action';

export const initialGovernanceState: FractalGovernance = {
isAzorius: false,
loadingProposals: true,
allProposalsLoaded: false,
proposals: null,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 0 additions & 8 deletions src/providers/App/useReadOnlyValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -84,13 +83,6 @@ export const useReadOnlyValues = ({
user: {
votingWeight: await getVotingWeight(),
},
dao: !node.safe?.address
? null // if there is no DAO connected, we return null for this
: {
isAzorius:
governance.type === GovernanceType.AZORIUS_ERC20 ||
governance.type === GovernanceType.AZORIUS_ERC721,
},
};
if (!isEqual(newReadOnlyValues, readOnlyValues)) {
setReadOnlyValues(newReadOnlyValues);
Expand Down
11 changes: 3 additions & 8 deletions src/types/fractal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down

0 comments on commit c72b7a3

Please sign in to comment.