{"version":3,"file":"get-notification-message.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-message.ts"],"names":[],"mappings":";;;AAEA,uEAAkE;AAoDlE;;;;;;GAMG;AACI,MAAM,qCAAqC,GAAG,CACnD,eAAgC,EACP,EAAE;IAI3B,MAAM,SAAS,GAAkB,CAAC,GAAG,IAAI,EAAE,EAAE;QAC3C,MAAM,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC;QAEjC,4CAA4C;QAC5C,8DAA8D;QAC9D,MAAM,EAAE,GAAQ,eAAe,CAAC,GAAG,CAAC,CAAC;QACrC,OAAO,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC;IAC1B,CAAC,CAAC;IAEF,OAAO;QACL,UAAU,EAAE;YACV,KAAK,EAAE,GAAkB,EAAE,CACzB,SAAS,CAAC,yCAAyC,CAAC;YACtD,kBAAkB,EAAE,GAAkB,EAAE,CACtC,SAAS,CAAC,sDAAsD,CAAC;YACnE,cAAc,EAAE,CAAC,YAAY,EAAiB,EAAE;gBAC9C,MAAM,MAAM,GAAG,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC;gBAC1D,MAAM,WAAW,GAAG,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC;gBAC/D,MAAM,aAAa,GAAG,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC;gBACnE,IAAI,CAAC,MAAM,IAAI,CAAC,WAAW,IAAI,CAAC,aAAa,EAAE,CAAC;oBAC9C,OAAO,IAAI,CAAC;gBACd,CAAC;gBAED,MAAM,MAAM,GAAG,IAAA,iCAAS,EAAC,WAAW,EAAE,aAAa,EAAE;oBACnD,aAAa,EAAE,IAAI;iBACpB,CAAC,CAAC;gBACH,OAAO,SAAS,CACd,+CAA+C,EAC/C,MAAM,EACN,MAAM,CACP,CAAC;YACJ,CAAC;SACF;QACD,QA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,CAAC;AAjCD,oFAiCC","sourcesContent":["import type { Types } from '../../NotificationServicesController';\nimport type { Constants } from '../../NotificationServicesController';\nimport { getAmount, formatAmount } from './get-notification-data';\n\nexport type TranslationKeys = {\n  pushPlatformNotificationsFundsSentTitle: () => string;\n  pushPlatformNotificationsFundsSentDescriptionDefault: () => string;\n  pushPlatformNotificationsFundsSentDescription: (\n    ...args: [string, string]\n  ) => string;\n  pushPlatformNotificationsFundsReceivedTitle: () => string;\n  pushPlatformNotificationsFundsReceivedDescriptionDefault: () => string;\n  pushPlatformNotificationsFundsReceivedDescription: (\n    ...args: [string, string]\n  ) => string;\n  pushPlatformNotificationsSwapCompletedTitle: () => string;\n  pushPlatformNotificationsSwapCompletedDescription: () => string;\n  pushPlatformNotificationsNftSentTitle: () => string;\n  pushPlatformNotificationsNftSentDescription: () => string;\n  pushPlatformNotificationsNftReceivedTitle: () => string;\n  pushPlatformNotificationsNftReceivedDescription: () => string;\n  pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle: () => string;\n  pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription: () => string;\n  pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle: () => string;\n  pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription: () => string;\n  pushPlatformNotificationsStakingLidoStakeCompletedTitle: () => string;\n  pushPlatformNotificationsStakingLidoStakeCompletedDescription: () => string;\n  pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle: () => string;\n  pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription: () => string;\n  pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle: () => string;\n  pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription: () => string;\n  pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle: () => string;\n  pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription: () => string;\n};\n\ntype PushNotificationMessage = {\n  title: string;\n  description: string;\n  ctaLink?: string;\n};\n\ntype NotificationMessage<TNotification extends Types.INotification> = {\n  title: (notification: TNotification) => string | null;\n  defaultDescription: (notification: TNotification) => string | null;\n  getDescription?: (notification: TNotification) => string | null;\n  link?: (notification: TNotification) => string | null;\n};\n\ntype NotificationMessageDict = {\n  [TriggerType in Constants.TRIGGER_TYPES]?: NotificationMessage<\n    Extract<Types.INotification, { type: TriggerType }>\n  >;\n};\n\n/**\n * On Chain Push Notification Messages.\n * This is a list of all the push notifications we support. Update this for synced notifications on mobile and extension\n *\n * @param translationKeys - all translations supported\n * @returns A translation push message object.\n */\nexport const createOnChainPushNotificationMessages = (\n  translationKeys: TranslationKeys,\n): NotificationMessageDict => {\n  type TranslationFn = <TKey extends keyof TranslationKeys>(\n    ...args: [TKey, ...Parameters<TranslationKeys[TKey]>]\n  ) => string;\n  const translate: TranslationFn = (...args) => {\n    const [key, ...otherArgs] = args;\n\n    // Coerce types for the translation function\n    // eslint-disable-next-line @typescript-eslint/no-explicit-any\n    const fn: any = translationKeys[key];\n    return fn(...otherArgs);\n  };\n\n  return {\n    erc20_sent: {\n      title: (): string | null =>\n        translate('pushPlatformNotificationsFundsSentTitle'),\n      defaultDescription: (): string | null =>\n        translate('pushPlatformNotificationsFundsSentDescriptionDefault'),\n      getDescription: (notification): string | null => {\n        const symbol = notification?.payload?.data?.token?.symbol;\n        const tokenAmount = notification?.payload?.data?.token?.amount;\n        const tokenDecimals = notification?.payload?.data?.token?.decimals;\n        if (!symbol || !tokenAmount || !tokenDecimals) {\n          return null;\n        }\n\n        const amount = getAmount(tokenAmount, tokenDecimals, {\n          shouldEllipse: true,\n        });\n        return translate(\n          'pushPlatformNotificationsFundsSentDescription',\n          amount,\n          symbol,\n        );\n      },\n    },\n    eth_sent: {\n      title: (): string | null =>\n        translate('pushPlatformNotificationsFundsSentTitle'),\n      defaultDescription: (): string | null =>\n        translate('pushPlatformNotificationsFundsSentDescriptionDefault'),\n      getDescription: (notification): string | null => {\n        const symbol = notification?.payload?.network?.native_symbol;\n        const tokenAmount = notification?.payload?.data?.amount?.eth;\n        if (!symbol || !tokenAmount) {\n          return null;\n        }\n\n        const amount = formatAmount(parseFloat(tokenAmount), {\n          shouldEllipse: true,\n        });\n        return translate(\n          'pushPlatformNotificationsFundsSentDescription',\n          amount,\n          symbol,\n        );\n      },\n    },\n    erc20_received: {\n      title: (): string | null =>\n        translate('pushPlatformNotificationsFundsReceivedTitle'),\n      defaultDescription: (): string | null =>\n        translate('pushPlatformNotificationsFundsReceivedDescriptionDefault'),\n      getDescription: (notification): string | null => {\n        const symbol = notification?.payload?.data?.token?.symbol;\n        const tokenAmount = notification?.payload?.data?.token?.amount;\n        const tokenDecimals = notification?.payload?.data?.token?.decimals;\n        if (!symbol || !tokenAmount || !tokenDecimals) {\n          return null;\n        }\n\n        const amount = getAmount(tokenAmount, tokenDecimals, {\n          shouldEllipse: true,\n        });\n        return translate(\n          'pushPlatformNotificationsFundsReceivedDescription',\n          amount,\n          symbol,\n        );\n      },\n    },\n    eth_received: {\n      title: (): string | null =>\n        translate('pushPlatformNotificationsFundsReceivedTitle'),\n      defaultDescription: (): string | null =>\n        translate('pushPlatformNotificationsFundsReceivedDescriptionDefault'),\n      getDescription: (notification): string | null => {\n        const symbol = notification?.payload?.network?.native_symbol;\n        const tokenAmount = notification?.payload?.data?.amount?.eth;\n        if (!symbol || !tokenAmount) {\n          return null;\n        }\n\n        const amount = formatAmount(parseFloat(tokenAmount), {\n          shouldEllipse: true,\n        });\n        return translate(\n          'pushPlatformNotificationsFundsReceivedDescription',\n          amount,\n          symbol,\n        );\n      },\n    },\n    metamask_swap_completed: {\n      title: (): string | null =>\n        translate('pushPlatformNotificationsSwapCompletedTitle'),\n      defaultDescription: (): string | null =>\n        translate('pushPlatformNotificationsSwapCompletedDescription'),\n    },\n    erc721_sent: {\n      title: (): string | null =>\n        translate('pushPlatformNotificationsNftSentTitle'),\n      defaultDescription: (): string | null =>\n        translate('pushPlatformNotificationsNftSentDescription'),\n    },\n    erc1155_sent: {\n      title: (): string | null =>\n        translate('pushPlatformNotificationsNftSentTitle'),\n      defaultDescription: (): string | null =>\n        translate('pushPlatformNotificationsNftSentDescription'),\n    },\n    erc721_received: {\n      title: (): string | null =>\n        translate('pushPlatformNotificationsNftReceivedTitle'),\n      defaultDescription: (): string | null =>\n        translate('pushPlatformNotificationsNftReceivedDescription'),\n    },\n    erc1155_received: {\n      title: (): string | null =>\n        translate('pushPlatformNotificationsNftReceivedTitle'),\n      defaultDescription: (): string | null =>\n        translate('pushPlatformNotificationsNftReceivedDescription'),\n    },\n    rocketpool_stake_completed: {\n      title: (): string | null =>\n        translate(\n          'pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle',\n        ),\n      defaultDescription: (): string | null =>\n        translate(\n          'pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription',\n        ),\n    },\n    rocketpool_unstake_completed: {\n      title: (): string | null =>\n        translate(\n          'pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle',\n        ),\n      defaultDescription: (): string | null =>\n        translate(\n          'pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription',\n        ),\n    },\n    lido_stake_completed: {\n      title: (): string | null =>\n        translate('pushPlatformNotificationsStakingLidoStakeCompletedTitle'),\n      defaultDescription: (): string | null =>\n        translate(\n          'pushPlatformNotificationsStakingLidoStakeCompletedDescription',\n        ),\n    },\n    lido_stake_ready_to_be_withdrawn: {\n      title: (): string | null =>\n        translate(\n          'pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle',\n        ),\n      defaultDescription: (): string | null =>\n        translate(\n          'pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription',\n        ),\n    },\n    lido_withdrawal_requested: {\n      title: (): string | null =>\n        translate(\n          'pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle',\n        ),\n      defaultDescription: (): string | null =>\n        translate(\n          'pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription',\n        ),\n    },\n    lido_withdrawal_completed: {\n      title: (): string | null =>\n        translate(\n          'pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle',\n        ),\n      defaultDescription: (): string | null =>\n        translate(\n          'pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription',\n        ),\n    },\n    platform: {\n      title: (notification): string | null => notification.template.title,\n      defaultDescription: (notification): string | null =>\n        notification.template.body,\n      getDescription: (notification): string | null =>\n        notification.template.body,\n    },\n  };\n};\n\n/**\n * Creates a push notification message based on the given on-chain raw notification.\n *\n * @param notification - processed notification.\n * @param translations - translates keys into text\n * @returns The push notification message object, or null if the notification is invalid.\n */\nexport function createOnChainPushNotificationMessage(\n  notification: Types.INotification,\n  translations: TranslationKeys,\n): PushNotificationMessage | null {\n  if (!notification?.type) {\n    return null;\n  }\n  const notificationMessage =\n    createOnChainPushNotificationMessages(translations)[notification.type];\n\n  if (!notificationMessage) {\n    return null;\n  }\n\n  let description: string | null = null;\n  try {\n    description =\n      // eslint-disable-next-line @typescript-eslint/no-explicit-any\n      notificationMessage?.getDescription?.(notification as any) ??\n      // eslint-disable-next-line @typescript-eslint/no-explicit-any\n      notificationMessage.defaultDescription?.(notification as any) ??\n      null;\n  } catch {\n    description =\n      // eslint-disable-next-line @typescript-eslint/no-explicit-any\n      notificationMessage.defaultDescription?.(notification as any) ?? null;\n  }\n\n  return {\n    // eslint-disable-next-line @typescript-eslint/no-explicit-any\n    title: notificationMessage?.title?.(notification as any) ?? '', // Ensure title is always a string\n    description: description ?? '', // Fallback to empty string if null\n  };\n}\n"]}