/* This file is part of GNU Taler (C) 2021-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 */ /** * * @author Sebastian Javier Marchano (sebasjm) */ import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { Fragment, h, VNode } from "preact"; import { StateUpdater, useState } from "preact/hooks"; import { MerchantBackend } from "../../../../declaration.js"; import { parsePaytoUri, PaytoType, PaytoUri, PaytoUriBitcoin, PaytoUriIBAN, PaytoUriTalerBank, PaytoUriUnknown } from "@gnu-taler/taler-util"; type Entity = MerchantBackend.BankAccounts.BankAccountEntry; interface Props { accounts: Entity[]; onDelete: (e: Entity) => void; onSelect: (e: Entity) => void; onCreate: () => void; onLoadMoreBefore?: () => void; hasMoreBefore?: boolean; hasMoreAfter?: boolean; onLoadMoreAfter?: () => void; } export function CardTable({ accounts, onCreate, onDelete, onSelect, onLoadMoreAfter, onLoadMoreBefore, hasMoreAfter, hasMoreBefore, }: Props): VNode { const [rowSelection, rowSelectionHandler] = useState([]); const { i18n } = useTranslationContext(); return (

Bank accounts

{accounts.length > 0 ? ( ) : ( )} ); } interface TableProps { rowSelection: string[]; accounts: Entity[]; onDelete: (e: Entity) => void; onSelect: (e: Entity) => void; rowSelectionHandler: StateUpdater; onLoadMoreBefore?: () => void; hasMoreBefore?: boolean; hasMoreAfter?: boolean; onLoadMoreAfter?: () => void; } function toggleSelected(id: T): (prev: T[]) => T[] { return (prev: T[]): T[] => prev.indexOf(id) == -1 ? [...prev, id] : prev.filter((e) => e != id); } function Table({ accounts, onLoadMoreAfter, onDelete, onSelect, onLoadMoreBefore, hasMoreAfter, hasMoreBefore, }: TableProps): VNode { const { i18n } = useTranslationContext(); const emptyList: Record = { "bitcoin": [], "x-taler-bank": [], "iban": [], "unknown": [], } const accountsByType = accounts.reduce((prev, acc) => { const parsed = parsePaytoUri(acc.payto_uri) if (!parsed) return prev //skip if (parsed.targetType !== "bitcoin" && parsed.targetType !== "x-taler-bank" && parsed.targetType !== "iban") { prev["unknown"].push({ parsed, acc }) } else { prev[parsed.targetType].push({ parsed, acc }) } return prev }, emptyList) const bitcoinAccounts = accountsByType["bitcoin"] const talerbankAccounts = accountsByType["x-taler-bank"] const ibanAccounts = accountsByType["iban"] const unkownAccounts = accountsByType["unknown"] return ( {bitcoinAccounts.length > 0 &&

Bitcoin type accounts

{bitcoinAccounts.map(({ parsed, acc }, idx) => { const ac = parsed as PaytoUriBitcoin return ( ); })}
Address Sewgit 1 Sewgit 2
onSelect(acc)} style={{ cursor: "pointer" }} > {ac.targetPath} onSelect(acc)} style={{ cursor: "pointer" }} > {ac.segwitAddrs[0]} onSelect(acc)} style={{ cursor: "pointer" }} > {ac.segwitAddrs[1]}
} {talerbankAccounts.length > 0 &&

Taler type accounts

{talerbankAccounts.map(({ parsed, acc }, idx) => { const ac = parsed as PaytoUriTalerBank return ( ); })}
Host Account name
onSelect(acc)} style={{ cursor: "pointer" }} > {ac.host} onSelect(acc)} style={{ cursor: "pointer" }} > {ac.account}
} {ibanAccounts.length > 0 &&

IBAN type accounts

{ibanAccounts.map(({ parsed, acc }, idx) => { const ac = parsed as PaytoUriIBAN return ( ); })}
Account name IBAN BIC
onSelect(acc)} style={{ cursor: "pointer" }} > {ac.params["receiver-name"]} onSelect(acc)} style={{ cursor: "pointer" }} > {ac.iban} onSelect(acc)} style={{ cursor: "pointer" }} > {ac.bic ?? ""}
} {unkownAccounts.length > 0 &&

Other type accounts

{unkownAccounts.map(({ parsed, acc }, idx) => { const ac = parsed as PaytoUriUnknown return ( ); })}
Type Path
onSelect(acc)} style={{ cursor: "pointer" }} > {ac.targetType} onSelect(acc)} style={{ cursor: "pointer" }} > {ac.targetPath}
} ); } function EmptyTable(): VNode { const { i18n } = useTranslationContext(); return (

There is no accounts yet, add more pressing the + sign

); }