gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] 02/04: also query /keys since it have some useful in


From: gnunet
Subject: [taler-wallet-core] 02/04: also query /keys since it have some useful information and if it's no available then it means problems
Date: Mon, 06 Jan 2025 23:56:59 +0100

This is an automated email from the git hooks/post-receive script.

sebasjm pushed a commit to branch master
in repository wallet-core.

commit 8e02b885e3a8f3a39577548e6bd0200a625c870e
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Mon Jan 6 19:45:04 2025 -0300

    also query /keys since it have some useful information and if it's no 
available then it means problems
---
 packages/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
index 967b042f9..eefdd481d 100644
--- 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 {

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]