diff options
author | Sebastian <sebasjm@gmail.com> | 2024-03-27 01:05:10 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-03-27 01:05:10 -0300 |
commit | 237c4e8adae997e84f5fb7a8fe5c03b1148e99dc (patch) | |
tree | 26ec2b1a82e730af080aae4625b736aaa77dfec7 /packages/merchant-backoffice-ui/src/Application.tsx | |
parent | ecb8c2078ebe94d81a6e03ebfe01ecdde53109e2 (diff) | |
download | wallet-core-237c4e8adae997e84f5fb7a8fe5c03b1148e99dc.tar.xz |
wip #8655
Diffstat (limited to 'packages/merchant-backoffice-ui/src/Application.tsx')
-rw-r--r-- | packages/merchant-backoffice-ui/src/Application.tsx | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/packages/merchant-backoffice-ui/src/Application.tsx b/packages/merchant-backoffice-ui/src/Application.tsx index d752d612d..497f49c0e 100644 --- a/packages/merchant-backoffice-ui/src/Application.tsx +++ b/packages/merchant-backoffice-ui/src/Application.tsx @@ -19,12 +19,14 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { canonicalizeBaseUrl } from "@gnu-taler/taler-util"; +import { TalerMerchantApi, assertUnreachable, canonicalizeBaseUrl } from "@gnu-taler/taler-util"; import { BrowserHashNavigationProvider, + ConfigResultFail, MerchantApiProvider, TalerWalletIntegrationBrowserProvider, - TranslationProvider + TranslationProvider, + useTranslationContext } from "@gnu-taler/web-util/browser"; import { VNode, h } from "preact"; import { useEffect, useState } from "preact/hooks"; @@ -34,8 +36,10 @@ import { Loading } from "./components/exception/loading.js"; import { SettingsProvider } from "./context/settings.js"; import { strings } from "./i18n/strings.js"; import { MerchantUiSettings, buildDefaultBackendBaseURL, fetchSettings } from "./settings.js"; +import { NotificationCard } from "./components/menu/index.js"; const WITH_LOCAL_STORAGE_CACHE = false; + export function Application(): VNode { const [settings, setSettings] = useState<MerchantUiSettings>(); useEffect(() => { @@ -53,7 +57,7 @@ export function Application(): VNode { de: strings["de"].completeness, }} > - <MerchantApiProvider baseUrl={new URL("/", baseUrl)} frameOnError={({ children }) => <div>{children}</div>}> + <MerchantApiProvider baseUrl={new URL("/", baseUrl)} frameOnError={OnConfigError}> <SWRConfig value={{ provider: WITH_LOCAL_STORAGE_CACHE @@ -136,3 +140,32 @@ function localStorageProvider(): Map<unknown, unknown> { }); return map; } + +function OnConfigError({ state }: { state: ConfigResultFail<TalerMerchantApi.VersionResponse> | undefined }): VNode { + const { i18n } = useTranslationContext(); + if (!state) { + return <i18n.Translate>checking compatibility with server...</i18n.Translate> + } + switch (state.type) { + case "error": { + return <NotificationCard + notification={{ + message: i18n.str`Contacting the server failed`, + description: state.error.message, + details: JSON.stringify(state.error.errorDetail, undefined, 2), + type: "ERROR", + }} + /> + } + case "incompatible": { + return <NotificationCard + notification={{ + message: i18n.str`The server version is not supported`, + description: i18n.str`Supported version "${state.supported}", server version "${state.result.version}".`, + type: "WARN", + }} + /> + } + default: assertUnreachable(state) + } +} |