diff --git a/blue_modules/currency.ts b/blue_modules/currency.ts index bd6d7ac10..195a74ce1 100644 --- a/blue_modules/currency.ts +++ b/blue_modules/currency.ts @@ -9,7 +9,7 @@ const PREFERRED_CURRENCY_STORAGE_KEY = 'preferredCurrency'; const PREFERRED_CURRENCY_LOCALE_STORAGE_KEY = 'preferredCurrencyLocale'; const EXCHANGE_RATES_STORAGE_KEY = 'exchangeRates'; const LAST_UPDATED = 'LAST_UPDATED'; -const GROUP_IO_BLUEWALLET = 'group.io.bluewallet.bluewallet'; +export const GROUP_IO_BLUEWALLET = 'group.io.bluewallet.bluewallet'; const BTC_PREFIX = 'BTC_'; export interface CurrencyRate { diff --git a/components/Context/SettingsContext.tsx b/components/Context/SettingsContext.tsx index 77a87df7b..143cb218f 100644 --- a/components/Context/SettingsContext.tsx +++ b/components/Context/SettingsContext.tsx @@ -9,6 +9,7 @@ import { useStorage } from '../../blue_modules/storage-context'; import { isBalanceDisplayAllowed, setBalanceDisplayAllowed } from '../WidgetCommunication'; import { clearUseURv1, isURv1Enabled, setUseURv1 } from '../../blue_modules/ur'; import BlueClipboard from '../../blue_modules/clipboard'; +import { getIsHandOffUseEnabled, setIsHandOffUseEnabled } from '../HandOffComponent'; import DeviceQuickActions from '../../class/quick-actions'; interface SettingsContextType { @@ -65,7 +66,7 @@ export const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({ chil // Language const [language, setLanguage] = useState(); // HandOff - const [isHandOffUseEnabled, setIsHandOffUseEnabled] = useState(false); + const [isHandOffUseEnabled, setHandOffUseEnabled] = useState(false); // PrivacyBlur const [isPrivacyBlurEnabled, setIsPrivacyBlurEnabled] = useState(true); // AdvancedMode @@ -83,7 +84,6 @@ export const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({ chil const advancedModeStorage = useAsyncStorage(BlueApp.ADVANCED_MODE_ENABLED); const doNotTrackStorage = useAsyncStorage(BlueApp.DO_NOT_TRACK); - const isHandOffUseEnabledStorage = useAsyncStorage(BlueApp.HANDOFF_STORAGE_KEY); const languageStorage = useAsyncStorage(STORAGE_KEY); const { walletsInitialized } = useStorage(); @@ -92,12 +92,12 @@ export const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({ chil const fetchSettings = async () => { const advMode = await advancedModeStorage.getItem(); console.debug('SettingsContext advMode:', advMode); - const handOff = await isHandOffUseEnabledStorage.getItem(); + const handOff = await getIsHandOffUseEnabled(); console.debug('SettingsContext handOff:', handOff); + setHandOffUseEnabled(handOff); const lang = (await languageStorage.getItem()) ?? 'en'; console.debug('SettingsContext lang:', lang); setIsAdvancedModeEnabled(advMode ? JSON.parse(advMode) : false); - setIsHandOffUseEnabled(handOff ? JSON.parse(handOff) : false); const isBalanceDisplayAllowedStorage = await isBalanceDisplayAllowed(); console.debug('SettingsContext isBalanceDisplayAllowed:', isBalanceDisplayAllowedStorage); setIsWidgetBalanceDisplayAllowed(isBalanceDisplayAllowedStorage); @@ -158,13 +158,11 @@ export const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({ chil [doNotTrackStorage], ); - const setIsHandOffUseEnabledAsyncStorage = useCallback( - async (value: boolean) => { - setIsHandOffUseEnabled(value); - await isHandOffUseEnabledStorage.setItem; - }, - [isHandOffUseEnabledStorage.setItem], - ); + const setIsHandOffUseEnabledAsyncStorage = useCallback(async (value: boolean) => { + console.debug('setIsHandOffUseEnabledAsyncStorage', value); + await setIsHandOffUseEnabled(value); + setHandOffUseEnabled(value); + }, []); const setIsWidgetBalanceDisplayAllowedStorage = useCallback(async (value: boolean) => { await setBalanceDisplayAllowed(value); diff --git a/components/HandOffComponent.ios.tsx b/components/HandOffComponent.ios.tsx index 739ec9c6b..0f4f57191 100644 --- a/components/HandOffComponent.ios.tsx +++ b/components/HandOffComponent.ios.tsx @@ -2,6 +2,9 @@ import React from 'react'; // @ts-ignore: react-native-handoff is not in the type definition import Handoff from 'react-native-handoff'; import { useSettings } from './Context/SettingsContext'; +import DefaultPreference from 'react-native-default-preference'; +import { GROUP_IO_BLUEWALLET } from '../blue_modules/currency'; +import { BlueApp } from '../class'; interface HandOffComponentProps { url?: string; @@ -18,6 +21,19 @@ interface HandOffComponentWithActivityTypes extends React.FC { + await DefaultPreference.setName(GROUP_IO_BLUEWALLET); + await DefaultPreference.set(BlueApp.HANDOFF_STORAGE_KEY, value.toString()); + console.log('setIsHandOffUseEnabledAsyncStorage', value); +}; + +export const getIsHandOffUseEnabled = async (): Promise => { + await DefaultPreference.setName(GROUP_IO_BLUEWALLET); + const isEnabledValue = await DefaultPreference.get(BlueApp.HANDOFF_STORAGE_KEY); + console.log('getIsHandOffUseEnabledV', isEnabledValue); + return isEnabledValue === 'true'; +}; + const HandOffComponent: HandOffComponentWithActivityTypes = props => { const { isHandOffUseEnabled } = useSettings(); diff --git a/components/HandOffComponent.tsx b/components/HandOffComponent.tsx index e44747c32..03f70e58b 100644 --- a/components/HandOffComponent.tsx +++ b/components/HandOffComponent.tsx @@ -19,6 +19,12 @@ const HandOffComponent: HandOffComponentWithActivityTypes = props => { return null; }; +export const setIsHandOffUseEnabled = async (value: boolean) => {}; + +export const getIsHandOffUseEnabled = async (): Promise => { + return false; +}; + const activityTypes = { ReceiveOnchain: 'io.bluewallet.bluewallet.receiveonchain', Xpub: 'io.bluewallet.bluewallet.xpub', diff --git a/screen/settings/GeneralSettings.tsx b/screen/settings/GeneralSettings.tsx index cae7704c2..1ec95a621 100644 --- a/screen/settings/GeneralSettings.tsx +++ b/screen/settings/GeneralSettings.tsx @@ -33,6 +33,10 @@ const GeneralSettings: React.FC = () => { navigate('SettingsPrivacy'); }; + const onHandOffUseEnabledChange = async (value: boolean) => { + await setIsHandOffUseEnabledAsyncStorage(value); + }; + const stylesWithThemeHook = { root: { backgroundColor: colors.background, @@ -54,7 +58,7 @@ const GeneralSettings: React.FC = () => { hideChevron title={loc.settings.general_continuity} Component={PressableWrapper} - switch={{ onValueChange: setIsHandOffUseEnabledAsyncStorage, value: isHandOffUseEnabled }} + switch={{ onValueChange: onHandOffUseEnabledChange, value: isHandOffUseEnabled }} /> {loc.settings.general_continuity_e} diff --git a/screen/settings/SettingsPrivacy.js b/screen/settings/SettingsPrivacy.js index df2910cde..1f95e954f 100644 --- a/screen/settings/SettingsPrivacy.js +++ b/screen/settings/SettingsPrivacy.js @@ -10,6 +10,7 @@ import { useTheme } from '../../components/themes'; import ListItem from '../../components/ListItem'; import A from '../../blue_modules/analytics'; import { useSettings } from '../../components/Context/SettingsContext'; +import { setBalanceDisplayAllowed } from '../../components/WidgetCommunication'; const SettingsPrivacy = () => { const { colors } = useTheme(); @@ -72,6 +73,7 @@ const SettingsPrivacy = () => { const onWidgetsTotalBalanceValueChange = async value => { setIsLoading(sections.WIDGETS); try { + await setBalanceDisplayAllowed(value); setIsWidgetBalanceDisplayAllowedStorage(value); } catch (e) { console.log(e);