UNPKG

@metamask/snaps-simulation

Version:

A simulation framework for MetaMask Snaps, enabling headless testing of Snaps in a controlled environment

1 lines 3.02 kB
{"version":3,"file":"notifications.mjs","sourceRoot":"","sources":["../../src/store/notifications.ts"],"names":[],"mappings":";;AAkCA;;GAEG;AACH,MAAM,aAAa,GAAuB;IACxC,aAAa,EAAE,EAAE;CAClB,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,WAAW,CAAC;IAC5C,IAAI,EAAE,eAAe;IACrB,YAAY,EAAE,aAAa;IAC3B,QAAQ,EAAE;QACR,eAAe,EAAE,CAAC,KAAK,EAAE,MAAmC,EAAE,EAAE;YAC9D,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC3C,CAAC;QACD,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAA6B,EAAE,EAAE;YAC3D,KAAK,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC,MAAM,CAC9C,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,KAAK,MAAM,CAAC,OAAO,CACrD,CAAC;QACJ,CAAC;QACD,kBAAkB,EAAE,CAAC,KAAK,EAAE,EAAE;YAC5B,KAAK,CAAC,aAAa,GAAG,EAAE,CAAC;QAC3B,CAAC;KACF;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,EAAE,eAAe,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,GACtE,kBAAkB,CAAC,OAAO,CAAC;AAE7B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,cAAc,CAC5C,CAAC,KAAuB,EAAE,EAAE,CAAC,KAAK,CAAC,aAAa,EAChD,CAAC,EAAE,aAAa,EAAE,EAAE,EAAE,CAAC,aAAa,CACrC,CAAC","sourcesContent":["import type { NotificationType } from '@metamask/snaps-sdk';\nimport type { PayloadAction } from '@reduxjs/toolkit';\nimport { createSelector, createSlice } from '@reduxjs/toolkit';\n\nimport type { ApplicationState } from './store';\n\n/**\n * A notification object.\n *\n * @property id - A unique ID for the notification.\n * @property message - The notification message.\n * @property type - The notification type.\n * @property title - The notification title (expanded view).\n * @property content - The notification JSX content (expanded view).\n * @property footerLink - The notification footer (expanded view).\n */\nexport type Notification = {\n id: string;\n message: string;\n type: NotificationType;\n title?: string;\n content?: string;\n footerLink?: { text: string; href: string };\n};\n\n/**\n * The notifications state.\n *\n * @property notifications - An array of notifications.\n */\nexport type NotificationsState = {\n notifications: Notification[];\n};\n\n/**\n * The initial notifications state.\n */\nconst INITIAL_STATE: NotificationsState = {\n notifications: [],\n};\n\nexport const notificationsSlice = createSlice({\n name: 'notifications',\n initialState: INITIAL_STATE,\n reducers: {\n addNotification: (state, action: PayloadAction<Notification>) => {\n state.notifications.push(action.payload);\n },\n removeNotification: (state, action: PayloadAction<string>) => {\n state.notifications = state.notifications.filter(\n (notification) => notification.id !== action.payload,\n );\n },\n clearNotifications: (state) => {\n state.notifications = [];\n },\n },\n});\n\nexport const { addNotification, removeNotification, clearNotifications } =\n notificationsSlice.actions;\n\n/**\n * Get the notifications from the state.\n *\n * @param state - The application state.\n * @returns An array of notifications.\n */\nexport const getNotifications = createSelector(\n (state: ApplicationState) => state.notifications,\n ({ notifications }) => notifications,\n);\n"]}