diff options
Diffstat (limited to 'packages/demobank-ui/src/pages/HomePage.tsx')
-rw-r--r-- | packages/demobank-ui/src/pages/HomePage.tsx | 78 |
1 files changed, 3 insertions, 75 deletions
diff --git a/packages/demobank-ui/src/pages/HomePage.tsx b/packages/demobank-ui/src/pages/HomePage.tsx index 95144f086..bd85cea1e 100644 --- a/packages/demobank-ui/src/pages/HomePage.tsx +++ b/packages/demobank-ui/src/pages/HomePage.tsx @@ -31,12 +31,11 @@ import { } from "@gnu-taler/web-util/browser"; import { Fragment, VNode, h } from "preact"; import { Loading } from "../components/Loading.js"; -import { getInitialBackendBaseURL } from "../hooks/backend.js"; +import { useBankCoreApiContext } from "../context/config.js"; import { useSettings } from "../hooks/settings.js"; import { AccountPage } from "./AccountPage/index.js"; import { LoginForm } from "./LoginForm.js"; import { WithdrawalQRCode } from "./WithdrawalQRCode.js"; -import { route } from "preact-router"; const logger = new Logger("AccountPage"); @@ -68,7 +67,6 @@ export function HomePage({ account={account} goToConfirmOperation={goToConfirmOperation} goToBusinessAccount={goToBusinessAccount} - onLoadNotOk={handleNotOkResult(i18n)} /> ); } @@ -82,9 +80,9 @@ export function WithdrawalOperationPage({ }): VNode { //FIXME: libeufin sandbox should return show to create the integration api endpoint //or return withdrawal uri from response - const baseUrl = getInitialBackendBaseURL() + const { api } = useBankCoreApiContext() const uri = stringifyWithdrawUri({ - bankIntegrationApiBaseUrl: `${baseUrl}/taler-integration`, + bankIntegrationApiBaseUrl: api.getIntegrationAPI().baseUrl, withdrawalOperationId: operationId, }); const parsedUri = parseWithdrawUri(uri); @@ -110,76 +108,6 @@ export function WithdrawalOperationPage({ ); } -export function handleNotOkResult( - i18n: ReturnType<typeof useTranslationContext>["i18n"], -): <T>( - result: - | HttpResponsePaginated<T, SandboxBackend.SandboxError> - | HttpResponse<T, SandboxBackend.SandboxError>, -) => VNode { - return function handleNotOkResult2<T>( - result: - | HttpResponsePaginated<T, SandboxBackend.SandboxError | undefined> - | HttpResponse<T, SandboxBackend.SandboxError | undefined>, - ): VNode { - if (result.loading) return <Loading />; - if (!result.ok) { - switch (result.type) { - case ErrorType.TIMEOUT: { - notifyError(i18n.str`Request timeout, try again later.`, undefined); - break; - } - case ErrorType.CLIENT: { - if (result.status === HttpStatusCode.Unauthorized) { - notifyError(i18n.str`Wrong credentials`, undefined); - return <LoginForm />; - } - const errorData = result.payload; - notify({ - type: "error", - title: i18n.str`Could not load due to a request error`, - description: i18n.str`Request to url "${result.info.url}" returned ${result.info.status}`, - debug: JSON.stringify(result), - }); - break; - } - case ErrorType.SERVER: { - notify({ - type: "error", - title: i18n.str`Server returned with error`, - description: result.payload?.error?.description as TranslatedString, - debug: JSON.stringify(result.payload), - }); - break; - } - case ErrorType.UNREADABLE: { - notify({ - type: "error", - title: i18n.str`Unexpected error.`, - description: i18n.str`Response from ${result.info?.url} is unreadable, http status: ${result.status}`, - debug: JSON.stringify(result), - }); - break; - } - case ErrorType.UNEXPECTED: { - notify({ - type: "error", - title: i18n.str`Unexpected error.`, - description: i18n.str`Diagnostic from ${result.info?.url} is "${result.message}"`, - debug: JSON.stringify(result), - }); - break; - } - default: { - assertUnreachable(result); - } - } - // route("/") - return <div>error</div>; - } - return <div />; - }; -} export function assertUnreachable(x: never): never { throw new Error("Didn't expect to get here"); } |