diff --git a/packages/notification-services-controller/src/NotificationServicesController/__fixtures__/mock-raw-notifications.ts b/packages/notification-services-controller/src/NotificationServicesController/__fixtures__/mock-raw-notifications.ts index 7d41fa3e7a..7358692332 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/__fixtures__/mock-raw-notifications.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/__fixtures__/mock-raw-notifications.ts @@ -668,8 +668,6 @@ export function createMockNotificationLidoReadyToBeWithdrawn(): OnChainRawNotifi export function createMockNotificationAaveV3HealthFactor(): OnChainRawNotification { const mockNotification: OnChainRawNotification = { type: TRIGGER_TYPES.AAVE_V3_HEALTH_FACTOR, - block_number: 18378208, - block_timestamp: '1697643851', chain_id: 1, created_at: '2023-10-18T16:35:03.147606Z', address: '0x881D40237659C251811CEC9c364ef91dC08D300C', @@ -681,8 +679,6 @@ export function createMockNotificationAaveV3HealthFactor(): OnChainRawNotificati }, id: 'd73df14d-ce73-4f38-bad3-ab028154042b', trigger_id: 'd73df14d-ce73-4f38-bad3-ab028154042b', - tx_hash: - '0xe6d210d2e601ef3dd1075c48e71452cf35f2daae3886911e964e3babad8ac657', unread: true, }; @@ -696,8 +692,6 @@ export function createMockNotificationAaveV3HealthFactor(): OnChainRawNotificati export function createMockNotificationEnsExpiration(): OnChainRawNotification { const mockNotification: OnChainRawNotification = { type: TRIGGER_TYPES.ENS_EXPIRATION, - block_number: 18378208, - block_timestamp: '1697643851', chain_id: 1, created_at: '2023-10-18T16:35:03.147606Z', address: '0x881D40237659C251811CEC9c364ef91dC08D300C', @@ -710,8 +704,6 @@ export function createMockNotificationEnsExpiration(): OnChainRawNotification { }, id: 'f4ef0b7f-5612-537f-9144-0b5c63ae5391', trigger_id: 'd73df14d-ce73-4f38-bad3-ab028154042c', - tx_hash: - '0xe6d210d2e601ef3dd1075c48e71452cf35f2daae3886911e964e3babad8ac657', unread: true, }; @@ -725,8 +717,6 @@ export function createMockNotificationEnsExpiration(): OnChainRawNotification { export function createMockNotificationLidoStakingRewards(): OnChainRawNotification { const mockNotification: OnChainRawNotification = { type: TRIGGER_TYPES.LIDO_STAKING_REWARDS, - block_number: 18378208, - block_timestamp: '1697643851', chain_id: 1, created_at: '2023-10-18T16:35:03.147606Z', address: '0x881D40237659C251811CEC9c364ef91dC08D300C', @@ -741,8 +731,6 @@ export function createMockNotificationLidoStakingRewards(): OnChainRawNotificati }, id: 'd73df14d-ce73-4f38-bad3-ab028154042l', trigger_id: 'd73df14d-ce73-4f38-bad3-ab028154042l', - tx_hash: - '0xe6d210d2e601ef3dd1075c48e71452cf35f2daae3886911e964e3babad8ac657', unread: true, }; @@ -756,8 +744,6 @@ export function createMockNotificationLidoStakingRewards(): OnChainRawNotificati export function createMockNotificationNotionalLoanExpiration(): OnChainRawNotification { const mockNotification: OnChainRawNotification = { type: TRIGGER_TYPES.NOTIONAL_LOAN_EXPIRATION, - block_number: 18378208, - block_timestamp: '1697643851', chain_id: 1, created_at: '2023-10-18T16:35:03.147606Z', address: '0x881D40237659C251811CEC9c364ef91dC08D300C', @@ -775,8 +761,6 @@ export function createMockNotificationNotionalLoanExpiration(): OnChainRawNotifi }, id: 'd73df14d-ce73-4f38-bad3-ab028154042n', trigger_id: 'd73df14d-ce73-4f38-bad3-ab028154042n', - tx_hash: - '0xe6d210d2e601ef3dd1075c48e71452cf35f2daae3886911e964e3babad8ac657', unread: true, }; @@ -790,8 +774,6 @@ export function createMockNotificationNotionalLoanExpiration(): OnChainRawNotifi export function createMockNotificationRocketpoolStakingRewards(): OnChainRawNotification { const mockNotification: OnChainRawNotification = { type: TRIGGER_TYPES.ROCKETPOOL_STAKING_REWARDS, - block_number: 18378208, - block_timestamp: '1697643851', chain_id: 1, created_at: '2023-10-18T16:35:03.147606Z', address: '0x881D40237659C251811CEC9c364ef91dC08D300C', @@ -806,8 +788,6 @@ export function createMockNotificationRocketpoolStakingRewards(): OnChainRawNoti }, id: 'd73df14d-ce73-4f38-bad3-ab028154042r', trigger_id: 'd73df14d-ce73-4f38-bad3-ab028154042r', - tx_hash: - '0xe6d210d2e601ef3dd1075c48e71452cf35f2daae3886911e964e3babad8ac657', unread: true, }; @@ -821,8 +801,6 @@ export function createMockNotificationRocketpoolStakingRewards(): OnChainRawNoti export function createMockNotificationSparkFiHealthFactor(): OnChainRawNotification { const mockNotification: OnChainRawNotification = { type: TRIGGER_TYPES.SPARK_FI_HEALTH_FACTOR, - block_number: 18378208, - block_timestamp: '1697643851', chain_id: 1, created_at: '2023-10-18T16:35:03.147606Z', address: '0x881D40237659C251811CEC9c364ef91dC08D300C', @@ -834,8 +812,6 @@ export function createMockNotificationSparkFiHealthFactor(): OnChainRawNotificat }, id: 'd73df14d-ce73-4f38-bad3-ab028154042s', trigger_id: 'd73df14d-ce73-4f38-bad3-ab028154042s', - tx_hash: - '0xe6d210d2e601ef3dd1075c48e71452cf35f2daae3886911e964e3babad8ac657', unread: true, }; diff --git a/packages/notification-services-controller/src/NotificationServicesController/types/on-chain-notification/on-chain-notification.ts b/packages/notification-services-controller/src/NotificationServicesController/types/on-chain-notification/on-chain-notification.ts index 82ec90ff45..8bd2d78ef5 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/types/on-chain-notification/on-chain-notification.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/types/on-chain-notification/on-chain-notification.ts @@ -37,8 +37,9 @@ export type Data_NotionalLoanExpiration = export type Data_SparkFiHealthFactor = components['schemas']['Data_SparkFiHealthFactor']; -type Notification = components['schemas']['Notification']; -type NotificationDataKinds = NonNullable['kind']; +type Notification = + | components['schemas']['WalletNotification'] + | components['schemas']['Web3Notification']; type ConvertToEnum = { [K in TRIGGER_TYPES]: Kind extends `${K}` ? K : never; }[TRIGGER_TYPES]; @@ -49,15 +50,23 @@ type ConvertToEnum = { * 2. It ensures that the `data` field is the correct Notification data for this `type` * - The `Compute` utility merges the intersections (`&`) for a prettier type. */ -export type OnChainRawNotification = { +type NormalizeNotification< + N extends Notification, + NotificationDataKinds extends string = NonNullable['kind'], +> = { [K in NotificationDataKinds]: Compute< - Omit & { + Omit & { type: ConvertToEnum; - data: Extract; + data: Extract; } >; }[NotificationDataKinds]; +export type OnChainRawNotification = Compute< + | NormalizeNotification + | NormalizeNotification +>; + export type UnprocessedOnChainRawNotification = Notification; export type OnChainRawNotificationsWithNetworkFields = Extract< diff --git a/packages/notification-services-controller/src/NotificationServicesController/types/on-chain-notification/schema.ts b/packages/notification-services-controller/src/NotificationServicesController/types/on-chain-notification/schema.ts index 59a2359ec4..a650b29be6 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/types/on-chain-notification/schema.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/types/on-chain-notification/schema.ts @@ -50,7 +50,10 @@ export type paths = { [name: string]: unknown; }; content: { - 'application/json': components['schemas']['Notification'][]; + 'application/json': ( + | components['schemas']['WalletNotification'] + | components['schemas']['Web3Notification'] + )[]; }; }; }; @@ -372,7 +375,7 @@ export type components = { /** Format: date-time */ created_at?: string; }; - Notification: { + WalletNotification: { /** Format: uuid */ id: string; /** Format: uuid */ @@ -380,13 +383,13 @@ export type components = { /** @example 1 */ chain_id: number; /** @example 17485840 */ - block_number?: number; - block_timestamp?: string; + block_number: number; + block_timestamp: string; /** * Format: address * @example 0x881D40237659C251811CEC9c364ef91dC08D300C */ - tx_hash?: string; + tx_hash: string; /** @example false */ unread: boolean; /** Format: date-time */ @@ -408,7 +411,22 @@ export type components = { | components['schemas']['Data_ERC721Sent'] | components['schemas']['Data_ERC721Received'] | components['schemas']['Data_ERC1155Sent'] - | components['schemas']['Data_ERC1155Received'] + | components['schemas']['Data_ERC1155Received']; + }; + Web3Notification: { + /** Format: uuid */ + id: string; + /** Format: uuid */ + trigger_id: string; + /** @example 1 */ + chain_id: number; + /** @example false */ + unread: boolean; + /** Format: date-time */ + created_at: string; + /** Format: address */ + address: string; + data?: | components['schemas']['Data_AaveV3HealthFactor'] | components['schemas']['Data_EnsExpiration'] | components['schemas']['Data_LidoStakingRewards'] @@ -685,7 +703,5 @@ export type components = { headers: never; pathItems: never; }; - export type $defs = Record; - export type operations = Record;