gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] 02/02: fix #7924


From: gnunet
Subject: [taler-wallet-core] 02/02: fix #7924
Date: Fri, 05 Apr 2024 15:42:49 +0200

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

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

commit 89dde053665d39be8367c25691efc008fc2a5cc7
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Fri Apr 5 10:42:41 2024 -0300

    fix #7924
---
 packages/web-util/src/context/bank-api.ts     | 26 +++++++++++++++++++++-----
 packages/web-util/src/context/merchant-api.ts | 26 +++++++++++++++++++++-----
 2 files changed, 42 insertions(+), 10 deletions(-)

diff --git a/packages/web-util/src/context/bank-api.ts 
b/packages/web-util/src/context/bank-api.ts
index d2938f150..3f6a32f4b 100644
--- a/packages/web-util/src/context/bank-api.ts
+++ b/packages/web-util/src/context/bank-api.ts
@@ -74,6 +74,8 @@ type ConfigResult<T> =
   | { type: "incompatible"; result: T; supported: string }
   | { type: "error"; error: TalerError };
 
+const CONFIG_FAIL_TRY_AGAIN_MS = 5000;
+
 export const BankApiProvider = ({
   baseUrl,
   children,
@@ -93,8 +95,10 @@ export const BankApiProvider = ({
     buildBankApiClient(baseUrl, evictors);
 
   useEffect(() => {
-    getRemoteConfig()
-      .then((config) => {
+    let keepRetrying = true;
+    async function testConfig(): Promise<void> {
+      try {
+        const config = await getRemoteConfig();
         if (LibtoolVersion.compare(VERSION, config.version)) {
           setChecked({ type: "ok", config, hints: [] });
         } else {
@@ -104,12 +108,24 @@ export const BankApiProvider = ({
             supported: VERSION,
           });
         }
-      })
-      .catch((error: unknown) => {
+      } catch (error) {
         if (error instanceof TalerError) {
+          if (keepRetrying) {
+            setTimeout(() => {
+              testConfig();
+            }, CONFIG_FAIL_TRY_AGAIN_MS);
+          }
           setChecked({ type: "error", error });
+        } else {
+          setChecked({ type: "error", error: TalerError.fromException(error) 
});
         }
-      });
+      }
+    }
+    testConfig();
+    return () => {
+      // on unload, stop retry
+      keepRetrying = false;
+    };
   }, []);
 
   if (checked === undefined) {
diff --git a/packages/web-util/src/context/merchant-api.ts 
b/packages/web-util/src/context/merchant-api.ts
index 604119e84..9998b3aeb 100644
--- a/packages/web-util/src/context/merchant-api.ts
+++ b/packages/web-util/src/context/merchant-api.ts
@@ -81,6 +81,8 @@ export type ConfigResultFail<T> =
   | { type: "incompatible"; result: T; supported: string }
   | { type: "error"; error: TalerError };
 
+const CONFIG_FAIL_TRY_AGAIN_MS = 5000
+
 export const MerchantApiProvider = ({
   baseUrl,
   children,
@@ -103,8 +105,10 @@ export const MerchantApiProvider = ({
     buildMerchantApiClient(merchantEndpoint, evictors);
 
   useEffect(() => {
-    getRemoteConfig()
-      .then((config) => {
+    let keepRetrying = true;
+    async function testConfig(): Promise<void> {
+      try {
+        const config = await getRemoteConfig();  
         if (LibtoolVersion.compare(VERSION, config.version)) {
           setChecked({ type: "ok", config, hints: [] });
         } else {
@@ -114,12 +118,24 @@ export const MerchantApiProvider = ({
             supported: VERSION,
           });
         }
-      })
-      .catch((error: unknown) => {
+      } catch (error) {
         if (error instanceof TalerError) {
+          if (keepRetrying) {
+            setTimeout(() => {
+              testConfig()
+            }, CONFIG_FAIL_TRY_AGAIN_MS);
+          }
           setChecked({ type: "error", error });
+        } else {
+          setChecked({ type: "error", error: TalerError.fromException(error) 
});
         }
-      });
+      }
+    }
+    testConfig();
+    return () => {
+      // on unload, stop retry
+      keepRetrying = false;
+    }
   }, []);
 
   if (!checked || checked.type !== "ok") {

-- 
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]