From a7c8f0f3edd738a59d719105cda3aa8821886b90 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 15 Apr 2024 12:01:16 -0300 Subject: fix #8604 --- packages/web-util/src/context/activity.ts | 2 +- packages/web-util/src/context/merchant-api.ts | 34 ++++++++++----------------- 2 files changed, 13 insertions(+), 23 deletions(-) (limited to 'packages/web-util/src') diff --git a/packages/web-util/src/context/activity.ts b/packages/web-util/src/context/activity.ts index 9a16f6673..422b25909 100644 --- a/packages/web-util/src/context/activity.ts +++ b/packages/web-util/src/context/activity.ts @@ -26,7 +26,7 @@ export class ActiviyTracker { this.notify = this.notify.bind(this) this.subscribe = this.subscribe.bind(this) } - notify(data: Event) { + notify(data: Event): void { this.observers.forEach((observer) => observer(data)) } subscribe(func: Listener): Unsuscriber { diff --git a/packages/web-util/src/context/merchant-api.ts b/packages/web-util/src/context/merchant-api.ts index 9998b3aeb..03c95d48e 100644 --- a/packages/web-util/src/context/merchant-api.ts +++ b/packages/web-util/src/context/merchant-api.ts @@ -69,7 +69,9 @@ enum VersionHint { } type Evictors = { - management?: CacheEvictor; + management?: CacheEvictor< + TalerMerchantManagementCacheEviction | TalerMerchantInstanceCacheEviction + >; }; type ConfigResult = @@ -81,7 +83,7 @@ export type ConfigResultFail = | { type: "incompatible"; result: T; supported: string } | { type: "error"; error: TalerError }; -const CONFIG_FAIL_TRY_AGAIN_MS = 5000 +const CONFIG_FAIL_TRY_AGAIN_MS = 5000; export const MerchantApiProvider = ({ baseUrl, @@ -108,7 +110,7 @@ export const MerchantApiProvider = ({ let keepRetrying = true; async function testConfig(): Promise { try { - const config = await getRemoteConfig(); + const config = await getRemoteConfig(); if (LibtoolVersion.compare(VERSION, config.version)) { setChecked({ type: "ok", config, hints: [] }); } else { @@ -122,7 +124,7 @@ export const MerchantApiProvider = ({ if (error instanceof TalerError) { if (keepRetrying) { setTimeout(() => { - testConfig() + testConfig(); }, CONFIG_FAIL_TRY_AGAIN_MS); } setChecked({ type: "error", error }); @@ -135,7 +137,7 @@ export const MerchantApiProvider = ({ return () => { // on unload, stop retry keepRetrying = false; - } + }; }, []); if (!checked || checked.type !== "ok") { @@ -183,30 +185,18 @@ function buildMerchantApiClient( httpLib, ); - // const instance = (instanceId: string): TalerMerchantInstanceHttpClient => { - // return new TalerMerchantInstanceHttpClient( - // management.getSubInstanceAPI(instanceId).href, - // httpLib, - // evictors.instance ? evictors.instance(instanceId) : undefined, - // ); - // } - // const impersonate = (instanceId: string): TalerAuthenticationHttpClient => { - // return new TalerAuthenticationHttpClient( - // instance(instanceId).getAuthenticationAPI().href, - // httpLib, - // ); - // } - const rootUrl = url; function getSubInstanceAPI(instanceId: string): MerchantLib { - const newURL = new URL(`instance/${instanceId}/`, rootUrl); - const api = buildMerchantApiClient(newURL, evictors); + const api = buildMerchantApiClient( + instance.getSubInstanceAPI(instanceId) as URL, + evictors, + ); return api.lib; } async function getRemoteConfig(): Promise { const resp = await instance.getConfig(); if (resp.type === "fail") { - throw TalerError.fromUncheckedDetail(resp.detail) + throw TalerError.fromUncheckedDetail(resp.detail); } return resp.body; } -- cgit v1.2.3