From 1e13d28f517e5f72b2c1c2217df1265835c7918e Mon Sep 17 00:00:00 2001 From: Michal S Date: Mon, 27 Jan 2025 11:45:17 +0000 Subject: [PATCH] feat(wallet-mobile): Add feature flag for push notifications (#3798) --- apps/wallet-mobile/src/AppNavigator.tsx | 2 +- .../Notifications/useCases/common/hooks.ts | 23 +++-- .../WalletSettingsScreen.tsx | 2 +- apps/wallet-mobile/src/kernel/features.ts | 3 +- .../messages/src/AppNavigator.json | 16 ++-- .../WalletSettingsScreen.json | 92 +++++++++---------- 6 files changed, 72 insertions(+), 66 deletions(-) diff --git a/apps/wallet-mobile/src/AppNavigator.tsx b/apps/wallet-mobile/src/AppNavigator.tsx index f033d3f91a..fa30a05e0d 100644 --- a/apps/wallet-mobile/src/AppNavigator.tsx +++ b/apps/wallet-mobile/src/AppNavigator.tsx @@ -56,7 +56,7 @@ const changeNavigationBarColor = (colorScheme: 'default-dark' | 'default-light', } export const AppNavigator = () => { - useInitNotifications({enabled: features.notifications}) + useInitNotifications({localEnabled: features.localNotifications, pushEnabled: features.pushNotifications}) useDeepLinkWatcher() const strings = useStrings() const [routeName, setRouteName] = React.useState() diff --git a/apps/wallet-mobile/src/features/Notifications/useCases/common/hooks.ts b/apps/wallet-mobile/src/features/Notifications/useCases/common/hooks.ts index fe6538f7ce..3b2b27f964 100644 --- a/apps/wallet-mobile/src/features/Notifications/useCases/common/hooks.ts +++ b/apps/wallet-mobile/src/features/Notifications/useCases/common/hooks.ts @@ -12,7 +12,7 @@ import {useTransactionReceivedNotifications} from './transaction-received-notifi let initialized = false -const init = () => { +const initPushNotifications = () => { if (initialized) return initialized = true PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS) @@ -39,21 +39,26 @@ const init = () => { }, ) - notificationManager.hydrate() - return () => { - notificationManager.destroy() notificationOpenedSubscription.remove() unsubscribeFromForegroundMessage() } } -export const useInitNotifications = ({enabled}: {enabled: boolean}) => { - React.useEffect(() => (enabled ? init() : undefined), [enabled]) - useTransactionReceivedNotifications({enabled}) +const initLocalNotifications = () => { + notificationManager.hydrate() + return () => { + notificationManager.destroy() + } +} + +export const useInitNotifications = ({localEnabled, pushEnabled}: {localEnabled: boolean; pushEnabled: boolean}) => { + React.useEffect(() => (localEnabled ? initLocalNotifications() : undefined), [localEnabled]) + React.useEffect(() => (pushEnabled ? initPushNotifications() : undefined), [pushEnabled]) + useTransactionReceivedNotifications({enabled: localEnabled}) usePrimaryTokenPriceChangedNotification({enabled: false}) // Temporarily disabled until requested by product team - useRewardsUpdatedNotifications({enabled}) - usePushNotifications({enabled}) + useRewardsUpdatedNotifications({enabled: localEnabled}) + usePushNotifications({enabled: pushEnabled}) } const usePushNotifications = ({enabled}: {enabled: boolean}) => { diff --git a/apps/wallet-mobile/src/features/Settings/useCases/changeWalletSettings/WalletSettingsScreen.tsx b/apps/wallet-mobile/src/features/Settings/useCases/changeWalletSettings/WalletSettingsScreen.tsx index 6de7b07b5a..009198dcba 100644 --- a/apps/wallet-mobile/src/features/Settings/useCases/changeWalletSettings/WalletSettingsScreen.tsx +++ b/apps/wallet-mobile/src/features/Settings/useCases/changeWalletSettings/WalletSettingsScreen.tsx @@ -135,7 +135,7 @@ export const WalletSettingsScreen = () => { - {features.notifications && ( + {features.localNotifications && ( <> } label={strings.allowNotifications}> diff --git a/apps/wallet-mobile/src/kernel/features.ts b/apps/wallet-mobile/src/kernel/features.ts index 7b039f58b1..1fda6d1d58 100644 --- a/apps/wallet-mobile/src/kernel/features.ts +++ b/apps/wallet-mobile/src/kernel/features.ts @@ -5,7 +5,8 @@ export const features = { prefillWalletInfo: false, showProdPoolsInDev: isDev, moderatingNftsEnabled: false, - notifications: isDev || isNightly, + localNotifications: true, + pushNotifications: isDev || isNightly, poolTransition: true, portfolioPerformance: false, portfolioNews: false, diff --git a/apps/wallet-mobile/translations/messages/src/AppNavigator.json b/apps/wallet-mobile/translations/messages/src/AppNavigator.json index 41c40edef2..853007d527 100644 --- a/apps/wallet-mobile/translations/messages/src/AppNavigator.json +++ b/apps/wallet-mobile/translations/messages/src/AppNavigator.json @@ -6,12 +6,12 @@ "start": { "line": 254, "column": 17, - "index": 9599 + "index": 9650 }, "end": { "line": 257, "column": 3, - "index": 9689 + "index": 9740 } }, { @@ -21,12 +21,12 @@ "start": { "line": 258, "column": 18, - "index": 9709 + "index": 9760 }, "end": { "line": 261, "column": 3, - "index": 9807 + "index": 9858 } }, { @@ -36,12 +36,12 @@ "start": { "line": 262, "column": 25, - "index": 9834 + "index": 9885 }, "end": { "line": 265, "column": 3, - "index": 9948 + "index": 9999 } }, { @@ -51,12 +51,12 @@ "start": { "line": 266, "column": 27, - "index": 9977 + "index": 10028 }, "end": { "line": 269, "column": 3, - "index": 10098 + "index": 10149 } } ] \ No newline at end of file diff --git a/apps/wallet-mobile/translations/messages/src/features/Settings/useCases/changeWalletSettings/WalletSettingsScreen.json b/apps/wallet-mobile/translations/messages/src/features/Settings/useCases/changeWalletSettings/WalletSettingsScreen.json index 1017d4b7f6..1ebad79dc7 100644 --- a/apps/wallet-mobile/translations/messages/src/features/Settings/useCases/changeWalletSettings/WalletSettingsScreen.json +++ b/apps/wallet-mobile/translations/messages/src/features/Settings/useCases/changeWalletSettings/WalletSettingsScreen.json @@ -6,12 +6,12 @@ "start": { "line": 245, "column": 11, - "index": 7799 + "index": 7804 }, "end": { "line": 248, "column": 3, - "index": 7897 + "index": 7902 } }, { @@ -21,12 +21,12 @@ "start": { "line": 249, "column": 11, - "index": 7910 + "index": 7915 }, "end": { "line": 252, "column": 3, - "index": 8008 + "index": 8013 } }, { @@ -36,12 +36,12 @@ "start": { "line": 253, "column": 16, - "index": 8026 + "index": 8031 }, "end": { "line": 256, "column": 3, - "index": 8135 + "index": 8140 } }, { @@ -51,12 +51,12 @@ "start": { "line": 257, "column": 10, - "index": 8147 + "index": 8152 }, "end": { "line": 260, "column": 3, - "index": 8243 + "index": 8248 } }, { @@ -66,12 +66,12 @@ "start": { "line": 261, "column": 14, - "index": 8259 + "index": 8264 }, "end": { "line": 264, "column": 3, - "index": 8364 + "index": 8369 } }, { @@ -81,12 +81,12 @@ "start": { "line": 265, "column": 12, - "index": 8378 + "index": 8383 }, "end": { "line": 268, "column": 3, - "index": 8478 + "index": 8483 } }, { @@ -96,12 +96,12 @@ "start": { "line": 269, "column": 18, - "index": 8498 + "index": 8503 }, "end": { "line": 272, "column": 3, - "index": 8620 + "index": 8625 } }, { @@ -111,12 +111,12 @@ "start": { "line": 273, "column": 20, - "index": 8642 + "index": 8647 }, "end": { "line": 276, "column": 3, - "index": 8771 + "index": 8776 } }, { @@ -126,12 +126,12 @@ "start": { "line": 277, "column": 24, - "index": 8797 + "index": 8802 }, "end": { "line": 280, "column": 3, - "index": 8959 + "index": 8964 } }, { @@ -141,12 +141,12 @@ "start": { "line": 281, "column": 16, - "index": 8977 + "index": 8982 }, "end": { "line": 284, "column": 3, - "index": 9086 + "index": 9091 } }, { @@ -156,12 +156,12 @@ "start": { "line": 285, "column": 14, - "index": 9102 + "index": 9107 }, "end": { "line": 288, "column": 3, - "index": 9173 + "index": 9178 } }, { @@ -171,12 +171,12 @@ "start": { "line": 289, "column": 21, - "index": 9196 + "index": 9201 }, "end": { "line": 292, "column": 3, - "index": 9282 + "index": 9287 } }, { @@ -186,12 +186,12 @@ "start": { "line": 293, "column": 17, - "index": 9301 + "index": 9306 }, "end": { "line": 296, "column": 3, - "index": 9379 + "index": 9384 } }, { @@ -201,12 +201,12 @@ "start": { "line": 297, "column": 25, - "index": 9406 + "index": 9411 }, "end": { "line": 300, "column": 3, - "index": 9537 + "index": 9542 } }, { @@ -216,12 +216,12 @@ "start": { "line": 302, "column": 11, - "index": 9598 + "index": 9603 }, "end": { "line": 305, "column": 3, - "index": 9664 + "index": 9669 } }, { @@ -231,12 +231,12 @@ "start": { "line": 306, "column": 14, - "index": 9680 + "index": 9685 }, "end": { "line": 309, "column": 3, - "index": 9786 + "index": 9791 } }, { @@ -246,12 +246,12 @@ "start": { "line": 310, "column": 15, - "index": 9803 + "index": 9808 }, "end": { "line": 313, "column": 3, - "index": 9914 + "index": 9919 } }, { @@ -261,12 +261,12 @@ "start": { "line": 314, "column": 17, - "index": 9933 + "index": 9938 }, "end": { "line": 317, "column": 3, - "index": 10048 + "index": 10053 } }, { @@ -276,12 +276,12 @@ "start": { "line": 318, "column": 21, - "index": 10071 + "index": 10076 }, "end": { "line": 321, "column": 3, - "index": 10191 + "index": 10196 } }, { @@ -291,12 +291,12 @@ "start": { "line": 322, "column": 9, - "index": 10202 + "index": 10207 }, "end": { "line": 325, "column": 3, - "index": 10296 + "index": 10301 } }, { @@ -306,12 +306,12 @@ "start": { "line": 326, "column": 10, - "index": 10308 + "index": 10313 }, "end": { "line": 329, "column": 3, - "index": 10410 + "index": 10415 } }, { @@ -321,12 +321,12 @@ "start": { "line": 330, "column": 22, - "index": 10434 + "index": 10439 }, "end": { "line": 333, "column": 3, - "index": 10556 + "index": 10561 } }, { @@ -336,12 +336,12 @@ "start": { "line": 334, "column": 22, - "index": 10580 + "index": 10585 }, "end": { "line": 337, "column": 3, - "index": 10701 + "index": 10706 } } ] \ No newline at end of file