From ed023020eac0d17a900e5fc33189db3b165b47d7 Mon Sep 17 00:00:00 2001 From: Michal Date: Thu, 10 Oct 2024 10:28:07 +0100 Subject: [PATCH] Add feature flag --- apps/wallet-mobile/src/AppNavigator.tsx | 3 ++- .../src/features/Notifications/useCases/common/hooks.ts | 6 +++--- .../useCases/common/transaction-received-notification.ts | 8 +++++--- apps/wallet-mobile/src/kernel/features.ts | 1 + 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/apps/wallet-mobile/src/AppNavigator.tsx b/apps/wallet-mobile/src/AppNavigator.tsx index 49aa82ef26..60b9477a16 100644 --- a/apps/wallet-mobile/src/AppNavigator.tsx +++ b/apps/wallet-mobile/src/AppNavigator.tsx @@ -38,6 +38,7 @@ import {SetupWalletNavigator} from './features/SetupWallet/SetupWalletNavigator' import {useHasWallets} from './features/WalletManager/common/hooks/useHasWallets' import {useStatusBar} from './hooks/useStatusBar' import {agreementDate} from './kernel/config' +import {features} from './kernel/features' import {AppRoutes, defaultStackNavigationOptions} from './kernel/navigation' import {WalletNavigator} from './WalletNavigator' @@ -46,7 +47,7 @@ const navRef = React.createRef { - useInitNotifications() + useInitNotifications({enabled: features.notifications}) 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 b875e5300c..2e6049a8a1 100644 --- a/apps/wallet-mobile/src/features/Notifications/useCases/common/hooks.ts +++ b/apps/wallet-mobile/src/features/Notifications/useCases/common/hooks.ts @@ -33,7 +33,7 @@ const init = () => { } } -export const useInitNotifications = () => { - useEffect(() => init(), []) - useTransactionReceivedNotifications() +export const useInitNotifications = ({enabled}: {enabled: boolean}) => { + useEffect(() => (enabled ? init() : undefined), [enabled]) + useTransactionReceivedNotifications({enabled}) } diff --git a/apps/wallet-mobile/src/features/Notifications/useCases/common/transaction-received-notification.ts b/apps/wallet-mobile/src/features/Notifications/useCases/common/transaction-received-notification.ts index 89b560ba41..a705f640a0 100644 --- a/apps/wallet-mobile/src/features/Notifications/useCases/common/transaction-received-notification.ts +++ b/apps/wallet-mobile/src/features/Notifications/useCases/common/transaction-received-notification.ts @@ -106,18 +106,20 @@ export const createTransactionReceivedNotification = ( export const transactionReceivedSubject = new Subject() -export const useTransactionReceivedNotifications = () => { +export const useTransactionReceivedNotifications = ({enabled}: {enabled: boolean}) => { const {walletManager} = useWalletManager() const asyncStorage = useAsyncStorage() React.useEffect(() => { + if (!enabled) return registerBackgroundFetchAsync() return () => { unregisterBackgroundFetchAsync() } - }, []) + }, [enabled]) React.useEffect(() => { + if (!enabled) return const subscription = walletManager.syncWalletInfos$.subscribe(async (status) => { const walletInfos = Array.from(status.values()) const walletsDoneSyncing = walletInfos.filter((info) => info.status === 'done') @@ -131,7 +133,7 @@ export const useTransactionReceivedNotifications = () => { return () => { subscription.unsubscribe() } - }, [walletManager, asyncStorage]) + }, [walletManager, asyncStorage, enabled]) } const buildStorage = (appStorage: App.Storage, walletId: string) => { diff --git a/apps/wallet-mobile/src/kernel/features.ts b/apps/wallet-mobile/src/kernel/features.ts index 51aa85a456..e2e2d8a774 100644 --- a/apps/wallet-mobile/src/kernel/features.ts +++ b/apps/wallet-mobile/src/kernel/features.ts @@ -5,6 +5,7 @@ export const features = { prefillWalletInfo: false, showProdPoolsInDev: isDev, moderatingNftsEnabled: false, + notifications: isDev, poolTransition: true, portfolioSecondaryCharts: isDev, portfolioPerformance: false,