Skip to content

Commit f50d1b9

Browse files
committed
chore: address code-rabbit suggestions
1 parent 94c13eb commit f50d1b9

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

infrastructure/eid-wallet/src/lib/services/NotificationService.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PUBLIC_PROVISIONER_URL } from "$env/static/public";
2-
import { addNotification } from "$lib/stores/notifications";
2+
import { addNotification, hasNotification } from "$lib/stores/notifications";
33
import {
44
isPermissionGranted,
55
onNotificationReceived,
@@ -422,11 +422,11 @@ class NotificationService {
422422
),
423423
);
424424

425-
addNotification({
426-
title,
427-
body: notification.body ?? "",
428-
data: Object.keys(data).length > 0 ? data : undefined,
429-
});
425+
const body = notification.body ?? "";
426+
const payload = Object.keys(data).length > 0 ? data : undefined;
427+
if (!hasNotification(title, body, payload)) {
428+
addNotification({ title, body, data: payload });
429+
}
430430
});
431431
}
432432

infrastructure/eid-wallet/src/lib/stores/notifications.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ export function getUnreadCount(): number {
5050
return loadNotifications().length;
5151
}
5252

53+
export function hasNotification(
54+
title: string,
55+
body: string,
56+
data?: Record<string, string>,
57+
): boolean {
58+
const notifications = loadNotifications();
59+
const key = `${title}\0${body}\0${JSON.stringify(data ?? {})}`;
60+
return notifications.some(
61+
(n) => `${n.title}\0${n.body}\0${JSON.stringify(n.data ?? {})}` === key,
62+
);
63+
}
64+
5365
export function addNotification(
5466
notification: Omit<StoredNotification, "id" | "createdAt">,
5567
): void {

0 commit comments

Comments
 (0)