diff options
Diffstat (limited to 'packages/demobank-ui/src/pages/QrCodeSection.tsx')
-rw-r--r-- | packages/demobank-ui/src/pages/QrCodeSection.tsx | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/packages/demobank-ui/src/pages/QrCodeSection.tsx b/packages/demobank-ui/src/pages/QrCodeSection.tsx index e07525ab4..109993aae 100644 --- a/packages/demobank-ui/src/pages/QrCodeSection.tsx +++ b/packages/demobank-ui/src/pages/QrCodeSection.tsx @@ -17,6 +17,7 @@ import { HttpStatusCode, stringifyWithdrawUri, + TalerError, TranslatedString, WithdrawUriResult, } from "@gnu-taler/taler-util"; @@ -29,8 +30,9 @@ import { import { Fragment, h, VNode } from "preact"; import { useEffect } from "preact/hooks"; import { QR } from "../components/QR.js"; -import { useAccessAnonAPI } from "../hooks/access.js"; import { buildRequestErrorMessage } from "../utils.js"; +import { useBankCoreApiContext } from "../context/config.js"; +import { assertUnreachable } from "./HomePage.js"; export function QrCodeSection({ withdrawUri, @@ -50,22 +52,30 @@ export function QrCodeSection({ }, []); const talerWithdrawUri = stringifyWithdrawUri(withdrawUri); - const { abortWithdrawal } = useAccessAnonAPI(); + const { api } = useBankCoreApiContext() async function doAbort() { try { - await abortWithdrawal(withdrawUri.withdrawalOperationId); - onAborted(); + const result = await api.abortWithdrawalById(withdrawUri.withdrawalOperationId); + if (result.type === "ok") { + onAborted(); + } else { + switch (result.case) { + case "previously-confirmed": { + notify({ + type: "info", + title: i18n.str`The reserve operation has been confirmed previously and can't be aborted` + }) + break; + } + default: { + assertUnreachable(result.case) + } + } + } } catch (error) { - if (error instanceof RequestError) { - notify( - buildRequestErrorMessage(i18n, error.cause, { - onClientError: (status) => - status === HttpStatusCode.Conflict - ? i18n.str`The reserve operation has been confirmed previously and can't be aborted` - : undefined, - }), - ); + if (error instanceof TalerError) { + notify(buildRequestErrorMessage(i18n, error)) } else { notifyError( i18n.str`Operation failed, please report`, @@ -120,13 +130,13 @@ export function QrCodeSection({ </div> </div> <div class="flex items-center justify-center gap-x-6 border-t border-gray-900/10 px-4 py-4 sm:px-8"> - <button type="button" - // class="disabled:opacity-50 disabled:cursor-default cursor-pointer rounded-md px-3 py-2 text-sm font-semibold text-black shadow-sm hover:bg-red-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-red-600" - class="text-sm font-semibold leading-6 text-gray-900" - onClick={doAbort} - > - Cancel - </button> + <button type="button" + // class="disabled:opacity-50 disabled:cursor-default cursor-pointer rounded-md px-3 py-2 text-sm font-semibold text-black shadow-sm hover:bg-red-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-red-600" + class="text-sm font-semibold leading-6 text-gray-900" + onClick={doAbort} + > + Cancel + </button> </div> </div> |