/*
This file is part of GNU Taler
(C) 2022-2024 Taler Systems S.A.
GNU Taler is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
GNU Taler; see the file COPYING. If not, see
*/
import {
AbsoluteTime,
Amounts,
HttpStatusCode,
TalerError,
TalerErrorCode,
TranslatedString,
assertUnreachable,
encodeCrock,
getRandomBytes,
parsePaytoUri,
} from "@gnu-taler/taler-util";
import {
Attention,
Loading,
LocalNotificationBanner,
ShowInputErrorLabel,
notifyInfo,
useLocalNotification,
useTranslationContext,
} from "@gnu-taler/web-util/browser";
import { Fragment, VNode, h } from "preact";
import { useEffect, useState } from "preact/hooks";
import { ErrorLoadingWithDebug } from "../../components/ErrorLoadingWithDebug.js";
import { VersionHint, useBankCoreApiContext } from "../../context/config.js";
import { useAccountDetails } from "../../hooks/account.js";
import { useBankState } from "../../hooks/bank-state.js";
import {
TransferCalculation,
useCashoutEstimator,
useConversionInfo,
} from "../../hooks/regional.js";
import { useSessionState } from "../../hooks/session.js";
import { RouteDefinition } from "../../route.js";
import { TanChannel, undefinedIfEmpty } from "../../utils.js";
import { LoginForm } from "../LoginForm.js";
import {
InputAmount,
RenderAmount,
doAutoFocus,
} from "../PaytoWireTransferForm.js";
interface Props {
account: string;
focus?: boolean;
onAuthorizationRequired: () => void;
routeClose: RouteDefinition;
routeHere: RouteDefinition;
}
type FormType = {
isDebit: boolean;
amount: string;
subject: string;
channel: TanChannel;
};
type ErrorFrom = {
[P in keyof T]+?: string;
};
export function CreateCashout({
account: accountName,
onAuthorizationRequired,
focus,
routeHere,
routeClose,
}: Props): VNode {
const { i18n } = useTranslationContext();
const resultAccount = useAccountDetails(accountName);
const {
estimateByCredit: calculateFromCredit,
estimateByDebit: calculateFromDebit,
} = useCashoutEstimator();
const { state: credentials } = useSessionState();
const creds = credentials.status !== "loggedIn" ? undefined : credentials;
const [, updateBankState] = useBankState();
const { bank: api, config, hints } = useBankCoreApiContext();
const [form, setForm] = useState>({ isDebit: true });
const [notification, notify, handleError] = useLocalNotification();
const info = useConversionInfo();
if (!config.allow_conversion) {
return (
The bank configuration does not support cashout operations.