/* This file is part of GNU Taler (C) 2022 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 { stringifyWithdrawUri } from "@gnu-taler/taler-util"; import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { Fragment, VNode, h } from "preact"; import { useEffect, useMemo, useState } from "preact/hooks"; import { QR } from "../../components/QR.js"; import { ShowInputErrorLabel } from "../../components/ShowInputErrorLabel.js"; import { useSettings } from "../../hooks/settings.js"; import { undefinedIfEmpty } from "../../utils.js"; import { State } from "./index.js"; export function InvalidPaytoView({ payto, onClose }: State.InvalidPayto) { return (
Payto from server is not valid "{payto}"
); } export function InvalidWithdrawalView({ uri, onClose }: State.InvalidWithdrawal) { return (
Withdrawal uri from server is not valid "{uri}"
); } export function InvalidReserveView({ reserve, onClose }: State.InvalidReserve) { return (
Reserve from server is not valid "{reserve}"
); } export function NeedConfirmationView({ error, onAbort, onConfirm, busy }: State.NeedConfirmation) { const { i18n } = useTranslationContext() const captchaNumbers = useMemo(() => { return { a: Math.floor(Math.random() * 10), b: Math.floor(Math.random() * 10), }; }, []); const [captchaAnswer, setCaptchaAnswer] = useState(); const answer = parseInt(captchaAnswer ?? "", 10); const errors = undefinedIfEmpty({ answer: !captchaAnswer ? i18n.str`Answer the question before continue` : Number.isNaN(answer) ? i18n.str`The answer should be a number` : answer !== captchaNumbers.a + captchaNumbers.b ? i18n.str`The answer "${answer}" to "${captchaNumbers.a} + ${captchaNumbers.b}" is wrong.` : undefined, }) ?? (busy ? {} as Record : undefined); return (

Confirm the withdrawal operation

{ e.preventDefault() }} >
{ setCaptchaAnswer(e.currentTarget.value) }} />
{/*

Wire transfer details

{((): VNode => { switch (details.account.targetType) { case "iban": { const p = details.account as PaytoUriIBAN const name = p.params["receiver-name"] return
Exchange account
{p.iban}
{name &&
Exchange name
{p.params["receiver-name"]}
}
} case "x-taler-bank": { const p = details.account as PaytoUriTalerBank const name = p.params["receiver-name"] return
Exchange account
{p.account}
{name &&
Exchange name
{p.params["receiver-name"]}
}
} default: return
Exchange account
{details.account.targetPath}
} })()}
Withdrawal identification
{details.reserve}
Amount
To be added
// {/* Amounts.stringifyValue(details.amount)
*/}
); } export function AbortedView({ error, onClose }: State.Aborted) { return (
aborted
); } export function ConfirmedView({ error, onClose }: State.Confirmed) { const { i18n } = useTranslationContext(); const [settings, updateSettings] = useSettings() return (

The wire transfer to the Taler operator has been initiated. You will soon receive the requested amount in your Taler wallet.

Do not show this again
); } export function ReadyView({ uri, onClose }: State.Ready): VNode<{}> { const { i18n } = useTranslationContext(); useEffect(() => { //Taler Wallet WebExtension is listening to headers response and tab updates. //In the SPA there is no header response with the Taler URI so //this hack manually triggers the tab update after the QR is in the DOM. // WebExtension will be using // https://developer.chrome.com/docs/extensions/reference/tabs/#event-onUpdated document.title = `${document.title} ${uri.withdrawalOperationId}`; }, []); const talerWithdrawUri = stringifyWithdrawUri(uri); return

On this device

If you are using a desktop browser you can open the popup now or click the link if you have the "Inject Taler support" option enabled.

On a mobile phone

Scan the QR code with your mobile device.

}