diff options
author | Sebastian <sebasjm@gmail.com> | 2024-04-05 18:11:15 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-04-05 18:11:15 -0300 |
commit | b95cc1876b7263913a3a18df9234fd0122f25cf2 (patch) | |
tree | a349b631349aa342d705c6a4068eb91d0847be0b /packages/aml-backoffice-ui/src/hooks | |
parent | cc38998803141c42511e878441a5a8b15a387436 (diff) |
fix #8655
Diffstat (limited to 'packages/aml-backoffice-ui/src/hooks')
-rw-r--r-- | packages/aml-backoffice-ui/src/hooks/useBackend.ts | 72 |
1 files changed, 14 insertions, 58 deletions
diff --git a/packages/aml-backoffice-ui/src/hooks/useBackend.ts b/packages/aml-backoffice-ui/src/hooks/useBackend.ts index 0615c9c99..7b55568c8 100644 --- a/packages/aml-backoffice-ui/src/hooks/useBackend.ts +++ b/packages/aml-backoffice-ui/src/hooks/useBackend.ts @@ -1,65 +1,21 @@ -import { canonicalizeBaseUrl } from "@gnu-taler/taler-util"; -import { - HttpResponseOk, - RequestOptions, - useApiContext, -} from "@gnu-taler/web-util/browser"; -import { useCallback } from "preact/hooks"; -import { uiSettings } from "../settings.js"; +/* + This file is part of GNU Taler + (C) 2022 Taler Systems S.A. -interface useBackendType { - request: <T>( - path: string, - options?: RequestOptions, - ) => Promise<HttpResponseOk<T>>; - fetcher: <T>(args: [string, string]) => Promise<HttpResponseOk<T>>; - paginatedFetcher: <T>( - args: [string, number, number, string], - ) => Promise<HttpResponseOk<T>>; -} -export function usePublicBackend(): useBackendType { - const { request: requestHandler } = useApiContext(); + 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. - const baseUrl = getInitialBackendBaseURL(); + 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. - const request = useCallback( - function requestImpl<T>( - path: string, - options: RequestOptions = {}, - ): Promise<HttpResponseOk<T>> { - return requestHandler<T>(baseUrl, path, options); - }, - [baseUrl], - ); + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + import { canonicalizeBaseUrl } from "@gnu-taler/taler-util"; +import { uiSettings } from "../settings.js"; - const fetcher = useCallback( - function fetcherImpl<T>([endpoint, talerAmlOfficerSignature]: [string, string]): Promise<HttpResponseOk<T>> { - return requestHandler<T>(baseUrl, endpoint, { - talerAmlOfficerSignature - }); - }, - [baseUrl], - ); - const paginatedFetcher = useCallback( - function fetcherImpl<T>([endpoint, page, size, talerAmlOfficerSignature]: [ - string, - number, - number, - string, - ]): Promise<HttpResponseOk<T>> { - return requestHandler<T>(baseUrl, endpoint, { - params: { page: page || 1, size }, - talerAmlOfficerSignature, - }); - }, - [baseUrl], - ); - return { - request, - fetcher, - paginatedFetcher, - }; -} export function getInitialBackendBaseURL(): string { const overrideUrl = |