Allow templates without alerts (#13150)

The confirmation page template system allows templates to have alerts,
but it throws an uncaught Promise rejection if a template has no
alerts. This is the unintended side-effect of input validation.

The `getTemplateAlerts` function was updated to always return an array.
The one callsite was updated to expect an empty array if there were no
alerts to render, rather than expecting `undefined`.
feature/default_network_editable
Mark Stacey 3 years ago committed by GitHub
parent ae97e91443
commit 3563a246fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      ui/pages/confirmation/confirmation.js
  2. 2
      ui/pages/confirmation/templates/index.js

@ -83,7 +83,7 @@ function useAlertState(pendingConfirmation) {
let isMounted = true;
if (pendingConfirmation) {
getTemplateAlerts(pendingConfirmation).then((alerts) => {
if (isMounted && alerts) {
if (isMounted && alerts.length > 0) {
dispatch({
type: 'set',
confirmationId: pendingConfirmation.id,

@ -43,7 +43,7 @@ const ALLOWED_TEMPLATE_KEYS = [
*/
export async function getTemplateAlerts(pendingApproval) {
const fn = APPROVAL_TEMPLATES[pendingApproval.type]?.getAlerts;
const results = fn ? await fn(pendingApproval) : undefined;
const results = fn ? await fn(pendingApproval) : [];
if (!Array.isArray(results)) {
throw new Error(`Template alerts must be an array, received: ${results}`);
}

Loading…
Cancel
Save