/* This file is part of TALER (C) 2015-2016 GNUnet e.V. 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. 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 TALER; see the file COPYING. If not, see */ /** * Page shown to the user to confirm creation * of a reserve, usually requested by the bank. * * @author Florian Dold */ import { AmountJson, Amounts, ExchangeListItem, GetExchangeTosResult, i18n, WithdrawUriInfoResponse, } from "@gnu-taler/taler-util"; import { VNode, h, Fragment } from "preact"; import { useState } from "preact/hooks"; import { CheckboxOutlined } from "../components/CheckboxOutlined"; import { ExchangeXmlTos } from "../components/ExchangeToS"; import { LogoHeader } from "../components/LogoHeader"; import { Part } from "../components/Part"; import { SelectList } from "../components/SelectList"; import { ButtonSuccess, ButtonWarning, LinkSuccess, TermsOfService, WalletAction, WarningText, } from "../components/styled"; import { useAsyncAsHook } from "../hooks/useAsyncAsHook"; import { acceptWithdrawal, getExchangeTos, getExchangeWithdrawalInfo, getWithdrawalDetailsForUri, listExchanges, setExchangeTosAccepted, } from "../wxApi"; interface Props { talerWithdrawUri?: string; } export interface ViewProps { withdrawalFee: AmountJson; exchangeBaseUrl: string; amount: AmountJson; onSwitchExchange: (ex: string) => void; onWithdraw: () => Promise; onReview: (b: boolean) => void; onAccept: (b: boolean) => void; reviewing: boolean; reviewed: boolean; confirmed: boolean; terms: { value?: TermsDocument; status: TermsStatus; }; knownExchanges: ExchangeListItem[]; } type TermsStatus = "new" | "accepted" | "changed" | "notfound"; type TermsDocument = | TermsDocumentXml | TermsDocumentHtml | TermsDocumentPlain | TermsDocumentJson | TermsDocumentPdf; interface TermsDocumentXml { type: "xml"; document: Document; } interface TermsDocumentHtml { type: "html"; href: URL; } interface TermsDocumentPlain { type: "plain"; content: string; } interface TermsDocumentJson { type: "json"; data: any; } interface TermsDocumentPdf { type: "pdf"; location: URL; } function amountToString(text: AmountJson): string { const aj = Amounts.jsonifyAmount(text); const amount = Amounts.stringifyValue(aj); return `${amount} ${aj.currency}`; } export function View({ withdrawalFee, exchangeBaseUrl, knownExchanges, amount, onWithdraw, onSwitchExchange, terms, reviewing, onReview, onAccept, reviewed, confirmed, }: ViewProps): VNode { const needsReview = terms.status === "changed" || terms.status === "new"; const [switchingExchange, setSwitchingExchange] = useState< string | undefined >(undefined); const exchanges = knownExchanges.reduce( (prev, ex) => ({ ...prev, [ex.exchangeBaseUrl]: ex.exchangeBaseUrl }), {}, ); return (

{i18n.str`Digital cash withdrawal`}

{Amounts.isNonZero(withdrawalFee) && ( )}
{!reviewing && (
{switchingExchange !== undefined ? (
onSwitchExchange(switchingExchange)} > {i18n.str`Confirm exchange selection`}
) : ( setSwitchingExchange("")}> {i18n.str`Switch exchange`} )}
)} {!reviewing && reviewed && (
onReview(true)}> {i18n.str`Show terms of service`}
)} {terms.status === "notfound" && (
{i18n.str`Exchange doesn't have terms of service`}
)} {reviewing && (
{terms.status !== "accepted" && terms.value && terms.value.type === "xml" && ( )} {terms.status !== "accepted" && terms.value && terms.value.type === "plain" && (
{terms.value.content}
)} {terms.status !== "accepted" && terms.value && terms.value.type === "html" && (