diff options
author | Sebastian <sebasjm@gmail.com> | 2023-02-28 19:03:43 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-02-28 19:03:43 -0300 |
commit | 9922192b0dba2e479b5af3e29c1d44b98e4d29d7 (patch) | |
tree | 260f2836892b93188bf17e30b2024ccea21262dd /packages/demobank-ui/src/pages/PaytoWireTransferForm.tsx | |
parent | 740849dd89e3746fdc34c3a112288dbfe4bd7220 (diff) | |
download | wallet-core-9922192b0dba2e479b5af3e29c1d44b98e4d29d7.tar.xz |
fix #7729
Diffstat (limited to 'packages/demobank-ui/src/pages/PaytoWireTransferForm.tsx')
-rw-r--r-- | packages/demobank-ui/src/pages/PaytoWireTransferForm.tsx | 64 |
1 files changed, 47 insertions, 17 deletions
diff --git a/packages/demobank-ui/src/pages/PaytoWireTransferForm.tsx b/packages/demobank-ui/src/pages/PaytoWireTransferForm.tsx index 07b011a00..9698d5b98 100644 --- a/packages/demobank-ui/src/pages/PaytoWireTransferForm.tsx +++ b/packages/demobank-ui/src/pages/PaytoWireTransferForm.tsx @@ -17,22 +17,20 @@ import { Amounts, buildPayto, + HttpStatusCode, Logger, parsePaytoUri, stringifyPaytoUri, } from "@gnu-taler/taler-util"; import { - InternationalizationAPI, RequestError, useTranslationContext, } from "@gnu-taler/web-util/lib/index.browser"; import { h, VNode } from "preact"; -import { StateUpdater, useEffect, useRef, useState } from "preact/hooks"; -import { useBackendContext } from "../context/backend.js"; -import { PageStateType, usePageContext } from "../context/pageState.js"; +import { useEffect, useRef, useState } from "preact/hooks"; +import { PageStateType } from "../context/pageState.js"; import { useAccessAPI } from "../hooks/access.js"; -import { BackendState } from "../hooks/backend.js"; -import { undefinedIfEmpty } from "../utils.js"; +import { buildRequestErrorMessage, undefinedIfEmpty } from "../utils.js"; import { ShowInputErrorLabel } from "./ShowInputErrorLabel.js"; const logger = new Logger("PaytoWireTransferForm"); @@ -184,11 +182,35 @@ export function PaytoWireTransferForm({ ibanPayto.params.message = encodeURIComponent(subject); const paytoUri = stringifyPaytoUri(ibanPayto); - await createTransaction({ - paytoUri, - amount: `${currency}:${amount}`, - }); - onSuccess(); + try { + await createTransaction({ + paytoUri, + amount: `${currency}:${amount}`, + }); + onSuccess(); + setAmount(undefined); + setIban(undefined); + setSubject(undefined); + } catch (error) { + if (error instanceof RequestError) { + onError( + buildRequestErrorMessage(i18n, error.cause, { + onClientError: (status) => + status === HttpStatusCode.BadRequest + ? i18n.str`The request was invalid or the payto://-URI used unacceptable features.` + : undefined, + }), + ); + } else { + onError({ + title: i18n.str`Operation failed, please report`, + description: + error instanceof Error + ? error.message + : JSON.stringify(error), + }); + } + } }} /> <input @@ -298,13 +320,21 @@ export function PaytoWireTransferForm({ rawPaytoInputSetter(undefined); } catch (error) { if (error instanceof RequestError) { - const errorData: SandboxBackend.SandboxError = - error.info.error; - + onError( + buildRequestErrorMessage(i18n, error.cause, { + onClientError: (status) => + status === HttpStatusCode.BadRequest + ? i18n.str`The request was invalid or the payto://-URI used unacceptable features.` + : undefined, + }), + ); + } else { onError({ - title: i18n.str`Transfer creation gave response error`, - description: errorData.error.description, - debug: JSON.stringify(errorData), + title: i18n.str`Operation failed, please report`, + description: + error instanceof Error + ? error.message + : JSON.stringify(error), }); } } |