aboutsummaryrefslogtreecommitdiff
path: root/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx')
-rw-r--r--packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx77
1 files changed, 48 insertions, 29 deletions
diff --git a/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx b/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx
index ddcd2492d..602ec9bd8 100644
--- a/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx
+++ b/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx
@@ -22,6 +22,7 @@ import {
PaytoUri,
PaytoUriIBAN,
PaytoUriTalerBank,
+ TalerError,
TranslatedString,
WithdrawUriResult
} from "@gnu-taler/taler-util";
@@ -35,10 +36,12 @@ import {
import { Fragment, VNode, h } from "preact";
import { useMemo, useState } from "preact/hooks";
import { ShowInputErrorLabel } from "../components/ShowInputErrorLabel.js";
-import { useAccessAnonAPI } from "../hooks/access.js";
import { buildRequestErrorMessage, undefinedIfEmpty } from "../utils.js";
import { useSettings } from "../hooks/settings.js";
import { RenderAmount } from "./PaytoWireTransferForm.js";
+import { useBankCoreApiContext } from "../context/config.js";
+import { assertUnreachable } from "./HomePage.js";
+import { mutate } from "swr";
const logger = new Logger("WithdrawalConfirmationQuestion");
@@ -70,7 +73,7 @@ export function WithdrawalConfirmationQuestion({
};
}, []);
- const { confirmWithdrawal, abortWithdrawal } = useAccessAnonAPI();
+ const { api } = useBankCoreApiContext()
const [captchaAnswer, setCaptchaAnswer] = useState<string | undefined>();
const answer = parseInt(captchaAnswer ?? "", 10);
const [busy, setBusy] = useState<Record<string, undefined>>()
@@ -87,24 +90,32 @@ export function WithdrawalConfirmationQuestion({
async function doTransfer() {
try {
setBusy({})
- await confirmWithdrawal(
- withdrawUri.withdrawalOperationId,
- );
- if (!settings.showWithdrawalSuccess) {
- notifyInfo(i18n.str`Wire transfer completed!`)
+ const resp = await api.confirmWithdrawalById(withdrawUri.withdrawalOperationId);
+ if (resp.type === "ok") {
+ mutate(() => true)// clean any info that we have
+ if (!settings.showWithdrawalSuccess) {
+ notifyInfo(i18n.str`Wire transfer completed!`)
+ }
+ } else {
+ switch (resp.case) {
+ case "previously-aborted": return notify({
+ type: "error",
+ title: i18n.str`The withdrawal has been aborted previously and can't be confirmed`,
+ description: resp.detail.hint as TranslatedString,
+ debug: resp.detail,
+ });
+ case "no-exchange-or-reserve-selected": return notify({
+ type: "error",
+ title: i18n.str`The withdraw operation cannot be confirmed because no exchange and reserve public key selection happened before`,
+ description: resp.detail.hint as TranslatedString,
+ debug: resp.detail,
+ });
+ default: assertUnreachable(resp)
+ }
}
} catch (error) {
- if (error instanceof RequestError) {
- notify(
- buildRequestErrorMessage(i18n, error.cause, {
- onClientError: (status) =>
- status === HttpStatusCode.Conflict
- ? i18n.str`The withdrawal has been aborted previously and can't be confirmed`
- : status === HttpStatusCode.UnprocessableEntity
- ? i18n.str`The withdraw operation cannot be confirmed because no exchange and reserve public key selection happened before`
- : undefined,
- }),
- );
+ if (error instanceof TalerError) {
+ notify(buildRequestErrorMessage(i18n, error))
} else {
notifyError(
i18n.str`Operation failed, please report`,
@@ -120,18 +131,26 @@ export function WithdrawalConfirmationQuestion({
async function doCancel() {
try {
setBusy({})
- await abortWithdrawal(withdrawUri.withdrawalOperationId);
- onAborted();
+ const resp = await api.abortWithdrawalById(withdrawUri.withdrawalOperationId);
+ if (resp.type === "ok") {
+ onAborted();
+ } else {
+ switch (resp.case) {
+ case "previously-confirmed": {
+ notify({
+ type: "error",
+ title: i18n.str`The reserve operation has been confirmed previously and can't be aborted`
+ });
+ break;
+ }
+ default: {
+ assertUnreachable(resp.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`,