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.ts150
1 files changed, 79 insertions, 71 deletions
diff --git a/packages/taler-wallet-webextension/src/wxBackend.ts b/packages/taler-wallet-webextension/src/wxBackend.ts
index 5fa255f5d..a0b9f2908 100644
--- a/packages/taler-wallet-webextension/src/wxBackend.ts
+++ b/packages/taler-wallet-webextension/src/wxBackend.ts
@@ -39,7 +39,7 @@ import {
makeErrorDetail,
openPromise,
setGlobalLogLevelFromString,
- setLogLevelFromString
+ setLogLevelFromString,
} from "@gnu-taler/taler-util";
import { HttpRequestLibrary } from "@gnu-taler/taler-util/http";
import {
@@ -92,7 +92,7 @@ async function resetDb(): Promise<void> {
export type WalletActivityTrack = {
id: number;
- events: (WalletNotification & {when: AbsoluteTime})[];
+ events: (WalletNotification & { when: AbsoluteTime })[];
start: AbsoluteTime;
type: NotificationType;
end: AbsoluteTime;
@@ -107,130 +107,138 @@ function getUniqueId(): number {
//FIXME: maybe circular buffer
const activity: WalletActivityTrack[] = [];
-function addNewWalletActivityNotification(list: WalletActivityTrack[], n: WalletNotification) {
- const start = AbsoluteTime.now();
- const ev = {...n, when:start};
- switch (n.type) {
+function convertWalletActivityNotification(
+ knownEvents: WalletActivityTrack[],
+ event: WalletNotification & {
+ when: AbsoluteTime;
+ },
+): WalletActivityTrack | undefined {
+ switch (event.type) {
case NotificationType.BalanceChange: {
- const groupId = `${n.type}:${n.hintTransactionId}`;
- const found = list.find((a)=>a.groupId === groupId)
+ const groupId = `${event.type}:${event.hintTransactionId}`;
+ const found = knownEvents.find((a) => a.groupId === groupId);
if (found) {
- found.end = start;
- found.events.unshift(ev)
- return;
+ found.end = event.when;
+ found.events.unshift(event);
+ return found;
}
- list.push({
+ return {
id: getUniqueId(),
- type: n.type,
- start,
+ type: event.type,
+ start: event.when,
end: AbsoluteTime.never(),
- events: [ev],
+ events: [event],
groupId,
- });
- return;
+ };
}
case NotificationType.BackupOperationError: {
const groupId = "";
- list.push({
+ return {
id: getUniqueId(),
- type: n.type,
- start,
+ type: event.type,
+ start: event.when,
end: AbsoluteTime.never(),
- events: [ev],
+ events: [event],
groupId,
- });
- return;
+ };
}
case NotificationType.TransactionStateTransition: {
- const groupId = `${n.type}:${n.transactionId}`;
- const found = list.find((a)=>a.groupId === groupId)
+ const groupId = `${event.type}:${event.transactionId}`;
+ const found = knownEvents.find((a) => a.groupId === groupId);
if (found) {
- found.end = start;
- found.events.unshift(ev)
- return;
+ found.end = event.when;
+ found.events.unshift(event);
+ return found;
}
- list.push({
+ return {
id: getUniqueId(),
- type: n.type,
- start,
+ type: event.type,
+ start: event.when,
end: AbsoluteTime.never(),
- events: [ev],
+ events: [event],
groupId,
- });
- return;
+ };
}
case NotificationType.WithdrawalOperationTransition: {
- return;
+ return undefined;
}
case NotificationType.ExchangeStateTransition: {
- const groupId = `${n.type}:${n.exchangeBaseUrl}`;
- const found = list.find((a)=>a.groupId === groupId)
+ const groupId = `${event.type}:${event.exchangeBaseUrl}`;
+ const found = knownEvents.find((a) => a.groupId === groupId);
if (found) {
- found.end = start;
- found.events.unshift(ev)
- return;
+ found.end = event.when;
+ found.events.unshift(event);
+ return found;
}
- list.push({
+ return {
id: getUniqueId(),
- type: n.type,
- start,
+ type: event.type,
+ start: event.when,
end: AbsoluteTime.never(),
- events: [ev],
+ events: [event],
groupId,
- });
- return;
+ };
}
case NotificationType.Idle: {
const groupId = "";
- list.push({
+ return({
id: getUniqueId(),
- type: n.type,
- start,
+ type: event.type,
+ start: event.when,
end: AbsoluteTime.never(),
- events: [ev],
+ events: [event],
groupId,
});
- return;
}
case NotificationType.TaskObservabilityEvent: {
- const groupId = `${n.type}:${n.taskId}`;
- const found = list.find((a)=>a.groupId === groupId)
+ const groupId = `${event.type}:${event.taskId}`;
+ const found = knownEvents.find((a) => a.groupId === groupId);
if (found) {
- found.end = start;
- found.events.unshift(ev)
- return;
+ found.end = event.when;
+ found.events.unshift(event);
+ return found;
}
- list.push({
+ return({
id: getUniqueId(),
- type: n.type,
- start,
+ type: event.type,
+ start: event.when,
end: AbsoluteTime.never(),
- events: [ev],
+ events: [event],
groupId,
});
- return;
}
case NotificationType.RequestObservabilityEvent: {
- const groupId = `${n.type}:${n.operation}:${n.requestId}`;
- const found = list.find((a)=>a.groupId === groupId)
+ const groupId = `${event.type}:${event.operation}:${event.requestId}`;
+ const found = knownEvents.find((a) => a.groupId === groupId);
if (found) {
- found.end = start;
- found.events.unshift(ev)
- return;
+ found.end = event.when;
+ found.events.unshift(event);
+ return found;
}
- list.push({
+ return({
id: getUniqueId(),
- type: n.type,
- start,
+ type: event.type,
+ start: event.when,
end: AbsoluteTime.never(),
- events: [ev],
+ events: [event],
groupId,
});
- return;
}
}
}
+function addNewWalletActivityNotification(
+ list: WalletActivityTrack[],
+ n: WalletNotification,
+) {
+ const start = AbsoluteTime.now();
+ const ev = { ...n, when: start };
+ const activity = convertWalletActivityNotification(list, ev);
+ if (activity) {
+ list.unshift(activity); // insert at start
+ }
+}
+
async function getNotifications({
filter,
}: {