taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 8e02b885e3a8f3a39577548e6bd0200a625c870e
parent 292d7bb92412ed106a80d484ebab1d46e2c8d2f1
Author: Sebastian <sebasjm@gmail.com>
Date:   Mon,  6 Jan 2025 19:45:04 -0300

also query /keys since it have some useful information and if it's no available then it means problems

Diffstat:
Mpackages/web-util/src/context/exchange-api.ts | 55+++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 39 insertions(+), 16 deletions(-)

diff --git a/packages/web-util/src/context/exchange-api.ts b/packages/web-util/src/context/exchange-api.ts @@ -22,7 +22,7 @@ import { TalerError, TalerExchangeApi, TalerExchangeCacheEviction, - TalerExchangeHttpClient + TalerExchangeHttpClient, } from "@gnu-taler/taler-util"; import { ComponentChildren, @@ -32,7 +32,11 @@ import { h, } from "preact"; import { useContext, useEffect, useState } from "preact/hooks"; -import { BrowserFetchHttpLib, ErrorLoading, useTranslationContext } from "../index.browser.js"; +import { + BrowserFetchHttpLib, + ErrorLoading, + useTranslationContext, +} from "../index.browser.js"; import { APIClient, ActiviyTracker, @@ -47,7 +51,7 @@ import { export type ExchangeContextType = { url: URL; - config: TalerExchangeApi.ExchangeVersionResponse; + config: KeysAndConfigType; lib: ExchangeLib; hints: VersionHint[]; onActivity: Subscriber<ObservabilityEvent>; @@ -80,6 +84,11 @@ type ConfigResultFail<T> = const CONFIG_FAIL_TRY_AGAIN_MS = 5000; +export type KeysAndConfigType = { + config: TalerExchangeApi.ExchangeVersionResponse; + keys: TalerExchangeApi.ExchangeKeysResponse; +}; + export const ExchangeApiProvider = ({ baseUrl, children, @@ -91,9 +100,8 @@ export const ExchangeApiProvider = ({ children: ComponentChildren; frameOnError: FunctionComponent<{ children: ComponentChildren }>; }): VNode => { - const [checked, setChecked] = - useState<ConfigResult<TalerExchangeApi.ExchangeVersionResponse>>(); - const { i18n } = useTranslationContext(); + const [checked, setChecked] = useState<ConfigResult<KeysAndConfigType>>(); + const { i18n } = useTranslationContext(); const { getRemoteConfig, VERSION, lib, cancelRequest, onActivity } = buildExchangeApiClient(baseUrl, evictors); @@ -103,7 +111,7 @@ export const ExchangeApiProvider = ({ async function testConfig(): Promise<void> { try { const config = await getRemoteConfig(); - if (LibtoolVersion.compare(VERSION, config.version)) { + if (LibtoolVersion.compare(VERSION, config.config.version)) { setChecked({ type: "ok", config, hints: [] }); } else { setChecked({ @@ -147,7 +155,7 @@ export const ExchangeApiProvider = ({ children: h( "div", {}, - i18n.str`The server version is not supported. Supported version "${checked.supported}", server version "${checked.result.version}"`, + i18n.str`The server version is not supported. Supported version "${checked.supported}", server version "${checked.result.config.version}"`, ), }); } @@ -169,7 +177,7 @@ export const ExchangeApiProvider = ({ function buildExchangeApiClient( url: URL, evictors: Evictors, -): APIClient<ExchangeLib, TalerExchangeApi.ExchangeVersionResponse> { +): APIClient<ExchangeLib, KeysAndConfigType> { const httpFetch = new BrowserFetchHttpLib({ enableThrottling: true, requireTls: false, @@ -184,16 +192,31 @@ function buildExchangeApiClient( const ex = new TalerExchangeHttpClient(url.href, httpLib, evictors.exchange); - async function getRemoteConfig(): Promise<TalerExchangeApi.ExchangeVersionResponse> { - const resp = await ex.getConfig(); - if (resp.type === "fail") { - if (resp.detail) { - throw TalerError.fromUncheckedDetail(resp.detail); + async function getRemoteConfig(): Promise<KeysAndConfigType> { + const configResp = await ex.getConfig(); + if (configResp.type === "fail") { + if (configResp.detail) { + throw TalerError.fromUncheckedDetail(configResp.detail); } else { - throw TalerError.fromException(new Error("failed to get exchange remote config")) + throw TalerError.fromException( + new Error("failed to get exchange remote config"), + ); } } - return resp.body; + const keysResp = await ex.getKeys(); + // if (keysResp.type === "fail") { + // if (keysResp.detail) { + // throw TalerError.fromUncheckedDetail(keysResp.detail); + // } else { + // throw TalerError.fromException( + // new Error("failed to get exchange remote config"), + // ); + // } + // } + return { + config: configResp.body, + keys: keysResp.body, + }; } return {