Skip to content

Commit

Permalink
Load proposals synchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgall committed Mar 30, 2024
1 parent 3f549b6 commit ab359c0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
77 changes: 45 additions & 32 deletions src/hooks/DAO/loaders/governance/useAzoriusProposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const useAzoriusProposals = () => {
[decode],
);

const loadAzoriusProposals = useCallback(async (): Promise<AzoriusProposal[]> => {
const loadAzoriusProposals = useCallback(async () => {
if (
!azoriusContractAddress ||
!(ozLinearVotingContractAddress || erc721LinearVotingContractAddress) ||
Expand Down Expand Up @@ -78,42 +78,55 @@ export const useAzoriusProposals = () => {
return [];
}

const proposals = await Promise.all(
proposalCreatedEvents.map(async ({ args }) => {
let proposalData;
if (args.metadata) {
const metadataEvent: ProposalMetadata = JSON.parse(args.metadata);
const decodedTransactions = await decodeTransactions(args.transactions);
proposalData = {
metaData: {
title: metadataEvent.title,
description: metadataEvent.description,
documentationUrl: metadataEvent.documentationUrl,
},
transactions: args.transactions,
decodedTransactions,
};
}
return mapProposalCreatedEventToProposal(
strategyContract,
strategyType,
args.proposalId,
args.proposer,
azoriusContract,
provider,
proposalData,
);
}),
);
return proposals;
const loadProposalFromEvent = async ({ args }: ProposalCreatedEvent) => {
let proposalData;
if (args.metadata) {
const metadataEvent: ProposalMetadata = JSON.parse(args.metadata);
const decodedTransactions = await decodeTransactions(args.transactions);
proposalData = {
metaData: {
title: metadataEvent.title,
description: metadataEvent.description,
documentationUrl: metadataEvent.documentationUrl,
},
transactions: args.transactions,
decodedTransactions,
};
}
return mapProposalCreatedEventToProposal(
strategyContract,
strategyType,
args.proposalId,
args.proposer,
azoriusContract,
provider,
proposalData,
);
};

const loadProposalSynchronously = async (
_proposalCreatedEvents: ProposalCreatedEvent[],
_loadProposalFromEvent: ({ args }: ProposalCreatedEvent) => Promise<AzoriusProposal>,
) => {
for (const proposalCreatedEvent of _proposalCreatedEvents) {
const proposal = await _loadProposalFromEvent(proposalCreatedEvent);
action.dispatch({
type: FractalGovernanceAction.SET_AZORIUS_PROPOSAL,
payload: proposal,
});
}
};

await loadProposalSynchronously(proposalCreatedEvents.reverse(), loadProposalFromEvent);
}, [
decodeTransactions,
azoriusContractAddress,
ozLinearVotingContractAddress,
erc721LinearVotingContractAddress,
azoriusContractAddress,
provider,
strategyType,
provider,
baseContracts,
decodeTransactions,
action,
]);

// const { requestWithRetries } = useAsyncRetry();
Expand Down
17 changes: 2 additions & 15 deletions src/hooks/DAO/loaders/useProposals.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useCallback } from 'react';
import { useFractal } from '../../../providers/App/AppProvider';
import { FractalGovernanceAction } from '../../../providers/App/governance/action';
import { GovernanceType } from '../../../types';
import { useUpdateTimer } from '../../utils/useUpdateTimer';
import { useAzoriusProposals } from './governance/useAzoriusProposals';
Expand All @@ -10,7 +9,6 @@ export const useDAOProposals = () => {
const {
node: { daoAddress },
governance: { type },
action,
} = useFractal();

const { setMethodOnInterval, clearIntervals } = useUpdateTimer(daoAddress);
Expand All @@ -21,23 +19,12 @@ export const useDAOProposals = () => {
clearIntervals();
if (type === GovernanceType.AZORIUS_ERC20 || type === GovernanceType.AZORIUS_ERC721) {
// load Azorius proposals and strategies
const proposals = await loadAzoriusProposals();
action.dispatch({
type: FractalGovernanceAction.SET_PROPOSALS,
payload: proposals,
});
await loadAzoriusProposals();
} else if (type === GovernanceType.MULTISIG) {
// load mulisig proposals
setMethodOnInterval(loadSafeMultisigProposals);
}
}, [
type,
loadAzoriusProposals,
action,
loadSafeMultisigProposals,
setMethodOnInterval,
clearIntervals,
]);
}, [type, loadAzoriusProposals, loadSafeMultisigProposals, setMethodOnInterval, clearIntervals]);

return loadDAOProposals;
};

0 comments on commit ab359c0

Please sign in to comment.