aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/wxBackend.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-webextension/src/wxBackend.ts')
-rw-r--r--packages/taler-wallet-webextension/src/wxBackend.ts43
1 files changed, 23 insertions, 20 deletions
diff --git a/packages/taler-wallet-webextension/src/wxBackend.ts b/packages/taler-wallet-webextension/src/wxBackend.ts
index 1601f7703..ab3c465c4 100644
--- a/packages/taler-wallet-webextension/src/wxBackend.ts
+++ b/packages/taler-wallet-webextension/src/wxBackend.ts
@@ -91,19 +91,15 @@ async function resetDb(): Promise<void> {
}
export type WalletActivityTrack = {
- id: number;
+ // id: number;
events: (WalletNotification & { when: AbsoluteTime })[];
start: AbsoluteTime;
type: NotificationType;
end: AbsoluteTime;
groupId: string;
+ requestId?: string; //only for request event
};
-let counter = 0;
-function getUniqueId(): number {
- return counter++;
-}
-
//FIXME: maybe circular buffer
const activity: WalletActivityTrack[] = [];
@@ -123,7 +119,6 @@ function convertWalletActivityNotification(
return undefined;
}
return {
- id: getUniqueId(),
type: event.type,
start: event.when,
end: AbsoluteTime.never(),
@@ -134,7 +129,6 @@ function convertWalletActivityNotification(
case NotificationType.BackupOperationError: {
const groupId = "";
return {
- id: getUniqueId(),
type: event.type,
start: event.when,
end: AbsoluteTime.never(),
@@ -151,7 +145,6 @@ function convertWalletActivityNotification(
return undefined;
}
return {
- id: getUniqueId(),
type: event.type,
start: event.when,
end: AbsoluteTime.never(),
@@ -171,7 +164,6 @@ function convertWalletActivityNotification(
return undefined;
}
return {
- id: getUniqueId(),
type: event.type,
start: event.when,
end: AbsoluteTime.never(),
@@ -182,7 +174,6 @@ function convertWalletActivityNotification(
case NotificationType.Idle: {
const groupId = "";
return {
- id: getUniqueId(),
type: event.type,
start: event.when,
end: AbsoluteTime.never(),
@@ -199,7 +190,6 @@ function convertWalletActivityNotification(
return undefined;
}
return {
- id: getUniqueId(),
type: event.type,
start: event.when,
end: AbsoluteTime.never(),
@@ -216,12 +206,12 @@ function convertWalletActivityNotification(
return undefined;
}
return {
- id: getUniqueId(),
type: event.type,
start: event.when,
end: AbsoluteTime.never(),
events: [event],
groupId,
+ requestId: event.requestId,
};
}
}
@@ -241,14 +231,24 @@ function addNewWalletActivityNotification(
async function getNotifications({
filter,
+ operationFrom,
}: {
filter: string;
+ operationFrom?: string;
}): Promise<WalletActivityTrack[]> {
- if (!filter) return activity;
-
const rg = new RegExp(`.*${filter}.*`);
return activity.filter((event) => {
- return rg.test(event.groupId.toLowerCase());
+ if (operationFrom) {
+ if (event.type !== NotificationType.RequestObservabilityEvent) {
+ return false;
+ }
+ if (event.requestId) {
+ return event.requestId.startsWith(operationFrom);
+ }
+ }
+ if (!filter) return true;
+ const testFilter = rg.test(event.groupId.toLowerCase());
+ return testFilter;
});
}
@@ -318,7 +318,10 @@ let nextMessageIndex = 0;
async function dispatch<
Op extends WalletOperations | BackgroundOperations | ExtensionOperations,
->(req: MessageFromFrontend<Op> & { id: string }): Promise<MessageResponse> {
+>(
+ req: MessageFromFrontend<Op> & { id: string },
+ from: string,
+): Promise<MessageResponse> {
nextMessageIndex = (nextMessageIndex + 1) % (Number.MAX_SAFE_INTEGER - 100);
switch (req.channel) {
@@ -402,7 +405,7 @@ async function dispatch<
};
}
//multiple client can create the same id, send the wallet an unique key
- const newId = `${req.id}_${nextMessageIndex}`;
+ const newId = `${from}:${req.id}`;
const resp = await w.handleCoreApiRequest(
req.operation,
newId,
@@ -516,10 +519,10 @@ export async function wxMain(): Promise<void> {
// Handlers for messages coming directly from the content
// script on the page
logger.trace("listen all channels");
- platform.listenToAllChannels(async (message) => {
+ platform.listenToAllChannels(async (message, from) => {
//wait until wallet is initialized
await afterWalletIsInitialized;
- const result = await dispatch(message);
+ const result = await dispatch(message, from);
return result;
});