aboutsummaryrefslogtreecommitdiff
path: root/packages/web-util/src/context
diff options
context:
space:
mode:
Diffstat (limited to 'packages/web-util/src/context')
-rw-r--r--packages/web-util/src/context/api.ts15
-rw-r--r--packages/web-util/src/context/bank-api.ts18
-rw-r--r--packages/web-util/src/context/challenger-api.ts6
-rw-r--r--packages/web-util/src/context/exchange-api.ts6
-rw-r--r--packages/web-util/src/context/merchant-api.ts18
-rw-r--r--packages/web-util/src/context/navigation.ts3
-rw-r--r--packages/web-util/src/context/translation.ts2
7 files changed, 46 insertions, 22 deletions
diff --git a/packages/web-util/src/context/api.ts b/packages/web-util/src/context/api.ts
index c1eaa37f8..89561e239 100644
--- a/packages/web-util/src/context/api.ts
+++ b/packages/web-util/src/context/api.ts
@@ -19,7 +19,12 @@
* @author Sebastian Javier Marchano (sebasjm)
*/
-import { TalerBankIntegrationHttpClient, TalerCoreBankHttpClient, TalerRevenueHttpClient, TalerWireGatewayHttpClient } from "@gnu-taler/taler-util";
+import {
+ TalerBankIntegrationHttpClient,
+ TalerCoreBankHttpClient,
+ TalerRevenueHttpClient,
+ TalerWireGatewayHttpClient,
+} from "@gnu-taler/taler-util";
import { ComponentChildren, createContext, h, VNode } from "preact";
import { useContext } from "preact/hooks";
import { defaultRequestHandler } from "../utils/request.js";
@@ -29,10 +34,10 @@ interface Type {
* @deprecated this show not be used
*/
request: typeof defaultRequestHandler;
- bankCore: TalerCoreBankHttpClient,
- bankIntegration: TalerBankIntegrationHttpClient,
- bankWire: TalerWireGatewayHttpClient,
- bankRevenue: TalerRevenueHttpClient,
+ bankCore: TalerCoreBankHttpClient;
+ bankIntegration: TalerBankIntegrationHttpClient;
+ bankWire: TalerWireGatewayHttpClient;
+ bankRevenue: TalerRevenueHttpClient;
}
const Context = createContext<Type>({ request: defaultRequestHandler } as any);
diff --git a/packages/web-util/src/context/bank-api.ts b/packages/web-util/src/context/bank-api.ts
index 3f6a32f4b..e610b49e0 100644
--- a/packages/web-util/src/context/bank-api.ts
+++ b/packages/web-util/src/context/bank-api.ts
@@ -16,6 +16,7 @@
import {
CacheEvictor,
+ TalerCorebankConfigResponse,
LibtoolVersion,
ObservabilityEvent,
ObservableHttpClientLibrary,
@@ -24,7 +25,6 @@ import {
TalerBankConversionHttpClient,
TalerCoreBankCacheEviction,
TalerCoreBankHttpClient,
- TalerCorebankApi,
TalerError,
} from "@gnu-taler/taler-util";
import {
@@ -35,9 +35,9 @@ import {
h,
} from "preact";
import { useContext, useEffect, useState } from "preact/hooks";
+import { BrowserFetchHttpLib, ErrorLoading } from "../index.browser.js";
import { APIClient, ActiviyTracker, BankLib, Subscriber } from "./activity.js";
import { useTranslationContext } from "./translation.js";
-import { BrowserFetchHttpLib, ErrorLoading } from "../index.browser.js";
/**
*
@@ -46,7 +46,7 @@ import { BrowserFetchHttpLib, ErrorLoading } from "../index.browser.js";
export type BankContextType = {
url: URL;
- config: TalerCorebankApi.Config;
+ config: TalerCorebankConfigResponse;
lib: BankLib;
hints: VersionHint[];
onActivity: Subscriber<ObservabilityEvent>;
@@ -88,7 +88,7 @@ export const BankApiProvider = ({
frameOnError: FunctionComponent<{ children: ComponentChildren }>;
}): VNode => {
const [checked, setChecked] =
- useState<ConfigResult<TalerCorebankApi.Config>>();
+ useState<ConfigResult<TalerCorebankConfigResponse>>();
const { i18n } = useTranslationContext();
const { getRemoteConfig, VERSION, lib, cancelRequest, onActivity } =
@@ -165,7 +165,7 @@ export const BankApiProvider = ({
function buildBankApiClient(
url: URL,
evictors: Evictors,
-): APIClient<BankLib, TalerCorebankApi.Config> {
+): APIClient<BankLib, TalerCorebankConfigResponse> {
const httpFetch = new BrowserFetchHttpLib({
enableThrottling: true,
requireTls: false,
@@ -189,10 +189,14 @@ function buildBankApiClient(
httpLib,
);
- async function getRemoteConfig(): Promise<TalerCorebankApi.Config> {
+ async function getRemoteConfig(): Promise<TalerCorebankConfigResponse> {
const resp = await bank.getConfig();
if (resp.type === "fail") {
- throw TalerError.fromUncheckedDetail(resp.detail);
+ if (resp.detail) {
+ throw TalerError.fromUncheckedDetail(resp.detail);
+ } else {
+ throw TalerError.fromException(new Error("failed to get bank remote config"))
+ }
}
return resp.body;
}
diff --git a/packages/web-util/src/context/challenger-api.ts b/packages/web-util/src/context/challenger-api.ts
index 8748f5f69..e2a6e05c3 100644
--- a/packages/web-util/src/context/challenger-api.ts
+++ b/packages/web-util/src/context/challenger-api.ts
@@ -183,7 +183,11 @@ function buildChallengerApiClient(
async function getRemoteConfig(): Promise<ChallengerApi.ChallengerTermsOfServiceResponse> {
const resp = await challenger.getConfig();
if (resp.type === "fail") {
- throw TalerError.fromUncheckedDetail(resp.detail);
+ if (resp.detail) {
+ throw TalerError.fromUncheckedDetail(resp.detail);
+ } else {
+ throw TalerError.fromException(new Error("failed to get challenger remote config"))
+ }
}
return resp.body;
}
diff --git a/packages/web-util/src/context/exchange-api.ts b/packages/web-util/src/context/exchange-api.ts
index 39f889ba9..967b042f9 100644
--- a/packages/web-util/src/context/exchange-api.ts
+++ b/packages/web-util/src/context/exchange-api.ts
@@ -187,7 +187,11 @@ function buildExchangeApiClient(
async function getRemoteConfig(): Promise<TalerExchangeApi.ExchangeVersionResponse> {
const resp = await ex.getConfig();
if (resp.type === "fail") {
- throw TalerError.fromUncheckedDetail(resp.detail);
+ if (resp.detail) {
+ throw TalerError.fromUncheckedDetail(resp.detail);
+ } else {
+ throw TalerError.fromException(new Error("failed to get exchange remote config"))
+ }
}
return resp.body;
}
diff --git a/packages/web-util/src/context/merchant-api.ts b/packages/web-util/src/context/merchant-api.ts
index 03c95d48e..8d929ae12 100644
--- a/packages/web-util/src/context/merchant-api.ts
+++ b/packages/web-util/src/context/merchant-api.ts
@@ -49,7 +49,7 @@ import {
export type MerchantContextType = {
url: URL;
- config: TalerMerchantApi.VersionResponse;
+ config: TalerMerchantApi.TalerMerchantConfigResponse;
lib: MerchantLib;
hints: VersionHint[];
onActivity: Subscriber<ObservabilityEvent>;
@@ -95,11 +95,13 @@ export const MerchantApiProvider = ({
evictors?: Evictors;
children: ComponentChildren;
frameOnError: FunctionComponent<{
- state: ConfigResultFail<TalerMerchantApi.VersionResponse> | undefined;
+ state:
+ | ConfigResultFail<TalerMerchantApi.TalerMerchantConfigResponse>
+ | undefined;
}>;
}): VNode => {
const [checked, setChecked] =
- useState<ConfigResult<TalerMerchantApi.VersionResponse>>();
+ useState<ConfigResult<TalerMerchantApi.TalerMerchantConfigResponse>>();
const [merchantEndpoint, changeMerchantEndpoint] = useState(baseUrl);
@@ -162,7 +164,7 @@ export const MerchantApiProvider = ({
function buildMerchantApiClient(
url: URL,
evictors: Evictors,
-): APIClient<MerchantLib, TalerMerchantApi.VersionResponse> {
+): APIClient<MerchantLib, TalerMerchantApi.TalerMerchantConfigResponse> {
const httpFetch = new BrowserFetchHttpLib({
enableThrottling: true,
requireTls: false,
@@ -193,10 +195,14 @@ function buildMerchantApiClient(
return api.lib;
}
- async function getRemoteConfig(): Promise<TalerMerchantApi.VersionResponse> {
+ async function getRemoteConfig(): Promise<TalerMerchantApi.TalerMerchantConfigResponse> {
const resp = await instance.getConfig();
if (resp.type === "fail") {
- throw TalerError.fromUncheckedDetail(resp.detail);
+ if (resp.detail) {
+ throw TalerError.fromUncheckedDetail(resp.detail);
+ } else {
+ throw TalerError.fromException(new Error("failed to get merchant remote config"))
+ }
}
return resp.body;
}
diff --git a/packages/web-util/src/context/navigation.ts b/packages/web-util/src/context/navigation.ts
index c2f2bbbc1..bd756318b 100644
--- a/packages/web-util/src/context/navigation.ts
+++ b/packages/web-util/src/context/navigation.ts
@@ -22,6 +22,7 @@ import {
Location,
findMatch,
RouteDefinition,
+ LocationNotFound,
} from "../utils/route.js";
/**
@@ -44,7 +45,7 @@ export const useNavigationContext = (): Type => useContext(Context);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function useCurrentLocation<T extends ObjectOf<RouteDefinition<any>>>(
pagesMap: T,
-): Location<T> | undefined {
+): Location<T> | LocationNotFound<T> {
const pageList = Object.keys(pagesMap as object) as Array<keyof T>;
const { path, params } = useNavigationContext();
diff --git a/packages/web-util/src/context/translation.ts b/packages/web-util/src/context/translation.ts
index 2725dc7e1..3e3ad2d13 100644
--- a/packages/web-util/src/context/translation.ts
+++ b/packages/web-util/src/context/translation.ts
@@ -95,7 +95,7 @@ export const TranslationProvider = ({
if (forceLang) {
changeLanguage(forceLang);
}
- });
+ },[forceLang]);
useEffect(() => {
setupI18n(lang, source);
}, [lang]);