/* This file is part of GNU Taler (C) 2022-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 */ 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, VNode, h } from "preact"; import { useEffect, useErrorBoundary } from "preact/hooks"; import { useBankCoreApiContext } from "../context/config.js"; import { useSettingsContext } from "../context/settings.js"; import { useAccountDetails } from "../hooks/access.js"; import { useBackendState } from "../hooks/backend.js"; import { useBankState } from "../hooks/bank-state.js"; import { getAllBooleanPreferences, getLabelForPreferences, usePreferences, } from "../hooks/preferences.js"; import { RenderAmount } from "./PaytoWireTransferForm.js"; import { RouteDefinition } from "../route.js"; const GIT_HASH = typeof __GIT_HASH__ !== "undefined" ? __GIT_HASH__ : undefined; const VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : undefined; export function BankFrame({ children, account, routeAccountDetails, }: { account?: string; routeAccountDetails?: RouteDefinition>; 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) { 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 && routeAccountDetails && (

    )}
    {children}
    ); } function WelcomeAccount({ account, routeAccountDetails }: { account: string, routeAccountDetails: RouteDefinition>; }): VNode { const { i18n } = useTranslationContext(); const result = useAccountDetails(account); if (!result) { return ; } if (result instanceof TalerError) { return
    ; } if (result.type === "fail") { return ( Welcome ); } return ( Welcome, {result.body.name} ); } 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 ( ); }