diff options
Diffstat (limited to 'packages/demobank-ui/src/components/app.tsx')
-rw-r--r-- | packages/demobank-ui/src/components/app.tsx | 90 |
1 files changed, 39 insertions, 51 deletions
diff --git a/packages/demobank-ui/src/components/app.tsx b/packages/demobank-ui/src/components/app.tsx index 7cf658681..beb24da57 100644 --- a/packages/demobank-ui/src/components/app.tsx +++ b/packages/demobank-ui/src/components/app.tsx @@ -15,47 +15,26 @@ */ import { - LibtoolVersion, + canonicalizeBaseUrl, getGlobalLogLevel, - setGlobalLogLevelFromString, + setGlobalLogLevelFromString } from "@gnu-taler/taler-util"; -import { TranslationProvider, useApiContext } from "@gnu-taler/web-util/browser"; -import { ComponentChildren, Fragment, FunctionalComponent, VNode, h } from "preact"; +import { TranslationProvider } from "@gnu-taler/web-util/browser"; +import { Fragment, FunctionalComponent, h } from "preact"; import { SWRConfig } from "swr"; -import { BackendStateProvider, useBackendContext } from "../context/backend.js"; +import { BackendStateProvider } from "../context/backend.js"; +import { BankCoreApiProvider } from "../context/config.js"; import { strings } from "../i18n/strings.js"; +import { bankUiSettings } from "../settings.js"; import { Routing } from "./Routing.js"; -import { useEffect, useState } from "preact/hooks"; -import { Loading } from "./Loading.js"; -import { getInitialBackendBaseURL } from "../hooks/backend.js"; -import { BANK_INTEGRATION_PROTOCOL_VERSION, useConfigState } from "../hooks/config.js"; -import { ErrorLoading } from "./ErrorLoading.js"; -import { BankFrame } from "../pages/BankFrame.js"; -import { ConfigStateProvider } from "../context/config.js"; const WITH_LOCAL_STORAGE_CACHE = false; -/** - * FIXME: - * - * - INPUT elements have their 'required' attribute ignored. - * - * - the page needs a "home" button that either redirects to - * the profile page (when the user is logged in), or to - * the very initial home page. - * - * - histories 'pages' are grouped in UL elements that cause - * the rendering to visually separate each UL. History elements - * should instead line up without any separation caused by - * a implementation detail. - * - * - Many strings need to be i18n-wrapped. - */ - const App: FunctionalComponent = () => { + const baseUrl = getInitialBackendBaseURL(); return ( <TranslationProvider source={strings}> <BackendStateProvider> - <VersionCheck> + <BankCoreApiProvider baseUrl={baseUrl}> <SWRConfig value={{ provider: WITH_LOCAL_STORAGE_CACHE @@ -65,34 +44,15 @@ const App: FunctionalComponent = () => { > <Routing /> </SWRConfig> - </VersionCheck> + </BankCoreApiProvider> </BackendStateProvider> </TranslationProvider > ); }; + (window as any).setGlobalLogLevelFromString = setGlobalLogLevelFromString; (window as any).getGlobalLevel = getGlobalLogLevel; -function VersionCheck({ children }: { children: ComponentChildren }): VNode { - const checked = useConfigState() - - if (checked === undefined) { - return <Loading /> - } - if (checked.type === "wrong") { - return <BankFrame> - the bank backend is not supported. supported version "{BANK_INTEGRATION_PROTOCOL_VERSION}", server version "{checked}" - </BankFrame> - } - if (checked.type === "ok") { - return <ConfigStateProvider value={checked.result}>{children}</ConfigStateProvider> - } - - return <BankFrame> - <ErrorLoading error={checked.result} /> - </BankFrame> -} - function localStorageProvider(): Map<unknown, unknown> { const map = new Map(JSON.parse(localStorage.getItem("app-cache") || "[]")); @@ -104,3 +64,31 @@ function localStorageProvider(): Map<unknown, unknown> { } export default App; + +function getInitialBackendBaseURL(): string { + const overrideUrl = + typeof localStorage !== "undefined" + ? localStorage.getItem("bank-base-url") + : undefined; + let result: string; + if (!overrideUrl) { + //normal path + if (!bankUiSettings.backendBaseURL) { + console.error( + "ERROR: backendBaseURL was overridden by a setting file and missing. Setting value to 'window.origin'", + ); + result = window.origin + } else { + result = bankUiSettings.backendBaseURL; + } + } else { + // testing/development path + result = overrideUrl + } + try { + return canonicalizeBaseUrl(result) + } catch (e) { + //fall back + return canonicalizeBaseUrl(window.origin) + } +}
\ No newline at end of file |