Skip to content

Commit

Permalink
feat(wallet-mobile): Add feature flag for push notifications (#3798)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljscript authored Jan 27, 2025
1 parent 374dc1b commit 1e13d28
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 66 deletions.
2 changes: 1 addition & 1 deletion apps/wallet-mobile/src/AppNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const WalletSettingsScreen = () => {

<Spacer height={24} />

{features.notifications && (
{features.localNotifications && (
<>
<SettingsSection title={strings.inAppNotifications}>
<SettingsItem icon={<Icon.Bell {...iconProps} />} label={strings.allowNotifications}>
Expand Down
3 changes: 2 additions & 1 deletion apps/wallet-mobile/src/kernel/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions apps/wallet-mobile/translations/messages/src/AppNavigator.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"start": {
"line": 254,
"column": 17,
"index": 9599
"index": 9650
},
"end": {
"line": 257,
"column": 3,
"index": 9689
"index": 9740
}
},
{
Expand All @@ -21,12 +21,12 @@
"start": {
"line": 258,
"column": 18,
"index": 9709
"index": 9760
},
"end": {
"line": 261,
"column": 3,
"index": 9807
"index": 9858
}
},
{
Expand All @@ -36,12 +36,12 @@
"start": {
"line": 262,
"column": 25,
"index": 9834
"index": 9885
},
"end": {
"line": 265,
"column": 3,
"index": 9948
"index": 9999
}
},
{
Expand All @@ -51,12 +51,12 @@
"start": {
"line": 266,
"column": 27,
"index": 9977
"index": 10028
},
"end": {
"line": 269,
"column": 3,
"index": 10098
"index": 10149
}
}
]
Loading

0 comments on commit 1e13d28

Please sign in to comment.