Skip to content

Commit

Permalink
fix: Make call to updateMetamaskNotificationsList async and fix its…
Browse files Browse the repository at this point in the history
… event emission. (#4826)

## Explanation

* What is the current state of things and why does it need to change?
The `updateMetamaskNotificationsList` function is async and the
registered message handler should also have been async. The
`NotificationServicesController:notificationsListUpdated` event is not
being received by the extension.
* What is the solution your changes offer and how does it work? Make the
message handler async and move the publish call outside of the update
function.
* Are there any changes whose purpose might not obvious to those
unfamiliar with the domain? This problem was never uncovered because the
`updateMetamaskNotfiicationsList` function was never called in the
extension until now (with snaps). When triggering a notification, with
the current state of things, the extension would not update the badge
counter because it wasn't receiving the
`NotificationServicesController:notificationsListUpdated` event.


## Changelog

### `@metamask/notification-services-controller`

- **FIXED**: `updateMetamaskNotificationsList` was fixed by updating the
message handler and moving the publish call outside of the update to
state in the function.


## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
- [x] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes
  • Loading branch information
hmalik88 authored Oct 22, 2024
1 parent ca4eb19 commit 5576c64
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ export default class NotificationServicesController extends BaseController<
#registerMessageHandlers(): void {
this.messagingSystem.registerActionHandler(
`${controllerName}:updateMetamaskNotificationsList`,
this.updateMetamaskNotificationsList.bind(this),
async (...args) => this.updateMetamaskNotificationsList(...args),
);

this.messagingSystem.registerActionHandler(
Expand Down Expand Up @@ -1375,12 +1375,13 @@ export default class NotificationServicesController extends BaseController<
processedNotification,
...state.metamaskNotificationsList,
];
this.messagingSystem.publish(
`${controllerName}:notificationsListUpdated`,
state.metamaskNotificationsList,
);
}
});

this.messagingSystem.publish(
`${controllerName}:notificationsListUpdated`,
this.state.metamaskNotificationsList,
);
}
}
}

0 comments on commit 5576c64

Please sign in to comment.