Skip to content

Commit

Permalink
Wrap the JSON.parse in a try catch, so as to not crash when metadata …
Browse files Browse the repository at this point in the history
…is malformed
  • Loading branch information
adamgall committed Apr 22, 2024
1 parent b7a92bc commit 62d0193
Showing 1 changed file with 34 additions and 19 deletions.
53 changes: 34 additions & 19 deletions src/hooks/DAO/loaders/governance/useAzoriusProposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { VotedEvent as ERC20VotedEvent } from '@fractal-framework/fractal-contracts/dist/typechain-types/contracts/azorius/LinearERC20Voting';
import { VotedEvent as ERC721VotedEvent } from '@fractal-framework/fractal-contracts/dist/typechain-types/contracts/azorius/LinearERC721Voting';
import { useCallback, useEffect, useMemo, useRef } from 'react';
import { logError } from '../../../../helpers/errorLogging';
import { useFractal } from '../../../../providers/App/AppProvider';
import { useEthersProvider } from '../../../../providers/Ethers/hooks/useEthersProvider';
import { CreateProposalMetadata, VotingStrategyType, DecodedTransaction } from '../../../../types';
Expand Down Expand Up @@ -140,25 +141,39 @@ export const useAzoriusProposals = () => {
for (const proposalCreatedEvent of proposalCreatedEvents) {
let proposalData;
if (proposalCreatedEvent.args.metadata) {
const metadataEvent: CreateProposalMetadata = JSON.parse(
proposalCreatedEvent.args.metadata,
);
const decodedTransactions = await decodeTransactions(
_decode,
proposalCreatedEvent.args.transactions.map(t => ({ ...t, value: t.value.toBigInt() })),
);
proposalData = {
metaData: {
title: metadataEvent.title,
description: metadataEvent.description,
documentationUrl: metadataEvent.documentationUrl,
},
transactions: proposalCreatedEvent.args.transactions.map(t => ({
...t,
value: t.value.toBigInt(),
})),
decodedTransactions,
};
try {
const metadataEvent: CreateProposalMetadata = JSON.parse(
proposalCreatedEvent.args.metadata,
);

const decodedTransactions = await decodeTransactions(
_decode,
proposalCreatedEvent.args.transactions.map(t => ({
...t,
value: t.value.toBigInt(),
})),
);
proposalData = {
metaData: {
title: metadataEvent.title,
description: metadataEvent.description,
documentationUrl: metadataEvent.documentationUrl,
},
transactions: proposalCreatedEvent.args.transactions.map(t => ({
...t,
value: t.value.toBigInt(),
})),
decodedTransactions,
};
} catch {
logError(
'Unable to parse proposal metadata or transactions.',
'metadata:',
proposalCreatedEvent.args.metadata,
'transactions:',
proposalCreatedEvent.args.transactions,
);
}
}

const proposal = await mapProposalCreatedEventToProposal(
Expand Down

0 comments on commit 62d0193

Please sign in to comment.