diff options
author | Sebastian <sebasjm@gmail.com> | 2024-03-01 10:50:17 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-03-01 10:50:17 -0300 |
commit | 1facde4ab16c8d943f16f7cb0ded8dc9104dacfd (patch) | |
tree | 14ee630a7e569779525b4e7a1c12a2fc650d41b4 /packages/taler-wallet-webextension | |
parent | d09c50bdb1f5eadc7aa64f38aedd07eb5beea039 (diff) | |
download | wallet-core-1facde4ab16c8d943f16f7cb0ded8dc9104dacfd.tar.xz |
send a new request id to wallet instead of client request id
Diffstat (limited to 'packages/taler-wallet-webextension')
4 files changed, 26 insertions, 29 deletions
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, |