commit 266e2a21ee31034d120bc0e03873fad156c13a77
parent d67ea0af93eebeca2fc1ef830a182fa1937c0f25
Author: Sebastian <sebasjm@gmail.com>
Date: Wed, 9 Apr 2025 10:28:13 -0300
fix: backend breaking change
Diffstat:
4 files changed, 52 insertions(+), 34 deletions(-)
diff --git a/packages/merchant-backoffice-ui/src/components/exception/AsyncButton.tsx b/packages/merchant-backoffice-ui/src/components/exception/AsyncButton.tsx
@@ -26,13 +26,13 @@ import { useTranslationContext } from "@gnu-taler/web-util/browser";
type Props = {
children: ComponentChildren;
- disabled: boolean;
+ disabled?: boolean;
onClick?: () => Promise<void>;
[rest: string]: any;
};
export function AsyncButton({ onClick, disabled, children, ...rest }: Props) {
- const { isSlow, isLoading, request, cancel } = useAsync(onClick);
+ const { isSlow, isLoading, request, cancel, error } = useAsync(onClick);
const { i18n } = useTranslationContext();
if (isSlow) {
return <LoadingModal onCancel={cancel} />;
@@ -50,6 +50,12 @@ export function AsyncButton({ onClick, disabled, children, ...rest }: Props) {
<button class="button is-success" onClick={request} disabled={disabled}>
{children}
</button>
+
+ {!error ? undefined : (
+ <div class="message is-danger" style={{padding:2}}>
+ Unexpected error: {error}
+ </div>
+ )}
</span>
);
}
diff --git a/packages/merchant-backoffice-ui/src/hooks/async.ts b/packages/merchant-backoffice-ui/src/hooks/async.ts
@@ -54,6 +54,7 @@ export function useAsync<T>(
const result = await fn(...args);
setData(result);
} catch (error) {
+ console.error(JSON.stringify(error, undefined, 2))
setError(error instanceof Error ? error.message : String(error));
}
setLoading(false);
diff --git a/packages/merchant-backoffice-ui/src/paths/login/index.tsx b/packages/merchant-backoffice-ui/src/paths/login/index.tsx
@@ -30,6 +30,7 @@ import { useState } from "preact/hooks";
import { NotificationCard } from "../../components/menu/index.js";
import { useSessionContext } from "../../context/session.js";
import { Notification } from "../../utils/types.js";
+import { AsyncButton } from "../../components/exception/AsyncButton.js";
interface Props {}
@@ -41,6 +42,7 @@ const tokenRequest = {
refreshable: true,
} as TokenRequest;
+const VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : undefined;
export function LoginPage(_p: Props): VNode {
const [token, setToken] = useState("");
const [notif, setNotif] = useState<Notification | undefined>(undefined);
@@ -138,38 +140,47 @@ export function LoginPage(_p: Props): VNode {
</div>
</div>
</div>
+ <div
+ style={{
+ position: "absolute",
+ bottom: 0,
+ height: "2rem",
+ }}
+ >
+ Version {VERSION}
+ </div>
</Fragment>
);
}
-function AsyncButton({
- onClick,
- disabled,
- type = "",
- children,
-}: {
- type?: string;
- disabled?: boolean;
- onClick: () => Promise<void>;
- children: ComponentChildren;
-}): VNode {
- const [running, setRunning] = useState(false);
- return (
- <button
- class={"button " + type}
- disabled={disabled || running}
- onClick={() => {
- setRunning(true);
- onClick()
- .then(() => {
- setRunning(false);
- })
- .catch(() => {
- setRunning(false);
- });
- }}
- >
- {children}
- </button>
- );
-}
+// function AsyncButton({
+// onClick,
+// disabled,
+// type = "",
+// children,
+// }: {
+// type?: string;
+// disabled?: boolean;
+// onClick: () => Promise<void>;
+// children: ComponentChildren;
+// }): VNode {
+// const [running, setRunning] = useState(false);
+// return (
+// <button
+// class={"button " + type}
+// disabled={disabled || running}
+// onClick={() => {
+// setRunning(true);
+// onClick()
+// .then(() => {
+// setRunning(false);
+// })
+// .catch((e) => {
+// setRunning(false);
+// });
+// }}
+// >
+// {children}
+// </button>
+// );
+// }
diff --git a/packages/taler-util/src/types-taler-common.ts b/packages/taler-util/src/types-taler-common.ts
@@ -471,7 +471,7 @@ export const codecForTokenSuccessResponseMerchant =
"scope",
codecForEither(
codecForConstString("readonly"),
- codecForConstString("readwrite"),
+ codecForConstString("write"),
codecForConstString("revenue"),
codecForConstString("wiregateway"),
),