From 72f74aba46c2b18ee46a2d66856454bb8c13d6b0 Mon Sep 17 00:00:00 2001 From: Adam Gall Date: Wed, 3 Apr 2024 16:43:24 -0400 Subject: [PATCH] Delay processing new proposal for a block, to give RPC chance to catch up --- .../DAO/loaders/governance/useAzoriusProposalListeners.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/hooks/DAO/loaders/governance/useAzoriusProposalListeners.ts b/src/hooks/DAO/loaders/governance/useAzoriusProposalListeners.ts index 2f0f407451..5b11edd9b8 100644 --- a/src/hooks/DAO/loaders/governance/useAzoriusProposalListeners.ts +++ b/src/hooks/DAO/loaders/governance/useAzoriusProposalListeners.ts @@ -23,6 +23,7 @@ import { mapProposalCreatedEventToProposal, decodeTransactions, } from '../../../../utils'; +import { getAverageBlockTime } from '../../../../utils/contract'; import useSafeContracts from '../../../safe/useSafeContracts'; import { useSafeDecoder } from '../../../utils/useSafeDecoder'; @@ -36,6 +37,13 @@ const proposalCreatedEventListener = ( dispatch: Dispatch, ): TypedListener => { return async (_strategyAddress, proposalId, proposer, transactions, metadata) => { + // Wait for a block before processing. + // We've seen that calling smart contract functions in `mapProposalCreatedEventToProposal` + // which include the `proposalId` error out because the RPC node (rather, the block it's on) + // doesn't see this proposal yet (despite the event being caught in the app...). + const averageBlockTime = await getAverageBlockTime(provider); + await new Promise(resolve => setTimeout(resolve, averageBlockTime * 1000)); + if (!metadata) { return; }