/*
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 {
KnownBankAccountsInfo,
PaytoUriBitcoin,
PaytoUriIBAN,
PaytoUriTalerBank,
} from "@gnu-taler/taler-util";
import { styled } from "@linaria/react";
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,
SvgIcon,
WarningText,
} 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 checkIcon from "../../svg/check_24px.svg";
import warningIcon from "../../svg/warning_24px.svg";
import deleteIcon from "../../svg/delete_24px.svg";
import { State } from "./index.js";
type AccountType = "bitcoin" | "x-taler-bank" | "iban";
type ComponentFormByAccountType = {
[type in AccountType]: (props: { field: TextFieldHandler }) => VNode;
};
type ComponentListByAccountType = {
[type in AccountType]: (props: {
list: KnownBankAccountsInfo[];
onDelete: (a: KnownBankAccountsInfo) => Promise;
}) => VNode;
};
const formComponentByAccountType: ComponentFormByAccountType = {
iban: IbanAddressAccount,
bitcoin: BitcoinAddressAccount,
"x-taler-bank": TalerBankAddressAccount,
};
const tableComponentByAccountType: ComponentListByAccountType = {
iban: IbanTable,
bitcoin: BitcoinTable,
"x-taler-bank": TalerBankTable,
};
const AccountTable = styled.table`
width: 100%;
border-collapse: separate;
border-spacing: 0px 10px;
tbody tr:nth-child(odd) > td:not(.actions, .kyc) {
background-color: lightgrey;
}
.actions,
.kyc {
width: 10px;
background-color: inherit;
}
`;
export function LoadingUriView({ error }: State.LoadingUriError): VNode {
const { i18n } = useTranslationContext();
return (
Could not load}
error={error}
/>
);
}
export function ReadyView({
currency,
error,
accountType,
accountByType,
alias,
onAccountAdded,
deleteAccount,
onCancel,
uri,
}: State.Ready): VNode {
const { i18n } = useTranslationContext();
return (
Known accounts for {currency}
To add a new account first select the account type.
{error && (
Unable add this account}
description={error}
/>
)}