Skip to content

Commit

Permalink
Delay processing new proposal for a block, to give RPC chance to catc…
Browse files Browse the repository at this point in the history
…h up
  • Loading branch information
adamgall committed Apr 3, 2024
1 parent 7d50962 commit 72f74ab
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
mapProposalCreatedEventToProposal,
decodeTransactions,
} from '../../../../utils';
import { getAverageBlockTime } from '../../../../utils/contract';
import useSafeContracts from '../../../safe/useSafeContracts';
import { useSafeDecoder } from '../../../utils/useSafeDecoder';

Expand All @@ -36,6 +37,13 @@ const proposalCreatedEventListener = (
dispatch: Dispatch<FractalActions>,
): TypedListener<ProposalCreatedEvent> => {
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;
}
Expand Down

0 comments on commit 72f74ab

Please sign in to comment.