Skip to content

Notification badge returns after "mark as read" until the app restarts #28

Description

@Bielcx

Symptom

Tapping "mark as read" in notifications clears the badge, then it comes straight
back to the same count (3 in the reported case). It only really clears after
restarting the app.

Root cause

lib/notifications-context.tsx:43-55 clears the badge locally and re-queries the
chain one second later:

const onNotificationsMarkedAsRead = useCallback(() => {
  setBadgeCount(0);
  // …
  markedAsReadTimerRef.current = setTimeout(() => {
    updateBadgeCount();
  }, 1000); // Wait 1 second for the mark as read operation to complete on blockchain
}, [updateBadgeCount]);

The comment states the intent, and the number is the bug. markAsRead broadcasts a
transaction; Hive produces a block roughly every 3 seconds, so after 1s the
transaction is typically not in a block yet. fetchNewNotifications then reads the
pre-mark state and returns the same notifications, so setBadgeCount puts the count
back.

Restarting works because by then the chain has caught up.

components/notifications/NotificationsScreen.tsx:33-35 does await markAsRead()
before signalling, but a broadcast resolving is not the same as the transaction
being included and the node reflecting it.

Suggested fix

Simplest is to drop the eager re-query. The local setBadgeCount(0) is already
correct, and the existing 2-minute refresh (notifications-context.tsx:63-71)
reconciles on its own.

Bumping the delay to ~5s would also work but stays a race against block time and
node propagation.

Suggested label: bug, mobile

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions