Files
dydx-v4-web/src/constants/notifications.ts
T

127 lines
3.6 KiB
TypeScript

import { StatusResponse } from "@0xsquid/sdk";
/** implemented in useNotificationTypes */
export enum NotificationType {
OrderStatusChanged = 'OrderStatusChanged',
SquidTransfer = 'SquidTransfer',
}
export enum NotificationComponentType {}
export type NotificationId = string | number;
export type NotificationTypeConfig<
_NotificationId extends NotificationId = string,
NotificationUpdateKey = any
> = {
type: NotificationType;
/** React hook to trigger notifications based on app state */
useTrigger: (_: {
trigger: (
/** Unique ID for the triggered notification */
id: _NotificationId,
/** Display data for the triggered notification */
displayData: NotificationDisplayData,
/**
* JSON-serializable key.
* Re-triggers the notification if passed a different value from the last trigger() call (even from a previous browser session).
* Suggested usage: data dependency array
*/
updateKey?: NotificationUpdateKey,
/**
* @param true (default): Notification initialized with status NotificationStatus.Triggered
* @param false: Notification initialized with status NotificationStatus.Cleared
*/
isNew?: boolean
) => void;
lastUpdated: number;
}) => void;
/** Callback for notification action (Toast action button click, NotificationsMenu item click, or native push notification interaction) */
useNotificationAction?: () => (id: _NotificationId) => any;
};
export enum NotificationStatus {
/** Notification triggered for the first time. Toast timer started. "New" in NotificationsMenu. */
Triggered,
/** Notification re-triggered with a different NotificationUpdateKey. Toast timer restarted. "New" in NotificationsMenu. */
Updated,
/** Toast timer expired without user interaction. "New" in NotificationsMenu. */
Unseen,
/** Toast or NotificationsMenu item interacted with or dismissed. "Seen" in NotificationsMenu. */
Seen,
/** Notification marked for deletion. "Archived" in NotificationsMenu. */
Cleared,
}
/** Notification state. Serialized and cached into localStorage. */
export type Notification<
_NotificationId extends NotificationId = string,
NotificationUpdateKey = any
> = {
id: _NotificationId;
type: NotificationType;
status: NotificationStatus;
timestamps: Partial<Record<NotificationStatus, number>>;
updateKey: NotificationUpdateKey;
};
export type Notifications = Record<NotificationId, Notification<any>>;
/** Notification display data derived from app state at runtime. */
export type NotificationDisplayData = {
icon?: React.ReactNode;
title?: string;
description?: React.ReactNode;
customContent?: React.ReactNode;
customMenuContent?: React.ReactNode;
actionDescription?: string;
/** Screen reader: instructions for performing toast action after its timer expires */
actionAltText?: string;
/**
* @param foreground
Screen reader: announces immediately.
Push notification: vibrates device.
* @param background
Screen reader: announces at the next graceful opportunity.
Push notification: no vibration.
*/
toastSensitivity?: 'foreground' | 'background';
/**
* @param number
Radix UI Toast: automatically Unseen.
Push notification: requires interaction.
* @param Infinity
Radix UI Toast: no timer.
Push notification: requires interaction.
*/
toastDuration?: number;
};
// Notification types
export type TransferNotifcation = {
txHash: string;
toChainId?: string;
fromChainId?: string;
toAmount?: number;
triggeredAt?: number;
status?: StatusResponse;
};