1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

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`.
This commit is contained in:
Mark Stacey 2022-01-03 11:32:15 -03:30 committed by GitHub
parent ae97e91443
commit 3563a246fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View File

@ -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,

View File

@ -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}`);
}