Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/notification-services-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Update `isOnChainRawNotification` to detect on-chain notifications using the v4 `notification_type` discriminator instead of legacy payload field checks, fixing web push notification handling after the v4 API migration ([#9407](https://github.com/MetaMask/core/pull/9407))

## [25.0.0]

### Added
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import type { OnChainRawNotification } from '../NotificationServicesController';
import type {
UnprocessedRawNotification,
OnChainNotification,
} from '../NotificationServicesController/types/notification-api';
import { isOnChainNotification } from './notification-api-type-guards';

/**
* Checks if the given value is an OnChainRawNotification object.
* Checks if the given value is an on-chain notification using the v4 `notification_type` discriminator.
*
* @param notification - The value to check.
* @returns True if the value is an OnChainRawNotification object, false otherwise.
* @returns True if the value is an on-chain notification, false otherwise.
*/
export function isOnChainRawNotification(
notification: unknown,
): notification is OnChainRawNotification {
const assumed = notification as OnChainRawNotification;

// We don't have a validation/parsing library to check all possible types of an on chain notification
// It is safe enough just to check "some" fields, and catch any errors down the line if the shape is bad.
const isValidEnoughToBeOnChainNotification = [
assumed?.id,
assumed?.payload?.data,
].every((field) => field !== undefined);
return isValidEnoughToBeOnChainNotification;
): notification is OnChainNotification {
return isOnChainNotification(notification as UnprocessedRawNotification);
}