Skip to content

Commit

Permalink
Merge commit 'bb5984d30f2366e6ba3f60220d415d54104474d6' into enhancem…
Browse files Browse the repository at this point in the history
…ent/1483-chainspacing
  • Loading branch information
adamgall committed Mar 29, 2024
2 parents 9447ffa + bb5984d commit 9396909
Show file tree
Hide file tree
Showing 27 changed files with 364 additions and 308 deletions.
18 changes: 8 additions & 10 deletions src/components/Proposals/MultisigProposalDetails/TxActions.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Box, Button, Text, Flex } from '@chakra-ui/react';
import { Check } from '@decent-org/fractal-ui';
import { TypedDataSigner } from '@ethersproject/abstract-signer';
import { MultisigFreezeGuard } from '@fractal-framework/fractal-contracts';
import { SafeMultisigTransactionWithTransfersResponse } from '@safe-global/safe-service-client';
import { Signer } from 'ethers';
import { useTranslation } from 'react-i18next';
Expand All @@ -10,6 +9,7 @@ import { BACKGROUND_SEMI_TRANSPARENT } from '../../../constants/common';
import { buildSafeTransaction, buildSignatureBytes, EIP712_SAFE_TX_TYPE } from '../../../helpers';
import { logError } from '../../../helpers/errorLogging';
import { useSafeMultisigProposals } from '../../../hooks/DAO/loaders/governance/useSafeMultisigProposals';
import useSafeContracts from '../../../hooks/safe/useSafeContracts';
import { useAsyncRequest } from '../../../hooks/utils/useAsyncRequest';
import useSignerOrProvider from '../../../hooks/utils/useSignerOrProvider';
import { useTransaction } from '../../../hooks/utils/useTransaction';
Expand All @@ -20,15 +20,10 @@ import { MultisigProposal, FractalProposalState } from '../../../types';
import ContentBox from '../../ui/containers/ContentBox';
import { ProposalCountdown } from '../../ui/proposal/ProposalCountdown';

export function TxActions({
proposal,
freezeGuard,
}: {
proposal: MultisigProposal;
freezeGuard: MultisigFreezeGuard;
}) {
export function TxActions({ proposal }: { proposal: MultisigProposal }) {
const {
node: { safe },
guardContracts: { freezeGuardContractAddress },
readOnly: { user },
} = useFractal();
const signerOrProvider = useSignerOrProvider();
Expand All @@ -40,7 +35,7 @@ export function TxActions({
const [asyncRequest, asyncRequestPending] = useAsyncRequest();
const [contractCall, contractCallPending] = useTransaction();
const loadSafeMultisigProposals = useSafeMultisigProposals();

const baseContracts = useSafeContracts();
if (user.votingWeight.eq(0)) return <></>;

const multisigTx = proposal.transaction as SafeMultisigTransactionWithTransfersResponse;
Expand Down Expand Up @@ -78,7 +73,7 @@ export function TxActions({

const timelockTransaction = async () => {
try {
if (!multisigTx.confirmations) {
if (!multisigTx.confirmations || !baseContracts || !freezeGuardContractAddress) {
return;
}
const safeTx = buildSafeTransaction({
Expand All @@ -90,6 +85,9 @@ export function TxActions({
data: confirmation.signature,
})),
);
const freezeGuard = baseContracts.multisigFreezeGuardMasterCopyContract.asSigner.attach(
freezeGuardContractAddress,
);
contractCall({
contractFn: () =>
freezeGuard.timelockTransaction(
Expand Down
9 changes: 1 addition & 8 deletions src/components/Proposals/MultisigProposalDetails/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { GridItem, Box } from '@chakra-ui/react';
import { MultisigFreezeGuard } from '@fractal-framework/fractal-contracts';
import { BACKGROUND_SEMI_TRANSPARENT } from '../../../constants/common';
import { useFractal } from '../../../providers/App/AppProvider';
import { FractalProposal, MultisigProposal } from '../../../types';
Expand All @@ -14,7 +13,6 @@ import { TxDetails } from './TxDetails';
export function MultisigProposalDetails({ proposal }: { proposal: FractalProposal }) {
const txProposal = proposal as MultisigProposal;
const {
guardContracts: { freezeGuardContract },
readOnly: { user },
} = useFractal();
return (
Expand All @@ -30,12 +28,7 @@ export function MultisigProposalDetails({ proposal }: { proposal: FractalProposa
</GridItem>
<GridItem colSpan={1}>
<TxDetails proposal={txProposal} />
{user.address && (
<TxActions
proposal={txProposal}
freezeGuard={freezeGuardContract?.asSigner as MultisigFreezeGuard}
/>
)}
{user.address && <TxActions proposal={txProposal} />}
</GridItem>
</ProposalDetailsGrid>
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/Proposals/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function Proposals() {
break;
case GovernanceType.MULTISIG:
default:
if (guardContracts.freezeGuardContract) {
if (guardContracts.freezeGuardContractAddress) {
options = FILTERS_MULTISIG_CHILD;
} else {
options = FILTERS_MULTISIG_BASE;
Expand All @@ -77,7 +77,7 @@ export default function Proposals() {
}
setAllOptions(options);
setFilters(options);
}, [daoSnapshotURL, guardContracts.freezeGuardContract, type]);
}, [daoSnapshotURL, guardContracts.freezeGuardContractAddress, type]);

const toggleFilter = (filter: FractalProposalState) => {
setFilters(prevState => {
Expand Down
3 changes: 2 additions & 1 deletion src/components/pages/DaoDashboard/Activities/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useActivities } from './hooks/useActivities';

export function Activities() {
const {
guardContracts: { freezeVotingContractAddress },
guard,
governance: { type },
} = useFractal();
Expand All @@ -37,7 +38,7 @@ export function Activities() {
flexDirection="column"
gap="1rem"
>
{guard.freezeProposalVoteCount?.gt(0) && <ActivityFreeze />}
{freezeVotingContractAddress && guard.freezeProposalVoteCount?.gt(0) && <ActivityFreeze />}
{!type ? (
<InfoBoxLoader />
) : sortedActivities.length ? (
Expand Down
19 changes: 12 additions & 7 deletions src/components/pages/DaoDashboard/Info/InfoGovernance.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Box, Flex, Text } from '@chakra-ui/react';
import { Govern } from '@decent-org/fractal-ui';
import { MultisigFreezeGuard } from '@fractal-framework/fractal-contracts';
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import useSafeContracts from '../../../../hooks/safe/useSafeContracts';
import { useTimeHelpers } from '../../../../hooks/utils/useTimeHelpers';
import { useFractal } from '../../../../providers/App/AppProvider';
import { useEthersProvider } from '../../../../providers/Ethers/hooks/useEthersProvider';
Expand All @@ -15,11 +15,12 @@ export function InfoGovernance() {
const {
node: { daoAddress },
governance,
guardContracts: { freezeGuardType, freezeGuardContract },
guardContracts: { freezeGuardType, freezeGuardContractAddress },
readOnly: { dao },
} = useFractal();
const provider = useEthersProvider();
const { getTimeDuration } = useTimeHelpers();
const baseContracts = useSafeContracts();
const [timelockPeriod, setTimelockPeriod] = useState<string>();
const [executionPeriod, setExecutionPeriod] = useState<string>();
useEffect(() => {
Expand All @@ -30,10 +31,13 @@ export function InfoGovernance() {
}
};
if (freezeGuardType == FreezeGuardType.MULTISIG) {
if (freezeGuardContract) {
const freezeGuard = freezeGuardContract.asProvider as MultisigFreezeGuard;
setTimelockPeriod(await formatBlocks(await freezeGuard.timelockPeriod()));
setExecutionPeriod(await formatBlocks(await freezeGuard.executionPeriod()));
if (freezeGuardContractAddress && baseContracts) {
const freezeGuardContract =
baseContracts.multisigFreezeGuardMasterCopyContract.asProvider.attach(
freezeGuardContractAddress,
);
setTimelockPeriod(await formatBlocks(await freezeGuardContract.timelockPeriod()));
setExecutionPeriod(await formatBlocks(await freezeGuardContract.executionPeriod()));
}
} else if (dao?.isAzorius) {
const azoriusGovernance = governance as AzoriusGovernance;
Expand All @@ -54,10 +58,11 @@ export function InfoGovernance() {

setTimelockInfo();
}, [
baseContracts,
executionPeriod,
getTimeDuration,
governance,
freezeGuardContract,
freezeGuardContractAddress,
freezeGuardType,
provider,
timelockPeriod,
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/DaoDashboard/Info/ParentLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function ParentLink() {
<Link
color="gold.500"
_hover={{ textDecoration: 'none', color: 'gold.500-hover' }}
href={DAO_ROUTES.dao.relative(addressPrefix, nodeHierarchy.parentAddress)}
to={DAO_ROUTES.dao.relative(addressPrefix, nodeHierarchy.parentAddress)}
onClick={action.resetDAO}
marginBottom="1rem"
as={RouterLink}
Expand Down
4 changes: 2 additions & 2 deletions src/components/pages/DaoHierarchy/DaoNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function DaoNode({
const isCurrentDAO = daoAddress === currentDAOAddress;

useEffect(() => {
if (daoAddress && !fractalNode) {
if (daoAddress) {
loadDao(utils.getAddress(daoAddress)).then(_node => {
const errorNode = _node as WithError;
if (!errorNode.error) {
Expand Down Expand Up @@ -80,7 +80,7 @@ export function DaoNode({
}
});
}
}, [loadDao, daoAddress, fractalNode, depth]);
}, [loadDao, daoAddress, depth]);

return (
<Box position="relative">
Expand Down
1 change: 0 additions & 1 deletion src/components/pages/DaoHierarchy/NodeLines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export function NodeLineVertical({ isCurrentDAO, trueDepth = 0, lastChildDescend
position="absolute"
h={`calc(100% - ${NODE_HEIGHT_REM + NODE_MARGIN_TOP_REM}rem)`}
w="100%"
zIndex={-1 - trueDepth}
bottom={0}
overflow="hidden"
>
Expand Down
6 changes: 4 additions & 2 deletions src/components/pages/DaoSettings/components/Modules/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function ModulesContainer() {
const { t } = useTranslation(['settings']);
const {
node: { fractalModules, isModulesLoaded, safe },
guardContracts: { freezeGuardContract, freezeVotingContract },
guardContracts: { freezeGuardContractAddress, freezeVotingContractAddress },
} = useFractal();

return (
Expand Down Expand Up @@ -91,7 +91,9 @@ export function ModulesContainer() {
<Box>
<DisplayAddress address={safe.guard}>
{safe.guard}
{!!freezeGuardContract || !!freezeVotingContract ? ' (Freeze Guard)' : ''}
{!!freezeGuardContractAddress || !!freezeVotingContractAddress
? ' (Freeze Guard)'
: ''}
</DisplayAddress>
</Box>
) : (
Expand Down
66 changes: 36 additions & 30 deletions src/components/ui/menus/ManageDAO/ManageDAOMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { VEllipsis } from '@decent-org/fractal-ui';
import {
ERC20FreezeVoting,
ERC721FreezeVoting,
MultisigFreezeVoting,
} from '@fractal-framework/fractal-contracts';
import { ERC20FreezeVoting, MultisigFreezeVoting } from '@fractal-framework/fractal-contracts';
import { BigNumber } from 'ethers';
import { useMemo, useCallback, useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
Expand All @@ -15,6 +11,7 @@ import {
import useSubmitProposal from '../../../../hooks/DAO/proposal/useSubmitProposal';
import useUserERC721VotingTokens from '../../../../hooks/DAO/proposal/useUserERC721VotingTokens';
import useClawBack from '../../../../hooks/DAO/useClawBack';
import useSafeContracts from '../../../../hooks/safe/useSafeContracts';
import useBlockTimestamp from '../../../../hooks/utils/useBlockTimestamp';
import { useMasterCopy } from '../../../../hooks/utils/useMasterCopy';
import { useFractal } from '../../../../providers/App/AppProvider';
Expand Down Expand Up @@ -59,8 +56,8 @@ export function ManageDAOMenu({
const {
node: { safe },
governance: { type },
baseContracts,
} = useFractal();
const baseContracts = useSafeContracts();
const currentTime = BigNumber.from(useBlockTimestamp());
const navigate = useNavigate();
const safeAddress = fractalNode?.daoAddress;
Expand Down Expand Up @@ -126,49 +123,61 @@ export function ManageDAOMenu({

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

const { addressPrefix } = useNetworkConfig();

const handleNavigateToSettings = useCallback(() => {
if (safeAddress) {
navigate(DAO_ROUTES.settings.relative(addressPrefix, safeAddress));
navigate(DAO_ROUTES.settings.relative(addressPrefix, safeAddress), { replace: true });
}
}, [navigate, addressPrefix, safeAddress]);

const handleModifyGovernance = useFractalModal(ModalType.CONFIRM_MODIFY_GOVERNANCE);

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

const freezeOption = {
const freezeOption = useMemo(
() => ({
optionKey: 'optionInitiateFreeze',
onClick: () => {
const freezeVotingContract = guardContracts?.freezeVotingContract?.asSigner;
const freezeVotingType = guardContracts?.freezeVotingType;
const freezeVotingContract =
baseContracts!.freezeMultisigVotingMasterCopyContract.asSigner.attach(
guardContracts!.freezeVotingContractAddress!,
);
const freezeVotingType = guardContracts!.freezeVotingType;
if (freezeVotingContract) {
if (
freezeVotingType === FreezeVotingType.MULTISIG ||
freezeVotingType === FreezeVotingType.ERC20
) {
(freezeVotingContract as ERC20FreezeVoting | MultisigFreezeVoting).castFreezeVote();
return (
freezeVotingContract as ERC20FreezeVoting | MultisigFreezeVoting
).castFreezeVote();
} else if (freezeVotingType === FreezeVotingType.ERC721) {
getUserERC721VotingTokens(undefined, parentAddress).then(tokensInfo => {
return (freezeVotingContract as ERC721FreezeVoting)[
'castFreezeVote(address[],uint256[])'
](tokensInfo.totalVotingTokenAddresses, tokensInfo.totalVotingTokenIds);
const freezeERC721VotingContract =
baseContracts!.freezeERC721VotingMasterCopyContract.asSigner.attach(
guardContracts!.freezeVotingContractAddress!,
);
return freezeERC721VotingContract!['castFreezeVote(address[],uint256[])'](
tokensInfo.totalVotingTokenAddresses,
tokensInfo.totalVotingTokenIds,
);
});
}
}
},
};
}),
[baseContracts, guardContracts, getUserERC721VotingTokens, parentAddress],
);

const options = useMemo(() => {
const createSubDAOOption = {
optionKey: 'optionCreateSubDAO',

onClick: () => {
if (safeAddress) {
navigate(DAO_ROUTES.newSubDao.relative(addressPrefix, safeAddress), { replace: true });
}
},
};
const clawBackOption = {
optionKey: 'optionInitiateClawback',
onClick: handleClawBack,
Expand Down Expand Up @@ -235,16 +244,13 @@ export function ManageDAOMenu({
currentTime,
navigate,
safeAddress,
parentAddress,
governanceType,
guardContracts?.freezeVotingContract?.asSigner,
guardContracts?.freezeVotingType,
handleClawBack,
canUserCreateProposal,
handleModifyGovernance,
handleNavigateToSettings,
getUserERC721VotingTokens,
addressPrefix,
freezeOption,
]);

return (
Expand Down
Loading

0 comments on commit 9396909

Please sign in to comment.