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:
parent
ae97e91443
commit
3563a246fe
@ -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…
Reference in New Issue
Block a user