UNPKG

@metamask/snaps-simulation

Version:

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

71 lines 2.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getShowInAppNotificationImplementation = exports.getShowNativeNotificationImplementation = void 0; const snaps_sdk_1 = require("@metamask/snaps-sdk"); const toolkit_1 = require("@reduxjs/toolkit"); const effects_1 = require("redux-saga/effects"); const store_1 = require("../../store/index.cjs"); /** * 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 (0, effects_1.put)((0, store_1.addNotification)({ id: (0, toolkit_1.nanoid)(), type: snaps_sdk_1.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. */ function getShowNativeNotificationImplementation(runSaga) { return async (...args) => { return await runSaga(showNativeNotificationImplementation, ...args).toPromise(); }; } exports.getShowNativeNotificationImplementation = getShowNativeNotificationImplementation; /** * 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 (0, effects_1.put)((0, store_1.setInterface)({ type: 'Notification', id: content })); } yield (0, effects_1.put)((0, store_1.addNotification)({ id: (0, toolkit_1.nanoid)(), type: snaps_sdk_1.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. */ function getShowInAppNotificationImplementation(runSaga) { return async (...args) => { return await runSaga(showInAppNotificationImplementation, ...args).toPromise(); }; } exports.getShowInAppNotificationImplementation = getShowInAppNotificationImplementation; //# sourceMappingURL=notifications.cjs.map