Skip to content

Commit

Permalink
refactor conditions in validateUpdatePluginProposalActions
Browse files Browse the repository at this point in the history
  • Loading branch information
josemarinas committed Nov 21, 2023
1 parent b5e0ede commit 73366ff
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions modules/client/src/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1550,7 +1550,16 @@ export async function validateUpdatePluginProposalActions(
...recCauses.proposalSettingsErrorCauses,
];
}
} else if (isPluginUpdateActionWithRootPermission(classifiedActions)) {
return {
// every item in the array should be empty
isValid: actionErrorCauses.every((cause) => cause.length === 0) &&
proposalSettingsErrorCauses.length === 0,
actionErrorCauses,
proposalSettingsErrorCauses,
};
}

if (isPluginUpdateActionWithRootPermission(classifiedActions)) {
// initialize the causes array
// we always use the index 0
// because this is going to be called recursively
Expand Down Expand Up @@ -1640,22 +1649,21 @@ export async function validateUpdatePluginProposalActions(
...recCauses.proposalSettingsErrorCauses,
];
}
} else {
// add invalid actions to the causes array
// return, if this is inside the recursion
// it will be added to the array
return {
isValid: false,
proposalSettingsErrorCauses: [ProposalSettingsErrorCause.INVALID_ACTIONS],
actionErrorCauses: actionErrorCauses,
// every item in the array should be empty
isValid: actionErrorCauses.every((cause) => cause.length === 0) &&
proposalSettingsErrorCauses.length === 0,
actionErrorCauses,
proposalSettingsErrorCauses,
};
}
// add invalid actions to the causes array
// return, if this is inside the recursion
// it will be added to the array
return {
// every item in the array should be empty
isValid: actionErrorCauses.every((cause) => cause.length === 0) &&
proposalSettingsErrorCauses.length === 0,
actionErrorCauses,
proposalSettingsErrorCauses,
isValid: false,
proposalSettingsErrorCauses: [ProposalSettingsErrorCause.INVALID_ACTIONS],
actionErrorCauses: actionErrorCauses,
};
}

Expand Down

0 comments on commit 73366ff

Please sign in to comment.