{"version":3,"file":"notifications.mjs","sourceRoot":"","sources":["../../../src/methods/hooks/notifications.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,4BAA4B;;;AAGvD,OAAO,EAAE,GAAG,EAAE,2BAA2B;AAGzC,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,8BAAoB;AAE5D;;;;;;;;GAQG;AACH,QAAQ,CAAC,CAAC,oCAAoC,CAC5C,OAAe,EACf,EAAE,OAAO,EAAgB;IAEzB,MAAM,GAAG,CACP,eAAe,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,gBAAgB,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAC1E,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,uCAAuC,CACrD,OAAwB;IAExB,OAAO,KAAK,EACV,GAAG,IAA6D,EAChE,EAAE;QACF,OAAO,MAAM,OAAO,CAClB,oCAAoC,EACpC,GAAG,IAAI,CACR,CAAC,SAAS,EAAE,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAUD;;;;;;;;;;;GAWG;AACH,QAAQ,CAAC,CAAC,mCAAmC,CAC3C,OAAe,EACf,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAA2B;IAEhE,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,GAAG,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,GAAG,CACP,eAAe,CAAC;QACd,EAAE,EAAE,MAAM,EAAE;QACZ,IAAI,EAAE,gBAAgB,CAAC,KAAK;QAC5B,OAAO;QACP,KAAK;QACL,OAAO;QACP,UAAU;KACX,CAAC,CACH,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sCAAsC,CACpD,OAAwB;IAExB,OAAO,KAAK,EACV,GAAG,IAA4D,EAC/D,EAAE;QACF,OAAO,MAAM,OAAO,CAClB,mCAAmC,EACnC,GAAG,IAAI,CACR,CAAC,SAAS,EAAE,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { NotifyParams } from '@metamask/snaps-sdk';\nimport { NotificationType } from '@metamask/snaps-sdk';\nimport { nanoid } from '@reduxjs/toolkit';\nimport type { SagaIterator } from 'redux-saga';\nimport { put } from 'redux-saga/effects';\n\nimport type { RunSagaFunction } from '../../store';\nimport { addNotification, setInterface } from '../../store';\n\n/**\n * Show a native notification to the user.\n *\n * @param _snapId - The ID of the Snap that created the notification.\n * @param options - The notification options.\n * @param options.message - The message to show in the notification.\n * @yields Adds the notification to the store.\n * @returns `null`.\n */\nfunction* showNativeNotificationImplementation(\n  _snapId: string,\n  { message }: NotifyParams,\n): SagaIterator {\n  yield put(\n    addNotification({ id: nanoid(), type: NotificationType.Native, message }),\n  );\n\n  return null;\n}\n\n/**\n * Get a method that can be used to show a native notification.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @returns A method that can be used to show a native notification.\n */\nexport function getShowNativeNotificationImplementation(\n  runSaga: RunSagaFunction,\n) {\n  return async (\n    ...args: Parameters<typeof showNativeNotificationImplementation>\n  ) => {\n    return await runSaga(\n      showNativeNotificationImplementation,\n      ...args,\n    ).toPromise();\n  };\n}\n\ntype InAppNotificationParams = {\n  type: NotificationType;\n  message: string;\n  title?: string | undefined;\n  content?: string | undefined;\n  footerLink?: { text: string; href: string } | undefined;\n};\n\n/**\n * Show an in-app notification to the user.\n *\n * @param _snapId - The ID of the Snap that created the notification.\n * @param options - The notification options.\n * @param options.message - The message to show in the notification.\n * @param options.title - The title to show in the notification.\n * @param options.content - The JSX content to show in the notification.\n * @param options.footerLink - The footer to show in the notification.\n * @yields Adds the notification to the store.\n * @returns `null`.\n */\nfunction* showInAppNotificationImplementation(\n  _snapId: string,\n  { message, title, content, footerLink }: InAppNotificationParams,\n): SagaIterator<null> {\n  if (content) {\n    yield put(setInterface({ type: 'Notification', id: content }));\n  }\n\n  yield put(\n    addNotification({\n      id: nanoid(),\n      type: NotificationType.InApp,\n      message,\n      title,\n      content,\n      footerLink,\n    }),\n  );\n\n  return null;\n}\n\n/**\n * Get a method that can be used to show an in-app notification.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @returns A method that can be used to show an in-app notification.\n */\nexport function getShowInAppNotificationImplementation(\n  runSaga: RunSagaFunction,\n) {\n  return async (\n    ...args: Parameters<typeof showInAppNotificationImplementation>\n  ) => {\n    return await runSaga(\n      showInAppNotificationImplementation,\n      ...args,\n    ).toPromise();\n  };\n}\n"]}