From ddcc6d924b60bd3095a9be6b890d5c0934412f07 Mon Sep 17 00:00:00 2001 From: Adam Gall Date: Wed, 6 Nov 2024 10:01:54 -0500 Subject: [PATCH] Flatten logic into shallower conditional blocks --- src/hooks/DAO/loaders/useFractalGovernance.ts | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/src/hooks/DAO/loaders/useFractalGovernance.ts b/src/hooks/DAO/loaders/useFractalGovernance.ts index 4162d78a25..de46285235 100644 --- a/src/hooks/DAO/loaders/useFractalGovernance.ts +++ b/src/hooks/DAO/loaders/useFractalGovernance.ts @@ -44,34 +44,41 @@ export const useFractalGovernance = () => { const { daos } = data; const dao = daos[0]; - if (dao) { - const { proposalTemplatesHash } = dao; - if (proposalTemplatesHash) { - const proposalTemplates: ProposalTemplate[] = await ipfsClient.cat(proposalTemplatesHash); - if (proposalTemplates) { - const mappedProposalTemplates = proposalTemplates.map(proposalTemplate => ({ - ...proposalTemplate, - transactions: proposalTemplate.transactions.map(transaction => ({ - ...transaction, - ethValue: { - bigintValue: BigInt(transaction.ethValue.bigintValue || 0n), - value: transaction.ethValue.value ?? '0', - }, - })), - })); + const { proposalTemplatesHash } = dao; - action.dispatch({ - type: FractalGovernanceAction.SET_PROPOSAL_TEMPLATES, - payload: mappedProposalTemplates, - }); - return; - } - } + if (!proposalTemplatesHash) { + action.dispatch({ + type: FractalGovernanceAction.SET_PROPOSAL_TEMPLATES, + payload: [], + }); + return; + } + + const proposalTemplates: ProposalTemplate[] | undefined = + await ipfsClient.cat(proposalTemplatesHash); + + if (!proposalTemplates) { + action.dispatch({ + type: FractalGovernanceAction.SET_PROPOSAL_TEMPLATES, + payload: [], + }); + return; } + const mappedProposalTemplates = proposalTemplates.map(proposalTemplate => ({ + ...proposalTemplate, + transactions: proposalTemplate.transactions.map(transaction => ({ + ...transaction, + ethValue: { + bigintValue: BigInt(transaction.ethValue.bigintValue || 0n), + value: transaction.ethValue.value ?? '0', + }, + })), + })); + action.dispatch({ type: FractalGovernanceAction.SET_PROPOSAL_TEMPLATES, - payload: [], + payload: mappedProposalTemplates, }); }, context: {