diff --git a/src/hooks/DAO/loaders/governance/useAzoriusProposals.ts b/src/hooks/DAO/loaders/governance/useAzoriusProposals.ts index f05e8166c4..d28c336c82 100644 --- a/src/hooks/DAO/loaders/governance/useAzoriusProposals.ts +++ b/src/hooks/DAO/loaders/governance/useAzoriusProposals.ts @@ -49,7 +49,7 @@ export const useAzoriusProposals = () => { [decode], ); - const loadAzoriusProposals = useCallback(async (): Promise => { + const loadAzoriusProposals = useCallback(async () => { if ( !azoriusContractAddress || !(ozLinearVotingContractAddress || erc721LinearVotingContractAddress) || @@ -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, + ) => { + 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(); diff --git a/src/hooks/DAO/loaders/useProposals.ts b/src/hooks/DAO/loaders/useProposals.ts index 7d487f7c94..46724467aa 100644 --- a/src/hooks/DAO/loaders/useProposals.ts +++ b/src/hooks/DAO/loaders/useProposals.ts @@ -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'; @@ -10,7 +9,6 @@ export const useDAOProposals = () => { const { node: { daoAddress }, governance: { type }, - action, } = useFractal(); const { setMethodOnInterval, clearIntervals } = useUpdateTimer(daoAddress); @@ -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; };