gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] 02/02: send a new request id to wallet instead of cl


From: gnunet
Subject: [taler-wallet-core] 02/02: send a new request id to wallet instead of client request id
Date: Fri, 01 Mar 2024 15:51:01 +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 1facde4ab16c8d943f16f7cb0ded8dc9104dacfd
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Fri Mar 1 10:50:17 2024 -0300

    send a new request id to wallet instead of client request id
---
 packages/taler-wallet-core/src/wallet.ts           |  5 +--
 .../src/components/WalletActivity.tsx              | 37 ++++++++--------------
 .../src/platform/chrome.ts                         |  3 +-
 .../src/wallet/Settings.tsx                        |  2 +-
 .../taler-wallet-webextension/src/wxBackend.ts     | 13 ++++++--
 5 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/packages/taler-wallet-core/src/wallet.ts 
b/packages/taler-wallet-core/src/wallet.ts
index 879508036..28d54fde3 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -530,13 +530,14 @@ async function dumpCoins(wex: WalletExecutionContext): 
Promise<CoinDumpJson> {
 /**
  * Get an API client from an internal wallet state object.
  */
+let id = 0;
 async function getClientFromWalletState(
   ws: InternalWalletState,
 ): Promise<WalletCoreApiClient> {
-  let id = 0;
   const client: WalletCoreApiClient = {
     async call(op, payload): Promise<any> {
-      const res = await handleCoreApiRequest(ws, op, `${id++}`, payload);
+      id = (id + 1) % (Number.MAX_SAFE_INTEGER - 100);
+      const res = await handleCoreApiRequest(ws, op, String(id), payload);
       switch (res.type) {
         case "error":
           throw TalerError.fromUncheckedDetail(res.error);
diff --git 
a/packages/taler-wallet-webextension/src/components/WalletActivity.tsx 
b/packages/taler-wallet-webextension/src/components/WalletActivity.tsx
index a370e859d..1dde08010 100644
--- a/packages/taler-wallet-webextension/src/components/WalletActivity.tsx
+++ b/packages/taler-wallet-webextension/src/components/WalletActivity.tsx
@@ -86,7 +86,7 @@ export function WalletActivity({ }: Props): VNode {
       {(function (): VNode {
         switch (table) {
           case "events": {
-            return <ObservavilityEventsTable />
+            return <ObservabilityEventsTable />
           }
           case "tasks": {
             return <ActiveTasksTable />
@@ -614,42 +614,32 @@ function getNotificationFor(id: string, event: 
WalletNotification, start: Absolu
   }
 }
 
-let lastTimeout: ReturnType<typeof setTimeout>;
-export function ObservavilityEventsTable({ }: {}): VNode {
+export function ObservabilityEventsTable({ }: {}): VNode {
   const { i18n } = useTranslationContext()
   const api = useBackendContext();
 
   const [notifications, setNotifications] = useState<Notif[]>([])
+  const [showDetails, setShowDetails] = useState<VNode>()
 
   useEffect(() => {
-    //initial call
-    api.background.call("getNotifications", undefined).then(notif => {
-      const list: Notif[] = []
-      for (const pepe of notif) {
-        const event = getNotificationFor(String(list.length), 
pepe.notification, pepe.when, list)
-        // pepe.
-        if (event) {
-          list.push(event)
-        }
-      }
-    setNotifications(list);
-    })
-
+    let lastTimeout: ReturnType<typeof setTimeout>;
     function periodicRefresh() {
-      lastTimeout = setTimeout(async () => {
-
-        const notif = await api.background.call("getNotifications", undefined);
+      api.background.call("getNotifications", undefined).then(notif => {
 
         const list: Notif[] = []
         for (const pepe of notif) {
           const event = getNotificationFor(String(list.length), 
pepe.notification, pepe.when, list)
           // pepe.
           if (event) {
-            list.push(event)
+            list.unshift(event)
           }
         }
-
         setNotifications(list);
+      }).catch(error => {
+        console.log(error)
+      })
+
+      lastTimeout = setTimeout(() => {
         periodicRefresh();
       }, 1000)
 
@@ -657,9 +647,8 @@ export function ObservavilityEventsTable({ }: {}): VNode {
       return () => { clearTimeout(lastTimeout) }
     }
     return periodicRefresh()
-  });
+  }, [1]);
 
-  const [showDetails, setShowDetails] = useState<VNode>()
   return <div>
     <div style={{ display: "flex", justifyContent: "space-between" }}>
 
@@ -732,7 +721,7 @@ export function ActiveTasksTable({ }: {}): VNode {
   );
   const [showError, setShowError] = useState<TalerErrorDetail>()
   const tasks = state && !state.hasError ? state.response.tasks : [];
-  
+
   // const listenAllEvents = Array.from<NotificationType>({ length: 1 });
   // listenAllEvents.includes = () => true
   // useEffect(() => {
diff --git a/packages/taler-wallet-webextension/src/platform/chrome.ts 
b/packages/taler-wallet-webextension/src/platform/chrome.ts
index fc2d1db09..68b065853 100644
--- a/packages/taler-wallet-webextension/src/platform/chrome.ts
+++ b/packages/taler-wallet-webextension/src/platform/chrome.ts
@@ -281,7 +281,8 @@ let nextMessageIndex = 0;
 async function sendMessageToBackground<
   Op extends WalletOperations | BackgroundOperations,
 >(message: MessageFromFrontend<Op>): Promise<MessageResponse> {
-  const messageWithId = { ...message, id: `id_${nextMessageIndex++ % 1000}` };
+  nextMessageIndex = (nextMessageIndex + 1) % (Number.MAX_SAFE_INTEGER - 100);
+  const messageWithId = { ...message, id: `id_${nextMessageIndex}` };
 
   return new Promise<any>((resolve, reject) => {
     logger.trace("send operation to the wallet background", message);
diff --git a/packages/taler-wallet-webextension/src/wallet/Settings.tsx 
b/packages/taler-wallet-webextension/src/wallet/Settings.tsx
index b704b585e..e35e6d241 100644
--- a/packages/taler-wallet-webextension/src/wallet/Settings.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/Settings.tsx
@@ -272,7 +272,7 @@ function AdvanceSettings(): VNode {
     },
     showWalletActivity: {
       label: i18n.str`Show wallet activity`,
-      description: i18n.str`Show the wallet notification and observavility 
event in the UI.`,
+      description: i18n.str`Show the wallet notification and observability 
event in the UI.`,
     },
   };
   return (
diff --git a/packages/taler-wallet-webextension/src/wxBackend.ts 
b/packages/taler-wallet-webextension/src/wxBackend.ts
index 2f48a6611..7c090b28b 100644
--- a/packages/taler-wallet-webextension/src/wxBackend.ts
+++ b/packages/taler-wallet-webextension/src/wxBackend.ts
@@ -155,10 +155,13 @@ async function setLoggingLevel({
     setLogLevelFromString(tag, level);
   }
 }
+let nextMessageIndex = 0;
 
 async function dispatch<
   Op extends WalletOperations | BackgroundOperations | ExtensionOperations,
 >(req: MessageFromFrontend<Op> & { id: string }): Promise<MessageResponse> {
+  nextMessageIndex = (nextMessageIndex + 1) % (Number.MAX_SAFE_INTEGER - 100);
+
   switch (req.channel) {
     case "background": {
       const handler = backendHandlers[req.operation] as (req: any) => any;
@@ -232,8 +235,12 @@ async function dispatch<
           ),
         };
       }
-
-      return await w.handleCoreApiRequest(req.operation, req.id, req.payload);
+      //multiple client can create the same id, send the wallet an unique key
+      const newId = `${req.id}_${nextMessageIndex}`
+      const resp = await w.handleCoreApiRequest(req.operation, newId, 
req.payload);
+      //return to the client the original id
+      resp.id = req.id
+      return resp
     }
   }
 
@@ -314,7 +321,7 @@ async function reinitWallet(): Promise<void> {
         when: AbsoluteTime.now()
       })
     }
-  
+
     platform.sendMessageToAllChannels({
       type: "wallet",
       notification: message,

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