From e812eae32daddad372c7629867298ca28678a44c Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 25 Oct 2023 18:26:36 -0300 Subject: update more error cases handling from bank-core-api --- .../demobank-ui/src/pages/OperationState/state.ts | 49 ++++++++++++++++++++-- packages/demobank-ui/src/pages/QrCodeSection.tsx | 20 +++++++-- .../demobank-ui/src/pages/WalletWithdrawForm.tsx | 28 +++++++++---- .../src/pages/WithdrawalConfirmationQuestion.tsx | 26 +++++++++++- .../demobank-ui/src/pages/WithdrawalQRCode.tsx | 8 ++-- 5 files changed, 111 insertions(+), 20 deletions(-) (limited to 'packages/demobank-ui') diff --git a/packages/demobank-ui/src/pages/OperationState/state.ts b/packages/demobank-ui/src/pages/OperationState/state.ts index 136a2b505..a4890d726 100644 --- a/packages/demobank-ui/src/pages/OperationState/state.ts +++ b/packages/demobank-ui/src/pages/OperationState/state.ts @@ -50,11 +50,17 @@ export function useComponentState({ currency, onClose }: Props): utils.Recursive switch (resp.case) { case "insufficient-funds": return notify({ type: "error", - title: i18n.str`The operation was rejected due to insufficient funds`, + title: i18n.str`The operation was rejected due to insufficient funds.`, description: resp.detail.hint as TranslatedString, debug: resp.detail, }); - default: assertUnreachable(resp.case) + case "unauthorized": return notify({ + type: "error", + title: i18n.str`Unauthorized to make the opeartion, maybe the session has expired or the password changed.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }); + default: assertUnreachable(resp) } } @@ -99,7 +105,19 @@ export function useComponentState({ currency, onClose }: Props): utils.Recursive description: resp.detail.hint as TranslatedString, debug: resp.detail, }) - default: assertUnreachable(resp.case) + case "invalid-id": return notify({ + type: "error", + title: i18n.str`The operation id is invalid.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }); + case "not-found": return notify({ + type: "error", + title: i18n.str`The operation was not found.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }); + default: assertUnreachable(resp) } } }) @@ -128,6 +146,18 @@ export function useComponentState({ currency, onClose }: Props): utils.Recursive description: resp.detail.hint as TranslatedString, debug: resp.detail, }) + case "invalid-id": return notify({ + type: "error", + title: i18n.str`The operation id is invalid.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }); + case "not-found": return notify({ + type: "error", + title: i18n.str`The operation was not found.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }); default: assertUnreachable(resp) } } @@ -183,7 +213,18 @@ export function useComponentState({ currency, onClose }: Props): utils.Recursive }, } } - default: assertUnreachable(result.case) + case "invalid-id": { + return { + status: "aborted", + error: undefined, + onClose: async () => { + updateSettings("currentWithdrawalOperationId", undefined) + onClose() + }, + } + + } + default: assertUnreachable(result) } } diff --git a/packages/demobank-ui/src/pages/QrCodeSection.tsx b/packages/demobank-ui/src/pages/QrCodeSection.tsx index 8948827aa..9ae1cf268 100644 --- a/packages/demobank-ui/src/pages/QrCodeSection.tsx +++ b/packages/demobank-ui/src/pages/QrCodeSection.tsx @@ -56,17 +56,29 @@ export function QrCodeSection({ async function doAbort() { await withRuntimeErrorHandling(i18n, async () => { - const result = await api.abortWithdrawalById(withdrawUri.withdrawalOperationId); - if (result.type === "ok") { + const resp = await api.abortWithdrawalById(withdrawUri.withdrawalOperationId); + if (resp.type === "ok") { onAborted(); } else { - switch (result.case) { + switch (resp.case) { case "previously-confirmed": return notify({ type: "info", title: i18n.str`The reserve operation has been confirmed previously and can't be aborted` }) + case "invalid-id": return notify({ + type: "error", + title: i18n.str`The operation id is invalid.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) + case "not-found": return notify({ + type: "error", + title: i18n.str`The operation was not found.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) default: { - assertUnreachable(result.case) + assertUnreachable(resp) } } } diff --git a/packages/demobank-ui/src/pages/WalletWithdrawForm.tsx b/packages/demobank-ui/src/pages/WalletWithdrawForm.tsx index f1ff49068..0637a8af4 100644 --- a/packages/demobank-ui/src/pages/WalletWithdrawForm.tsx +++ b/packages/demobank-ui/src/pages/WalletWithdrawForm.tsx @@ -89,26 +89,40 @@ function OldWithdrawalForm({ goToConfirmOperation, limit, onCancel, focus }: { async function doStart() { if (!parsedAmount || !creds) return; await withRuntimeErrorHandling(i18n, async () => { - const result = await api.createWithdrawal(creds, { + const resp = await api.createWithdrawal(creds, { amount: Amounts.stringify(parsedAmount), }); - if (result.type === "ok") { - const uri = parseWithdrawUri(result.body.taler_withdraw_uri); + if (resp.type === "ok") { + const uri = parseWithdrawUri(resp.body.taler_withdraw_uri); if (!uri) { return notifyError( i18n.str`Server responded with an invalid withdraw URI`, - i18n.str`Withdraw URI: ${result.body.taler_withdraw_uri}`); + i18n.str`Withdraw URI: ${resp.body.taler_withdraw_uri}`); } else { updateSettings("currentWithdrawalOperationId", uri.withdrawalOperationId) goToConfirmOperation(uri.withdrawalOperationId); } } else { - switch (result.case) { + switch (resp.case) { case "insufficient-funds": { - notify({ type: "error", title: i18n.str`The operation was rejected due to insufficient funds` }) + notify({ + type: "error", + title: i18n.str`The operation was rejected due to insufficient funds`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) break; } - default: assertUnreachable(result.case) + case "unauthorized": { + notify({ + type: "error", + title: i18n.str`The operation was rejected due to insufficient funds`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) + break; + } + default: assertUnreachable(resp) } } }) diff --git a/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx b/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx index 895094c28..5e0fa322f 100644 --- a/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx +++ b/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx @@ -110,6 +110,18 @@ export function WithdrawalConfirmationQuestion({ description: resp.detail.hint as TranslatedString, debug: resp.detail, }); + case "invalid-id": return notify({ + type: "error", + title: i18n.str`The operation id is invalid.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) + case "not-found": return notify({ + type: "error", + title: i18n.str`The operation was not found.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) default: assertUnreachable(resp) } } @@ -129,8 +141,20 @@ export function WithdrawalConfirmationQuestion({ type: "error", title: i18n.str`The reserve operation has been confirmed previously and can't be aborted` }); + case "invalid-id": return notify({ + type: "error", + title: i18n.str`The operation id is invalid.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) + case "not-found": return notify({ + type: "error", + title: i18n.str`The operation was not found.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) default: { - assertUnreachable(resp.case) + assertUnreachable(resp) } } } diff --git a/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx b/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx index 5c300d0ab..bdd8ea585 100644 --- a/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx +++ b/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx @@ -23,14 +23,13 @@ import { } from "@gnu-taler/taler-util"; import { notifyInfo, useTranslationContext } from "@gnu-taler/web-util/browser"; import { Fragment, VNode, h } from "preact"; +import { Attention } from "../components/Attention.js"; import { ErrorLoading } from "../components/ErrorLoading.js"; import { Loading } from "../components/Loading.js"; import { useWithdrawalDetails } from "../hooks/access.js"; -import { assertUnreachable } from "./WithdrawalOperationPage.js"; import { QrCodeSection } from "./QrCodeSection.js"; import { WithdrawalConfirmationQuestion } from "./WithdrawalConfirmationQuestion.js"; -import { Attention } from "../components/Attention.js"; -import { Pages } from "../pages.js"; +import { assertUnreachable } from "./WithdrawalOperationPage.js"; const logger = new Logger("WithdrawalQRCode"); @@ -59,7 +58,8 @@ export function WithdrawalQRCode({ if (result.type === "fail") { switch (result.case) { case "not-found": return - default: assertUnreachable(result.case) + case "invalid-id": return + default: assertUnreachable(result) } } -- cgit v1.2.3