mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-03 20:07:11 +01:00
wip
This commit is contained in:
parent
4ebf0932ab
commit
60990636f0
2 changed files with 98 additions and 60 deletions
|
@ -1,4 +1,4 @@
|
|||
import React, { createContext, useState, useContext, useEffect } from 'react';
|
||||
import React, { createContext, useState, useContext, useEffect, useMemo, useCallback } from 'react';
|
||||
import { useAsyncStorage } from '@react-native-async-storage/async-storage';
|
||||
import { FiatUnit, TFiatUnit } from '../../models/fiatUnit';
|
||||
import { getPreferredCurrency, initCurrencyDaemon } from '../../blue_modules/currency';
|
||||
|
@ -19,7 +19,7 @@ interface SettingsContextType {
|
|||
isHandOffUseEnabled: boolean;
|
||||
setIsHandOffUseEnabledAsyncStorage: (value: boolean) => Promise<void>;
|
||||
isPrivacyBlurEnabled: boolean;
|
||||
setIsPrivacyBlurEnabled: (value: boolean) => void;
|
||||
setIsPrivacyBlurEnabledState: (value: boolean) => void;
|
||||
isAdvancedModeEnabled: boolean;
|
||||
setIsAdvancedModeEnabledStorage: (value: boolean) => Promise<void>;
|
||||
isDoNotTrackEnabled: boolean;
|
||||
|
@ -42,7 +42,7 @@ const defaultSettingsContext: SettingsContextType = {
|
|||
isHandOffUseEnabled: false,
|
||||
setIsHandOffUseEnabledAsyncStorage: async () => {},
|
||||
isPrivacyBlurEnabled: true,
|
||||
setIsPrivacyBlurEnabled: () => {},
|
||||
setIsPrivacyBlurEnabledState: () => {},
|
||||
isAdvancedModeEnabled: false,
|
||||
setIsAdvancedModeEnabledStorage: async () => {},
|
||||
isDoNotTrackEnabled: false,
|
||||
|
@ -132,51 +132,67 @@ export const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({ chil
|
|||
}
|
||||
}, [walletsInitialized]);
|
||||
|
||||
const setPreferredFiatCurrencyStorage = async (currency: TFiatUnit) => {
|
||||
const setPreferredFiatCurrencyStorage = useCallback(async (currency: TFiatUnit) => {
|
||||
await setPreferredFiatCurrency(currency);
|
||||
setPreferredFiatCurrency(currency);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const setLanguageStorage = async (newLanguage: string) => {
|
||||
const setLanguageStorage = useCallback(async (newLanguage: string) => {
|
||||
await saveLanguage(newLanguage);
|
||||
setLanguage(newLanguage);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const setIsAdvancedModeEnabledStorage = async (value: boolean) => {
|
||||
const setIsAdvancedModeEnabledStorage = useCallback(
|
||||
async (value: boolean) => {
|
||||
await advancedModeStorage.setItem(JSON.stringify(value));
|
||||
setIsAdvancedModeEnabled(value);
|
||||
};
|
||||
},
|
||||
[advancedModeStorage],
|
||||
);
|
||||
|
||||
const setDoNotTrackStorage = async (value: boolean) => {
|
||||
const setDoNotTrackStorage = useCallback(
|
||||
async (value: boolean) => {
|
||||
await doNotTrackStorage.setItem(JSON.stringify(value));
|
||||
setIsDoNotTrackEnabled(value);
|
||||
};
|
||||
},
|
||||
[doNotTrackStorage],
|
||||
);
|
||||
|
||||
const setIsHandOffUseEnabledAsyncStorage = async (value: boolean) => {
|
||||
const setIsHandOffUseEnabledAsyncStorage = useCallback(
|
||||
async (value: boolean) => {
|
||||
setIsHandOffUseEnabled(value);
|
||||
await isHandOffUseEnabledStorage.setItem;
|
||||
};
|
||||
},
|
||||
[isHandOffUseEnabledStorage.setItem],
|
||||
);
|
||||
|
||||
const setIsWidgetBalanceDisplayAllowedStorage = async (value: boolean) => {
|
||||
const setIsWidgetBalanceDisplayAllowedStorage = useCallback(async (value: boolean) => {
|
||||
await setBalanceDisplayAllowed(value);
|
||||
setIsWidgetBalanceDisplayAllowed(value);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const setIsLegacyURv1EnabledStorage = async (value: boolean) => {
|
||||
const setIsLegacyURv1EnabledStorage = useCallback(async (value: boolean) => {
|
||||
value ? await setUseURv1() : await clearUseURv1();
|
||||
await setIsLegacyURv1Enabled(value);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const setIsClipboardGetContentEnabledStorage = async (value: boolean) => {
|
||||
const setIsClipboardGetContentEnabledStorage = useCallback(async (value: boolean) => {
|
||||
await BlueClipboard().setReadClipboardAllowed(value);
|
||||
setIsClipboardGetContentEnabled(value);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const setIsQuickActionsEnabledStorage = async (value: boolean) => {
|
||||
const setIsQuickActionsEnabledStorage = useCallback(async (value: boolean) => {
|
||||
// @ts-ignore: Fix later
|
||||
await DeviceQuickActions.setEnabled(value);
|
||||
setIsQuickActionsEnabled(value);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const setIsPrivacyBlurEnabledState = useCallback((value: boolean) => {
|
||||
setIsPrivacyBlurEnabled(value);
|
||||
if (!value) {
|
||||
presentAlert({ message: 'Privacy blur has been disabled.' });
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
console.log(`Privacy blur: ${isPrivacyBlurEnabled}`);
|
||||
|
@ -185,7 +201,8 @@ export const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({ chil
|
|||
}
|
||||
}, [isPrivacyBlurEnabled]);
|
||||
|
||||
const value: SettingsContextType = {
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
preferredFiatCurrency,
|
||||
setPreferredFiatCurrencyStorage,
|
||||
language,
|
||||
|
@ -193,7 +210,7 @@ export const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({ chil
|
|||
isHandOffUseEnabled,
|
||||
setIsHandOffUseEnabledAsyncStorage,
|
||||
isPrivacyBlurEnabled,
|
||||
setIsPrivacyBlurEnabled,
|
||||
setIsPrivacyBlurEnabledState,
|
||||
isAdvancedModeEnabled,
|
||||
setIsAdvancedModeEnabledStorage,
|
||||
isDoNotTrackEnabled,
|
||||
|
@ -206,7 +223,30 @@ export const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({ chil
|
|||
setIsClipboardGetContentEnabledStorage,
|
||||
isQuickActionsEnabled,
|
||||
setIsQuickActionsEnabledStorage,
|
||||
};
|
||||
}),
|
||||
[
|
||||
preferredFiatCurrency,
|
||||
setPreferredFiatCurrencyStorage,
|
||||
language,
|
||||
setLanguageStorage,
|
||||
isHandOffUseEnabled,
|
||||
setIsHandOffUseEnabledAsyncStorage,
|
||||
isPrivacyBlurEnabled,
|
||||
setIsPrivacyBlurEnabledState,
|
||||
isAdvancedModeEnabled,
|
||||
setIsAdvancedModeEnabledStorage,
|
||||
isDoNotTrackEnabled,
|
||||
setDoNotTrackStorage,
|
||||
isWidgetBalanceDisplayAllowed,
|
||||
setIsWidgetBalanceDisplayAllowedStorage,
|
||||
isLegacyURv1Enabled,
|
||||
setIsLegacyURv1EnabledStorage,
|
||||
isClipboardGetContentEnabled,
|
||||
setIsClipboardGetContentEnabledStorage,
|
||||
isQuickActionsEnabled,
|
||||
setIsQuickActionsEnabledStorage,
|
||||
],
|
||||
);
|
||||
|
||||
return <SettingsContext.Provider value={value}>{children}</SettingsContext.Provider>;
|
||||
};
|
||||
|
|
|
@ -5,7 +5,6 @@ import { openSettings } from 'react-native-permissions';
|
|||
import navigationStyle from '../../components/navigationStyle';
|
||||
import { BlueText, BlueSpacing20, BlueCard, BlueHeaderDefaultSub, BlueSpacing40 } from '../../BlueComponents';
|
||||
import loc from '../../loc';
|
||||
import DeviceQuickActions from '../../class/quick-actions';
|
||||
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
||||
import { useTheme } from '../../components/themes';
|
||||
import ListItem from '../../components/ListItem';
|
||||
|
@ -18,16 +17,17 @@ const SettingsPrivacy = () => {
|
|||
const {
|
||||
isDoNotTrackEnabled,
|
||||
setDoNotTrackStorage,
|
||||
setIsPrivacyBlurEnabled,
|
||||
setIsPrivacyBlurEnabledState,
|
||||
isWidgetBalanceDisplayAllowed,
|
||||
setIsWidgetBalanceDisplayAllowedStorage,
|
||||
isClipboardGetContentEnabled,
|
||||
setIsClipboardGetContentEnabledStorage,
|
||||
isQuickActionsEnabled,
|
||||
setIsQuickActionsEnabledStorage,
|
||||
} = useSettings();
|
||||
const sections = Object.freeze({ ALL: 0, CLIPBOARDREAD: 1, QUICKACTION: 2, WIDGETS: 3 });
|
||||
const [isLoading, setIsLoading] = useState(sections.ALL);
|
||||
|
||||
const [isQuickActionsEnabled, setIsQuickActionsEnabled] = useState(false);
|
||||
const [storageIsEncrypted, setStorageIsEncrypted] = useState(true);
|
||||
const [isPrivacyBlurEnabledTapped, setIsPrivacyBlurEnabledTapped] = useState(0);
|
||||
const styleHooks = StyleSheet.create({
|
||||
|
@ -40,7 +40,6 @@ const SettingsPrivacy = () => {
|
|||
(async () => {
|
||||
try {
|
||||
setStorageIsEncrypted(await isStorageEncrypted());
|
||||
setIsQuickActionsEnabled(await DeviceQuickActions.getEnabled());
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
@ -63,8 +62,7 @@ const SettingsPrivacy = () => {
|
|||
const onQuickActionsValueChange = async value => {
|
||||
setIsLoading(sections.QUICKACTION);
|
||||
try {
|
||||
await DeviceQuickActions.setEnabled(value);
|
||||
setIsQuickActionsEnabled(value);
|
||||
setIsQuickActionsEnabledStorage(value);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
@ -92,15 +90,13 @@ const SettingsPrivacy = () => {
|
|||
};
|
||||
|
||||
const onDisablePrivacyTapped = () => {
|
||||
setIsPrivacyBlurEnabled(!(isPrivacyBlurEnabledTapped >= 10));
|
||||
setIsPrivacyBlurEnabledState(!(isPrivacyBlurEnabledTapped >= 10));
|
||||
setIsPrivacyBlurEnabledTapped(prev => prev + 1);
|
||||
};
|
||||
|
||||
return (
|
||||
<ScrollView style={[styles.root, stylesWithThemeHook.root]} contentInsetAdjustmentBehavior="automatic" automaticallyAdjustContentInsets>
|
||||
<Pressable accessibilityRole="button" onPress={onDisablePrivacyTapped}>
|
||||
{Platform.OS === 'android' ? <BlueHeaderDefaultSub leftText={loc.settings.general} /> : <></>}
|
||||
</Pressable>
|
||||
<ListItem
|
||||
hideChevron
|
||||
title={loc.settings.privacy_read_clipboard}
|
||||
|
@ -113,7 +109,9 @@ const SettingsPrivacy = () => {
|
|||
}}
|
||||
/>
|
||||
<BlueCard>
|
||||
<Pressable accessibilityRole="button" onPress={onDisablePrivacyTapped}>
|
||||
<BlueText>{loc.settings.privacy_clipboard_explanation}</BlueText>
|
||||
</Pressable>
|
||||
</BlueCard>
|
||||
<BlueSpacing20 />
|
||||
{!storageIsEncrypted && (
|
||||
|
|
Loading…
Add table
Reference in a new issue