From af30bb560aff38b8953a7193fe9e294c4e316fbe Mon Sep 17 00:00:00 2001 From: Jean Ribeiro Date: Wed, 22 May 2024 04:18:37 -0300 Subject: [PATCH] feat: highlight unread notifications (#2527) * chore: refactor for multi chain support (#2511) * chore: remove BASE_TOKEN_CONTRACT_ADDRESS map * chore: rename getL1Network to getStardustNetwork * fix: type * feat: highlight unread notification * fix incoming notifications * restructure --------- Co-authored-by: Tuditi <45079109+Tuditi@users.noreply.github.com> Co-authored-by: Mark Nardi --- .../components/tiles/NotificationTile.svelte | 24 ++++++++++------- .../classes/notificationsManager.class.ts | 27 ++++++++++++++----- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/packages/shared/src/components/tiles/NotificationTile.svelte b/packages/shared/src/components/tiles/NotificationTile.svelte index 2ff499c296..86f26d4ab3 100644 --- a/packages/shared/src/components/tiles/NotificationTile.svelte +++ b/packages/shared/src/components/tiles/NotificationTile.svelte @@ -1,6 +1,7 @@ - +
-
+
{notification.title} - - {getBestTimeDuration(new Date().getTime() - notification.sentAt, 'day', true)} - + {#if notification.url} + + {/if}
- {#if notification.url} - + {#if !notification.isRead} + {/if}
- {notification.body} +
+ {notification.body} + + {getBestTimeDuration($time.getTime() - notification.sentAt, 'day', true)} + +
diff --git a/packages/shared/src/lib/auxiliary/wallet-connect/notifications/classes/notificationsManager.class.ts b/packages/shared/src/lib/auxiliary/wallet-connect/notifications/classes/notificationsManager.class.ts index 45a3d0a205..a100c346ba 100644 --- a/packages/shared/src/lib/auxiliary/wallet-connect/notifications/classes/notificationsManager.class.ts +++ b/packages/shared/src/lib/auxiliary/wallet-connect/notifications/classes/notificationsManager.class.ts @@ -49,7 +49,11 @@ export class NotificationsManager { this.notifyClient.on( NotifyEvent.Notification, (event: NotifyClientTypes.EventArguments[NotifyEvent.Notification]) => { - this.handleNewNotification(event.topic, event.params.notification) + // The types are not correct on this event, so we need to cast it to the correct type + this.handleNewNotification( + event.topic, + event.params.notification as unknown as NotifyClientTypes.NotifyServerNotification + ) } ) @@ -212,14 +216,25 @@ export class NotificationsManager { }) } - private handleNewNotification(topic: string, notification: NotifyClientTypes.NotifyNotification): void { + private handleNewNotification(topic: string, notification: NotifyClientTypes.NotifyServerNotification): void { + const notificationsForTopic = get(this.notificationsPerSubscription)[topic] + + if (!notificationsForTopic || notificationsForTopic?.find((n) => n.id === notification.id)) { + return + } + this.notificationsPerSubscription.update((state) => { - if (!state[topic]) { - return state + const parsedNotification = { + title: notification.title, + sentAt: notification.sent_at, + body: notification.body, + id: notification.id, + url: notification.url, + isRead: notification.is_read, + type: notification.type, } - const notificationsForTopic = state[topic] - state[topic] = [...notificationsForTopic, notification] + state[topic] = [...state[topic], parsedNotification] return state }) }