UNPKG

@metamask/snaps-simulation

Version:

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

67 lines 2.51 kB
import { NotificationType } from "@metamask/snaps-sdk"; import $reduxjstoolkit from "@reduxjs/toolkit"; const { nanoid } = $reduxjstoolkit; import { put } from "redux-saga/effects"; import { addNotification, setInterface } from "../../store/index.mjs"; /** * Show a native notification to the user. * * @param _snapId - The ID of the Snap that created the notification. * @param options - The notification options. * @param options.message - The message to show in the notification. * @yields Adds the notification to the store. * @returns `null`. */ function* showNativeNotificationImplementation(_snapId, { message }) { yield put(addNotification({ id: nanoid(), type: NotificationType.Native, message })); return null; } /** * Get a method that can be used to show a native notification. * * @param runSaga - A function to run a saga outside the usual Redux flow. * @returns A method that can be used to show a native notification. */ export function getShowNativeNotificationImplementation(runSaga) { return async (...args) => { return await runSaga(showNativeNotificationImplementation, ...args).toPromise(); }; } /** * Show an in-app notification to the user. * * @param _snapId - The ID of the Snap that created the notification. * @param options - The notification options. * @param options.message - The message to show in the notification. * @param options.title - The title to show in the notification. * @param options.content - The JSX content to show in the notification. * @param options.footerLink - The footer to show in the notification. * @yields Adds the notification to the store. * @returns `null`. */ function* showInAppNotificationImplementation(_snapId, { message, title, content, footerLink }) { if (content) { yield put(setInterface({ type: 'Notification', id: content })); } yield put(addNotification({ id: nanoid(), type: NotificationType.InApp, message, title, content, footerLink, })); return null; } /** * Get a method that can be used to show an in-app notification. * * @param runSaga - A function to run a saga outside the usual Redux flow. * @returns A method that can be used to show an in-app notification. */ export function getShowInAppNotificationImplementation(runSaga) { return async (...args) => { return await runSaga(showInAppNotificationImplementation, ...args).toPromise(); }; } //# sourceMappingURL=notifications.mjs.map