taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 827a8d875b72b6c479651064587ca10acfd0770a
parent ae065fe0f6f07edb5061dccef8f5401b776980c8
Author: Sebastian <sebasjm@taler-systems.com>
Date:   Fri,  3 Apr 2026 12:03:56 -0300

fix #11307

Diffstat:
Mpackages/merchant-backoffice-ui/src/components/SolveMFA.tsx | 27++++-----------------------
Mpackages/merchant-backoffice-ui/src/components/form/InputCode.tsx | 18+++++++++++++++---
Mpackages/merchant-backoffice-ui/src/scss/_loading.scss | 16++++++++++++++++
Mpackages/taler-util/src/http-client/merchant.ts | 4+++-
Mpackages/web-util/src/components/Button.tsx | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
Mpackages/web-util/src/hooks/useNotifications.ts | 8++++++++
6 files changed, 109 insertions(+), 33 deletions(-)

diff --git a/packages/merchant-backoffice-ui/src/components/SolveMFA.tsx b/packages/merchant-backoffice-ui/src/components/SolveMFA.tsx @@ -144,8 +144,6 @@ function SolveChallenge({ numTries: 0, solvable: true, }); - const [{ showDebugInfo }] = useCommonPreferences(); - const [currentExpiration, setCurrentExpiration] = useState(expiration); const [showExpired, setExpired] = useState( AbsoluteTime.isExpired(currentExpiration), @@ -278,25 +276,6 @@ function SolveChallenge({ <Fragment> <LocalNotificationBannerBulma notification={notification} /> - {showDebugInfo ? ( - <pre> - {JSON.stringify( - { - retransmission: - currentRetransmission.t_ms === "never" - ? "never" - : new Date(currentRetransmission.t_ms).toISOString(), - expiration: - currentExpiration.t_ms === "never" - ? "never" - : new Date(currentExpiration.t_ms).toISOString(), - }, - undefined, - 2, - )} - </pre> - ) : undefined} - <div class="columns is-centered" style={{ margin: "auto" }}> <div class="column is-two-thirds "> <div class="modal is-active" style={{ position: "initial" }}> @@ -512,6 +491,7 @@ export function SolveMFAChallenges({ if (selected) { return ( <SolveChallenge + key={selected.ch.challenge_id} onCancel={onCancel} challenge={selected.ch} expiration={selected.expiration} @@ -519,7 +499,6 @@ export function SolveMFAChallenges({ focus={focus} showFull={showFull ?? {}} onSolved={async () => { - setSelected(undefined); const total = [...solved, selected.ch.challenge_id]; const enough = currentChallenge.combi_and ? total.length === currentChallenge.challenges.length @@ -533,7 +512,9 @@ export function SolveMFAChallenges({ return pending; }); if (nextPending) { - sendMessage.withArgs(nextPending).call(); + await sendMessage.withArgs(nextPending).call(); + } else { + setSelected(undefined); } } }} diff --git a/packages/merchant-backoffice-ui/src/components/form/InputCode.tsx b/packages/merchant-backoffice-ui/src/components/form/InputCode.tsx @@ -24,6 +24,8 @@ import { InputProps, useField } from "./useField.js"; import { useRef } from "preact/hooks"; import { doAutoFocus } from "./Input.js"; import { useEffect } from "preact/hooks"; +import { useState } from "preact/hooks"; +import { useTranslationContext } from "@gnu-taler/web-util/browser"; interface Props<T> extends InputProps<T> { inputExtra?: any; @@ -47,7 +49,10 @@ export function InputCode<T>({ dashesIndex = [], filter, }: Props<keyof T>): VNode { - const { error, value, onChange, required } = useField<T>(name); + const { i18n } = useTranslationContext(); + const { error: inputError, value, onChange, required } = useField<T>(name); + const [pasteError, setPasteError] = useState<string>(); + const error = pasteError ?? inputError; const elementArray = Array.from<HTMLInputElement | null>({ length: size, @@ -138,6 +143,10 @@ export function InputCode<T>({ .then((r) => { onChange(cleared as any); }); + } else { + setPasteError( + i18n.str`Can't paste this content. Please copy the 8 digits again.`, + ); } } }} @@ -166,10 +175,11 @@ export function InputCode<T>({ name={String(name)} onKeyDown={(e) => { if (e.key === "Backspace") { + setPasteError(undefined); if (idx > 0) { elements.current[idx - 1]?.focus(); - e.currentTarget.value = "" - onChange(undefined as any) + e.currentTarget.value = ""; + onChange(undefined as any); e.preventDefault(); } } else if (e.key === "ArrowLeft") { @@ -192,6 +202,7 @@ export function InputCode<T>({ e.preventDefault(); const v = filter(e.currentTarget.value); e.currentTarget.value = v ?? ""; + setPasteError(undefined); if (v === undefined) { onChange(undefined as any); return; @@ -203,6 +214,7 @@ export function InputCode<T>({ const total = result(); if (total.length === size) { + setPasteError(undefined); onChange(total as any); } }} diff --git a/packages/merchant-backoffice-ui/src/scss/_loading.scss b/packages/merchant-backoffice-ui/src/scss/_loading.scss @@ -49,3 +49,19 @@ transform: rotate(360deg); } } + +.lds-ring.small { + display: flex; + width: 40px; + height: 40px; + align-items: center; + // position: initial; +} + +.lds-ring.small div { + // position: initial; + width: 24px; + height: 24px; + margin: 2px; + border-width: 4px ; +} diff --git a/packages/taler-util/src/http-client/merchant.ts b/packages/taler-util/src/http-client/merchant.ts @@ -892,7 +892,9 @@ export class TalerMerchantInstanceHttpClient { return opFixedSuccess({ etag, ...f.body }); } case HttpStatusCode.NoContent: - return opKnownHttpFailure(resp.status, resp, {} as any); + // FIXME: using opKnownHttpFailure is wrong here + // we expect to read a body with the error description + return opKnownHttpFailure(resp.status, resp, {} as any); case HttpStatusCode.NotModified: return opKnownFailureWithBody(resp.status, { etag }); case HttpStatusCode.Unauthorized: // FIXME: missing in docs diff --git a/packages/web-util/src/components/Button.tsx b/packages/web-util/src/components/Button.tsx @@ -126,6 +126,29 @@ export function ButtonBetterBulma({ ...rest }: PropsBetter & { "data-tooltip"?: string }): VNode { const [running, setRunning] = useState(false); + if (onClick) { + { + const prev = onClick.onStart; + onClick.onStart = () => { + setRunning(true); + prev(); + }; + } + { + const prev = onClick.onSuccess; + onClick.onSuccess = (...args) => { + setRunning(false); + return prev(...args); + }; + } + { + const prev = onClick.onFail; + onClick.onFail = (...args) => { + setRunning(false); + return prev(...args); + }; + } + } return ( <button class="button is-success" @@ -137,21 +160,55 @@ export function ButtonBetterBulma({ if (!onClick || !onClick.args) { return; } - setRunning(true); - onClick.call().finally(() => { - setRunning(false); - }); + onClick.call(); }} > - {running ? <Wait /> : children} + {running ? <Spinner /> : children} </button> ); } +function Spinner(): VNode { + return ( + <div + class="columns is-centered is-vcentered" + style={{ + width: 80, + height: 40, + }} + > + <div class="lds-ring small"> + <div /> + <div /> + <div /> + <div /> + </div> + </div> + ); +} + function Wait(): VNode { return ( <Fragment> - <div id="l1" /> + <div role="status"> + <svg + aria-hidden="true" + class="w-8 h-8 text-neutral-tertiary animate-spin fill-brand" + viewBox="0 0 100 101" + fill="none" + xmlns="http://www.w3.org/2000/svg" + > + <path + d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" + fill="currentColor" + /> + <path + d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" + fill="currentFill" + /> + </svg> + <span class="sr-only">Loading...</span> + </div> </Fragment> ); } diff --git a/packages/web-util/src/hooks/useNotifications.ts b/packages/web-util/src/hooks/useNotifications.ts @@ -243,6 +243,7 @@ export function useLocalNotificationBetter(): [ call: async (): Promise<void> => { if (!thiz.args) return; try { + thiz.onStart(); const resp = await doAction(...thiz.args); switch (resp.type) { case "ok": { @@ -277,6 +278,7 @@ export function useLocalNotificationBetter(): [ onFail: (fail, ...rest) => i18n.str`Unhandled failure trying to ${opName}. Code ${fail.case}`, onSuccess: () => undefined, + onStart: () => undefined, }; return thiz; } @@ -457,6 +459,11 @@ function sanitizeFunctionArguments(args: any[]): string { .join(", "); } +interface AppEvents<Errors,Args> { + 'on-success': { userId: string; timestamp: number }; + 'on-fail': undefined; // Or void if no payload +} + /** * A function converted into a safe handler. * @@ -484,6 +491,7 @@ export interface SafeHandlerTemplate<Args extends any[], Errors> { onSuccess: OnOperationSuccesReturnType<Errors, Args>; onFail: OnOperationFailReturnType<Errors, Args>; + onStart: () => void; } function successWithTitle(title: TranslatedString): NotificationMessage {