diff options
Diffstat (limited to 'packages/demobank-ui/src/pages/WalletWithdrawForm.tsx')
-rw-r--r-- | packages/demobank-ui/src/pages/WalletWithdrawForm.tsx | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/packages/demobank-ui/src/pages/WalletWithdrawForm.tsx b/packages/demobank-ui/src/pages/WalletWithdrawForm.tsx index 8bbfe0713..7f3e207ac 100644 --- a/packages/demobank-ui/src/pages/WalletWithdrawForm.tsx +++ b/packages/demobank-ui/src/pages/WalletWithdrawForm.tsx @@ -19,6 +19,7 @@ import { Amounts, HttpStatusCode, Logger, + parseWithdrawUri, } from "@gnu-taler/taler-util"; import { RequestError, @@ -26,7 +27,11 @@ import { } from "@gnu-taler/web-util/lib/index.browser"; import { h, VNode } from "preact"; import { useEffect, useRef, useState } from "preact/hooks"; -import { PageStateType } from "../context/pageState.js"; +import { + ObservedStateType, + PageStateType, + notifyError, +} from "../context/pageState.js"; import { useAccessAPI } from "../hooks/access.js"; import { buildRequestErrorMessage, undefinedIfEmpty } from "../utils.js"; import { ShowInputErrorLabel } from "./ShowInputErrorLabel.js"; @@ -36,18 +41,12 @@ const logger = new Logger("WalletWithdrawForm"); export function WalletWithdrawForm({ focus, limit, - onError, onSuccess, }: { limit: AmountJson; focus?: boolean; - onError: (e: PageStateType["error"]) => void; - onSuccess: ( - data: SandboxBackend.Access.BankAccountCreateWithdrawalResponse, - ) => void; + onSuccess: (operationId: string) => void; }): VNode { - // const backend = useBackendContext(); - // const { pageState, pageStateSetter } = usePageContext(); const { i18n } = useTranslationContext(); const { createWithdrawal } = useAccessAPI(); @@ -129,10 +128,18 @@ export function WalletWithdrawForm({ const result = await createWithdrawal({ amount: Amounts.stringify(parsedAmount), }); - onSuccess(result.data); + const uri = parseWithdrawUri(result.data.taler_withdraw_uri); + if (!uri) { + return notifyError({ + title: i18n.str`Server responded with an invalid withdraw URI`, + description: i18n.str`Withdraw URI: ${result.data.taler_withdraw_uri}`, + }); + } else { + onSuccess(uri.withdrawalOperationId); + } } catch (error) { if (error instanceof RequestError) { - onError( + notifyError( buildRequestErrorMessage(i18n, error.cause, { onClientError: (status) => status === HttpStatusCode.Forbidden @@ -141,7 +148,7 @@ export function WalletWithdrawForm({ }), ); } else { - onError({ + notifyError({ title: i18n.str`Operation failed, please report`, description: error instanceof Error |