Skip to content

Commit

Permalink
Merge branch 'develop' into fix/qa-bug-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrila committed Dec 19, 2023
2 parents e0a70fe + dddf7ae commit 9944749
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 34 deletions.
6 changes: 3 additions & 3 deletions app/daos/[daoAddress]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default function DaoPageLayout({
params: { daoAddress?: string };
}) {
const { node } = useFractal();
const loading = useDAOController({ daoAddress });
const { nodeLoading, reloadingDAO } = useDAOController({ daoAddress });
const { chain } = useNetwork();

const validSafe = node.safe;
Expand All @@ -84,7 +84,7 @@ export default function DaoPageLayout({
display = children;
} else if (!chain) {
// if we're disconnected
if (loading || validSafe) {
if (nodeLoading || reloadingDAO || validSafe) {
display = children;
} else {
display = <InvalidSafe />;
Expand All @@ -94,7 +94,7 @@ export default function DaoPageLayout({
const invalidChain = !supportedChains.map(c => c.chainId).includes(chain.id);
if (invalidChain) {
display = <InvalidChain />;
} else if (loading || validSafe) {
} else if (nodeLoading || reloadingDAO || validSafe) {
display = children;
} else {
display = <InvalidSafe />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function ProposalAction({
);

const showActionButton =
(isSnapshotProposal && canVote) ||
(isSnapshotProposal && canVote && isActiveProposal) ||
(user.votingWeight.gt(0) &&
(isActiveProposal ||
proposal.state === FractalProposalState.EXECUTABLE ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Grid, GridItem, Text, Flex } from '@chakra-ui/react';
import { useTranslation } from 'react-i18next';
import useSnapshotProposal from '../../../hooks/DAO/loaders/snapshot/useSnapshotProposal';
import useDisplayName from '../../../hooks/utils/useDisplayName';
import { useFractal } from '../../../providers/App/AppProvider';
import {
Expand All @@ -17,7 +16,6 @@ interface ISnapshotProposalVoteItem {

export default function SnapshotProposalVoteItem({ proposal, vote }: ISnapshotProposalVoteItem) {
const { t } = useTranslation();
const { getVoteWeight } = useSnapshotProposal(proposal);
const { displayName } = useDisplayName(vote.voter);
const {
readOnly: { user },
Expand Down Expand Up @@ -62,7 +60,7 @@ export default function SnapshotProposalVoteItem({ proposal, vote }: ISnapshotPr
</GridItem>
<GridItem colSpan={1}>
<Text textStyle="text-base-sans-regular">
{getVoteWeight(vote)} {proposal.strategies[0].params.symbol}
{vote.votingWeight} {proposal.strategies[0].params.symbol}
</Text>
</GridItem>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { useState, useEffect } from 'react';
import useSnapshotProposal from '../../../../hooks/DAO/loaders/snapshot/useSnapshotProposal';
import { ExtendedSnapshotProposal } from '../../../../types';

export default function useTotalVotes({ proposal }: { proposal?: ExtendedSnapshotProposal }) {
const [totalVotesCasted, setTotalVotesCasted] = useState(0);
const { getVoteWeight } = useSnapshotProposal(proposal);

useEffect(() => {
if (proposal) {
let newTotalVotesCasted = 0;
proposal.votes.forEach(vote => (newTotalVotesCasted += getVoteWeight(vote)));
proposal.votes.forEach(vote => (newTotalVotesCasted += vote.votingWeight));
setTotalVotesCasted(newTotalVotesCasted);
}
}, [proposal, totalVotesCasted, getVoteWeight]);
}, [proposal, totalVotesCasted]);

return { totalVotesCasted };
}
29 changes: 8 additions & 21 deletions src/hooks/DAO/loaders/snapshot/useSnapshotProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ export default function useSnapshotProposal(proposal: FractalProposal | null | u
[snapshotProposal]
);

const getVoteWeight = useCallback(
(vote: SnapshotVote) =>
vote.votingWeight * vote.votingWeightByStrategy.reduce((prev, curr) => prev + curr, 0),
[]
);

const loadProposal = useCallback(async () => {
if (snapshotProposal?.snapshotProposalId && client) {
const proposalQueryResult = await client
Expand Down Expand Up @@ -86,7 +80,7 @@ export default function useSnapshotProposal(proposal: FractalProposal | null | u
const votesQueryResult = await client
.query({
query: gql`query SnapshotProposalVotes {
votes(where: {proposal: "${snapshotProposal.snapshotProposalId}"}) {
votes(where: {proposal: "${snapshotProposal.snapshotProposalId}"}, first: 100) {
id
voter
vp
Expand Down Expand Up @@ -147,12 +141,12 @@ export default function useSnapshotProposal(proposal: FractalProposal | null | u
const existingChoiceType = votesBreakdown[voteChoice];
if (existingChoiceType) {
votesBreakdown[voteChoice] = {
total: existingChoiceType.total + getVoteWeight(vote),
total: existingChoiceType.total + vote.votingWeight,
votes: [...existingChoiceType.votes, vote],
};
} else {
votesBreakdown[voteChoice] = {
total: getVoteWeight(vote),
total: vote.votingWeight,
votes: [vote],
};
}
Expand All @@ -164,12 +158,12 @@ export default function useSnapshotProposal(proposal: FractalProposal | null | u
const existingChoiceType = votesBreakdown[voteChoice];
if (existingChoiceType) {
votesBreakdown[voteChoice] = {
total: existingChoiceType.total + getVoteWeight(vote),
total: existingChoiceType.total + vote.votingWeight,
votes: [...existingChoiceType.votes, vote],
};
} else {
votesBreakdown[voteChoice] = {
total: getVoteWeight(vote),
total: vote.votingWeight,
votes: [vote],
};
}
Expand All @@ -182,12 +176,12 @@ export default function useSnapshotProposal(proposal: FractalProposal | null | u

if (existingChoiceType) {
votesBreakdown[choiceKey] = {
total: existingChoiceType.total + getVoteWeight(vote),
total: existingChoiceType.total + vote.votingWeight,
votes: [...existingChoiceType.votes, vote],
};
} else {
votesBreakdown[choiceKey] = {
total: getVoteWeight(vote),
total: vote.votingWeight,
votes: [vote],
};
}
Expand All @@ -202,13 +196,7 @@ export default function useSnapshotProposal(proposal: FractalProposal | null | u
votes: votesQueryResult,
} as ExtendedSnapshotProposal);
}
}, [
snapshotProposal?.snapshotProposalId,
proposal,
snapshotProposal?.state,
getVoteWeight,
client,
]);
}, [snapshotProposal?.snapshotProposalId, proposal, snapshotProposal?.state, client]);

const loadVotingWeight = useCallback(async () => {
const emptyVotingWeight = {
Expand Down Expand Up @@ -253,7 +241,6 @@ export default function useSnapshotProposal(proposal: FractalProposal | null | u
return {
loadVotingWeight,
loadProposal,
getVoteWeight,
snapshotProposal,
isSnapshotProposal,
extendedSnapshotProposal,
Expand Down
1 change: 1 addition & 0 deletions src/hooks/DAO/loaders/snapshot/useSnapshotProposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const useSnapshotProposals = () => {
query: gql`
query Proposals {
proposals(
first: 50,
where: {
space_in: ["${daoSnapshotSpaceName}"]
},
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/DAO/loaders/useFractalNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ export const useFractalNode = ({ daoAddress }: { daoAddress?: string }) => {
const chainId = chain ? chain.id : disconnectedChain.id;
useEffect(() => {
if (daoAddress && chainId + daoAddress !== currentValidSafe.current) {
setNodeLoading(true);
setDAO(chainId, daoAddress);
}
}, [daoAddress, setDAO, action, currentValidSafe, chainId]);
}, [daoAddress, setDAO, currentValidSafe, chainId]);

return nodeLoading;
};
5 changes: 4 additions & 1 deletion src/hooks/DAO/useDAOController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useGovernanceContracts } from './loaders/useGovernanceContracts';

export default function useDAOController({ daoAddress }: { daoAddress?: string }) {
const [currentDAOAddress, setCurrentDAOAddress] = useState<string>();
const [reloadingDAO, setReloadingDAO] = useState(false);
const {
node: {
nodeHierarchy: { parentAddress },
Expand All @@ -21,8 +22,10 @@ export default function useDAOController({ daoAddress }: { daoAddress?: string }
} = useFractal();
useEffect(() => {
if (daoAddress && currentDAOAddress !== daoAddress) {
setReloadingDAO(true);
action.resetDAO().then(() => {
setCurrentDAOAddress(daoAddress);
setReloadingDAO(false);
});
}
}, [daoAddress, currentDAOAddress, action]);
Expand All @@ -35,5 +38,5 @@ export default function useDAOController({ daoAddress }: { daoAddress?: string }
useFractalTreasury();
useERC20Claim();
useSnapshotProposals();
return nodeLoading;
return { nodeLoading, reloadingDAO };
}

0 comments on commit 9944749

Please sign in to comment.