Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ update notification types and tests #4818

Merged
merged 3 commits into from
Oct 18, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
};

Expand All @@ -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',
Expand All @@ -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,
};

Expand All @@ -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',
Expand All @@ -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,
};

Expand All @@ -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',
Expand All @@ -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,
};

Expand All @@ -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',
Expand All @@ -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,
};

Expand All @@ -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,
Prithpal-Sooriya marked this conversation as resolved.
Show resolved Hide resolved
block_timestamp: '1697643851',
chain_id: 1,
created_at: '2023-10-18T16:35:03.147606Z',
address: '0x881D40237659C251811CEC9c364ef91dC08D300C',
Expand All @@ -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,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ export type Data_NotionalLoanExpiration =
export type Data_SparkFiHealthFactor =
components['schemas']['Data_SparkFiHealthFactor'];

type Notification = components['schemas']['Notification'];
type NotificationDataKinds = NonNullable<Notification['data']>['kind'];
type Notification =
| components['schemas']['WalletNotification']
| components['schemas']['Web3Notification'];
type ConvertToEnum<Kind> = {
[K in TRIGGER_TYPES]: Kind extends `${K}` ? K : never;
}[TRIGGER_TYPES];
Expand All @@ -49,15 +50,23 @@ type ConvertToEnum<Kind> = {
* 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<N['data']>['kind'],
> = {
[K in NotificationDataKinds]: Compute<
Omit<Notification, 'data'> & {
Omit<N, 'data'> & {
type: ConvertToEnum<K>;
data: Extract<Notification['data'], { kind: K }>;
data: Extract<N['data'], { kind: K }>;
}
>;
}[NotificationDataKinds];

export type OnChainRawNotification = Compute<
| NormalizeNotification<components['schemas']['WalletNotification']>
| NormalizeNotification<components['schemas']['Web3Notification']>
>;
Prithpal-Sooriya marked this conversation as resolved.
Show resolved Hide resolved

export type UnprocessedOnChainRawNotification = Notification;

export type OnChainRawNotificationsWithNetworkFields = Extract<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ export type paths = {
[name: string]: unknown;
};
content: {
'application/json': components['schemas']['Notification'][];
'application/json': (
| components['schemas']['WalletNotification']
| components['schemas']['Web3Notification']
)[];
};
};
};
Expand Down Expand Up @@ -372,21 +375,21 @@ export type components = {
/** Format: date-time */
created_at?: string;
};
Notification: {
WalletNotification: {
/** Format: uuid */
id: string;
/** Format: uuid */
trigger_id: string;
/** @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 */
Expand All @@ -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']
Expand Down Expand Up @@ -685,7 +703,5 @@ export type components = {
headers: never;
pathItems: never;
};

export type $defs = Record<string, never>;

export type operations = Record<string, never>;
Loading