UNPKG

@yoroi/types

Version:
110 lines 3.95 kB
import { BehaviorSubject, Subject } from 'rxjs'; import { AppStorage } from '../app/storage'; export declare enum NotificationTrigger { 'TransactionReceived' = "TransactionReceived", 'RewardsUpdated' = "RewardsUpdated", 'PrimaryTokenPriceChanged' = "PrimaryTokenPriceChanged", 'Push' = "Push", 'Banner' = "Banner" } export type NotificationManagerMakerProps = { eventsStorage: AppStorage<true, string>; configStorage: AppStorage<true, string>; subscriptions?: Partial<{ [NotificationTrigger.TransactionReceived]: Subject<NotificationTransactionReceivedEvent>; [NotificationTrigger.RewardsUpdated]: Subject<NotificationRewardsUpdatedEvent>; [NotificationTrigger.PrimaryTokenPriceChanged]: Subject<NotificationPrimaryTokenPriceChangedEvent>; [NotificationTrigger.Push]: Subject<PushNotificationEvent>; [NotificationTrigger.Banner]: Subject<BannerNotificationEvent>; }>; eventsLimit?: number; }; export interface BannerNotificationEvent extends NotificationEventBase { trigger: NotificationTrigger.Banner; metadata: { title: string; body: string; data?: Record<string, unknown>; }; } export interface PushNotificationEvent extends NotificationEventBase { trigger: NotificationTrigger.Push; metadata: { title: string; body: string; data?: Record<string, unknown>; }; } export interface NotificationTransactionReceivedEvent extends NotificationEventBase { trigger: NotificationTrigger.TransactionReceived; metadata: { walletId: string; previousTxsCounter: number; nextTxsCounter: number; txId: string; isSentByUser: boolean; }; } export interface NotificationRewardsUpdatedEvent extends NotificationEventBase { trigger: NotificationTrigger.RewardsUpdated; metadata: { walletId: string; }; } export interface NotificationPrimaryTokenPriceChangedEvent extends NotificationEventBase { trigger: NotificationTrigger.PrimaryTokenPriceChanged; metadata: { previousPrice: number; nextPrice: number; }; } export type NotificationGroup = 'transaction-history' | 'portfolio' | 'push'; export type NotificationEvent = NotificationTransactionReceivedEvent | NotificationPrimaryTokenPriceChangedEvent | NotificationRewardsUpdatedEvent | PushNotificationEvent | BannerNotificationEvent; type NotificationEventId = number; interface NotificationEventBase { id: NotificationEventId; date: string; isRead: boolean; } export type NotificationConfig = { displayDuration: number; [NotificationTrigger.Push]: { notify: boolean; }; [NotificationTrigger.PrimaryTokenPriceChanged]: { notify: boolean; thresholdInPercent: number; interval: '24h' | '1h'; }; [NotificationTrigger.TransactionReceived]: { notify: boolean; }; [NotificationTrigger.RewardsUpdated]: { notify: boolean; }; [NotificationTrigger.Banner]: { notify: boolean; }; }; export type NotificationManager = { hydrate: () => void; unreadCounterByGroup$: BehaviorSubject<Readonly<Map<NotificationGroup, number>>>; newEvents$: Subject<NotificationEvent>; events: { markAllAsRead: () => Promise<void>; markAsRead(id: NotificationEventId): Promise<void>; remove(id: NotificationEventId): Promise<ReadonlyArray<NotificationEvent>>; read: () => Promise<ReadonlyArray<NotificationEvent>>; push: (event: Readonly<NotificationEvent>) => Promise<void>; clear: () => Promise<void>; }; config: { read: () => Promise<Readonly<NotificationConfig>>; save: (config: Readonly<Partial<NotificationConfig>>) => Promise<void>; reset: () => Promise<void>; }; destroy: () => Promise<void>; clear: () => Promise<void>; }; export {}; //# sourceMappingURL=manager.d.ts.map