/* 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 { parsePaytoUri } from "@gnu-taler/taler-util"; import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; import { ErrorMessage } from "../../components/ErrorMessage.js"; import { LoadingError } from "../../components/LoadingError.js"; import { SelectList } from "../../components/SelectList.js"; import { Input, LightText, SubTitle } from "../../components/styled/index.js"; import { useTranslationContext } from "../../context/translation.js"; import { Button } from "../../mui/Button.js"; import { TextFieldHandler } from "../../mui/handlers.js"; import { TextField } from "../../mui/TextField.js"; import { State } from "./index.js"; export function LoadingUriView({ error }: State.LoadingUriError): VNode { const { i18n } = useTranslationContext(); return ( Could not load} error={error} /> ); } export function ReadyView({ currency, error, accountType, alias, onAccountAdded, onCancel, uri, }: State.Ready): VNode { const { i18n } = useTranslationContext(); return (
Add bank account for {currency} Enter the URL of an exchange you trust. {error && ( Unable add this account} description={error} /> )}

Select account type} list={accountType.list} name="accountType" value={accountType.value} onChange={accountType.onChange} />

{accountType.value === "" ? undefined : (

)}
); } function CustomFieldByAccountType({ type, field, }: { type: string; field: TextFieldHandler; }): VNode { const p = parsePaytoUri(field.value); const parts = !p ? [] : p.targetPath.split("/"); const initialPart1 = parts.length > 0 ? parts[0] : ""; const initialPart2 = parts.length > 1 ? parts[1] : ""; const [part1, setPart1] = useState(initialPart1); const [part2, setPart2] = useState(initialPart2); function updateField(): void { if (part1 && part2) { field.onInput(`payto://${type}/${part1}/${part2}`); } else { if (part1) field.onInput(`payto://${type}/${part1}`); } } if (type === "bitcoin") { return ( {field.error && {field.error}} />} { setPart1(v); updateField(); }} /> ); } if (type === "x-taler-bank") { return ( {field.error && {field.error}} />} { setPart1(v); updateField(); }} />{" "} { setPart2(v); updateField(); }} /> ); } if (type === "iban") { return ( {field.error && {field.error}} />} { setPart1(v); updateField(); }} /> ); } return ; }