Skip to content

Commit

Permalink
Flatten logic into shallower conditional blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgall committed Nov 6, 2024
1 parent 70381f2 commit ddcc6d9
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions src/hooks/DAO/loaders/useFractalGovernance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit ddcc6d9

Please sign in to comment.