From 4a781bd0dd8828ce152f6ab2c3f1bbd6b5e826f7 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 9 Jan 2023 20:20:09 -0300 Subject: fix #7153: more error handling if handler do not trap error then fail at compile time, all safe handlers push alert on error errors are typed so they render good information --- .../src/components/CurrentAlerts.tsx | 75 ++++++++++++++++------ 1 file changed, 57 insertions(+), 18 deletions(-) (limited to 'packages/taler-wallet-webextension/src/components/CurrentAlerts.tsx') diff --git a/packages/taler-wallet-webextension/src/components/CurrentAlerts.tsx b/packages/taler-wallet-webextension/src/components/CurrentAlerts.tsx index a56c82dee..47863d73e 100644 --- a/packages/taler-wallet-webextension/src/components/CurrentAlerts.tsx +++ b/packages/taler-wallet-webextension/src/components/CurrentAlerts.tsx @@ -18,7 +18,6 @@ import { ComponentChildren, Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; import { useTranslationContext } from "../../../web-util/src/index.browser.js"; import { - ErrorAlert, Alert as AlertNotification, useAlertContext, } from "../context/alert.js"; @@ -37,41 +36,78 @@ function AlertContext({ context: undefined | object; }): VNode { const [more, setMore] = useState(false); + const [wrap, setWrap] = useState(false); const { i18n } = useTranslationContext(); if (!more) { return (
- setMore(true)}> + setMore(true)} + style={{ cursor: "pointer", textDecoration: "underline" }} + > more info
); } + const errorInfo = JSON.stringify( + context === undefined ? { cause } : { context, cause }, + undefined, + 2, + ); return ( -
-      {JSON.stringify(
-        context === undefined ? { cause } : { context, cause },
-        undefined,
-        2,
-      )}
-    
+ +
+ setWrap(!wrap)} + style={{ cursor: "pointer", textDecoration: "underline" }} + > + wrap text + +    + navigator.clipboard.writeText(errorInfo)} + style={{ cursor: "pointer", textDecoration: "underline" }} + > + copy content + +    + setMore(false)} + style={{ cursor: "pointer", textDecoration: "underline" }} + > + less info + +
+
+        {errorInfo}
+      
+
); } export function ErrorAlertView({ - error: alert, + error, onClose, }: { - error: ErrorAlert; + error: AlertNotification; onClose?: () => Promise; }): VNode { return ( - -
-
{alert.description}
- -
-
+ + + ); } @@ -86,6 +122,9 @@ export function AlertView({
{alert.description}
+ {alert.type === "error" ? ( + + ) : undefined}
); @@ -104,5 +143,5 @@ export function CurrentAlerts(): VNode { } function Wrapper({ children }: { children: ComponentChildren }): VNode { - return
{children}
; + return
{children}
; } -- cgit v1.2.3