/*
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 { AmountJson, TalerError } from "@gnu-taler/taler-util";
import { Fragment, VNode, h } from "preact";
import { useBankState } from "../hooks/bank-state.js";
import { PaytoWireTransferForm } from "./PaytoWireTransferForm.js";
import { WalletWithdrawForm } from "./WalletWithdrawForm.js";
import { EmptyObject, RouteDefinition } from "../route.js";
import { useTranslationContext } from "@gnu-taler/web-util/browser";
import { useWithdrawalDetails } from "../hooks/access.js";
import { useEffect } from "preact/hooks";
import { useBackendState } from "../hooks/backend.js";
function ShowOperationPendingTag({
woid,
onOperationAlreadyCompleted,
}: {
woid: string;
onOperationAlreadyCompleted?: () => void;
}): VNode {
const { i18n } = useTranslationContext();
const { state: credentials } = useBackendState();
const result = useWithdrawalDetails(woid);
const loading = !result
const error =
!loading && (result instanceof TalerError || result.type === "fail");
const pending =
!loading && !error &&
(result.body.status === "pending" || result.body.status === "selected")
&& credentials.status === "loggedIn"
&& credentials.username === result.body.username;
useEffect(() => {
if (!loading && !pending && onOperationAlreadyCompleted) {
onOperationAlreadyCompleted();
}
}, [pending]);
if (error || !pending) {
return ;
}
return (
Operation ready
);
}
/**
* Let the user choose a payment option,
* then specify the details trigger the action.
*/
export function PaymentOptions({
routeClose,
routeCashout,
routeChargeWallet,
routeWireTransfer,
tab,
limit,
onOperationCreated,
onClose,
routeOperationDetails,
onAuthorizationRequired,
}: {
limit: AmountJson;
tab: "charge-wallet" | "wire-transfer" | undefined;
onAuthorizationRequired: () => void;
onOperationCreated: (wopid: string) => void;
onClose: () => void;
routeOperationDetails: RouteDefinition<{ wopid: string }>;
routeClose: RouteDefinition;
routeCashout: RouteDefinition;
routeChargeWallet: RouteDefinition;
routeWireTransfer: RouteDefinition<{
account?: string,
subject?: string,
amount?: string,
}>;
}): VNode {
const { i18n } = useTranslationContext();
const [bankState, updateBankState] = useBankState();
return (