mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-20 02:09:10 +01:00
Merge pull request #6460 from BlueWallet/prf
FIX: Some get/set for Settings was broken
This commit is contained in:
commit
e7757bc126
@ -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 {
|
||||
|
@ -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<string>();
|
||||
// HandOff
|
||||
const [isHandOffUseEnabled, setIsHandOffUseEnabled] = useState<boolean>(false);
|
||||
const [isHandOffUseEnabled, setHandOffUseEnabled] = useState<boolean>(false);
|
||||
// PrivacyBlur
|
||||
const [isPrivacyBlurEnabled, setIsPrivacyBlurEnabled] = useState<boolean>(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);
|
||||
|
@ -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<HandOffComponentPro
|
||||
};
|
||||
}
|
||||
|
||||
export const setIsHandOffUseEnabled = async (value: boolean) => {
|
||||
await DefaultPreference.setName(GROUP_IO_BLUEWALLET);
|
||||
await DefaultPreference.set(BlueApp.HANDOFF_STORAGE_KEY, value.toString());
|
||||
console.log('setIsHandOffUseEnabledAsyncStorage', value);
|
||||
};
|
||||
|
||||
export const getIsHandOffUseEnabled = async (): Promise<boolean> => {
|
||||
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();
|
||||
|
||||
|
@ -19,6 +19,12 @@ const HandOffComponent: HandOffComponentWithActivityTypes = props => {
|
||||
return null;
|
||||
};
|
||||
|
||||
export const setIsHandOffUseEnabled = async (value: boolean) => {};
|
||||
|
||||
export const getIsHandOffUseEnabled = async (): Promise<boolean> => {
|
||||
return false;
|
||||
};
|
||||
|
||||
const activityTypes = {
|
||||
ReceiveOnchain: 'io.bluewallet.bluewallet.receiveonchain',
|
||||
Xpub: 'io.bluewallet.bluewallet.xpub',
|
||||
|
@ -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 }}
|
||||
/>
|
||||
<BlueCard>
|
||||
<BlueText>{loc.settings.general_continuity_e}</BlueText>
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user