/* 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 { Amounts, TalerError, TranslatedString } from "@gnu-taler/taler-util"; import { Footer, GlobalNotificationsBanner, Header, Loading, notifyError, notifyException, useTranslationContext } from "@gnu-taler/web-util/browser"; import { ComponentChildren, Fragment, VNode, h } from "preact"; import { useEffect, useErrorBoundary, useState } from "preact/hooks"; import { useAccountDetails } from "../hooks/access.js"; import { useBackendState } from "../hooks/backend.js"; import { getAllBooleanPreferences, getLabelForPreferences, usePreferences } from "../hooks/preferences.js"; import { RenderAmount } from "./PaytoWireTransferForm.js"; import { useSettingsContext } from "../context/settings.js"; import { useBankCoreApiContext } from "../context/config.js"; import { useBankState } from "../hooks/bank-state.js"; const GIT_HASH = typeof __GIT_HASH__ !== "undefined" ? __GIT_HASH__ : undefined; const VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : undefined; export function BankFrame({ children, account, }: { account?: string, children: ComponentChildren; }): VNode { const { i18n } = useTranslationContext(); const backend = useBackendState(); const settings = useSettingsContext(); const [preferences, updatePreferences] = usePreferences(); const [, , resetBankState] = useBankState() const [error, resetError] = useErrorBoundary(); useEffect(() => { if (error) { const desc = (error instanceof Error ? error.stack : String(error)) as TranslatedString if (error instanceof Error) { console.log("Internal error, please report", error) notifyException(i18n.str`Internal error, please report.`, error) } else { console.log("Internal error, please report", error) notifyError(i18n.str`Internal error, please report.`, String(error) as TranslatedString) } resetError() } }, [error]) return (
{ backend.logOut() resetBankState(); }} sites={!settings.topNavSites ? [] : Object.entries(settings.topNavSites)} supportedLangs={["en", "es", "de"]} >
  • Preferences
      {getAllBooleanPreferences().map(set => { const isOn: boolean = !!preferences[set] return
    • {getLabelForPreferences(set, i18n)}
    • })}
  • {account &&

    }
    {children}
    ); } function WelcomeAccount({ account: accountName }: { account: string }): VNode { const { i18n } = useTranslationContext(); return Welcome, {accountName} // const result = useAccountDetails(accountName); // if (!result) { // return // } // if (result instanceof TalerError) { // return
    // } // const payto = result.type === "fail" ? undefined : parsePaytoUri(result.body.payto_uri) // const info = !payto || !payto.isKnown ? undefined // : payto.targetType === "iban" ? { account: payto.iban, uri: stringifyPaytoUri(payto) } // : payto.targetType === "x-taler-bank" ? { account: payto.account, uri: stringifyPaytoUri(payto) } // : undefined; // return // Welcome, {accountName} {info !== undefined ? // // ({info.account} info.uri} />) // // : }! // } function AccountBalance({ account }: { account: string }): VNode { const result = useAccountDetails(account); const { config } = useBankCoreApiContext(); if (!result) { return } if (result instanceof TalerError) { return
    } if (result.type === "fail") return
    return }