Merge pull request #7172 from BlueWallet/phook

REF: usePrivacy hook no longer needed
This commit is contained in:
GLaDOS 2024-10-14 08:49:55 +00:00 committed by GitHub
commit c86f2a2833
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 39 additions and 84 deletions

View file

@ -1,34 +0,0 @@
import { useEffect, useCallback } from 'react';
import { disallowScreenshot } from 'react-native-screen-capture';
import { useSettings } from './context/useSettings';
export const usePrivacy = () => {
const { isPrivacyBlurEnabled } = useSettings();
const enableBlur = useCallback(() => {
if (!isPrivacyBlurEnabled) return;
disallowScreenshot(true);
}, [isPrivacyBlurEnabled]);
const disableBlur = useCallback(() => {
disallowScreenshot(false);
}, []);
useEffect(() => {
// Apply privacy settings when the component mounts or when the setting changes
if (isPrivacyBlurEnabled) {
enableBlur();
} else {
disableBlur();
}
// Cleanup: Re-enable screenshots when the component unmounts
return () => {
disableBlur();
};
}, [isPrivacyBlurEnabled, enableBlur, disableBlur]);
return { enableBlur, disableBlur };
};
export default usePrivacy;

View file

@ -16,7 +16,7 @@ import { BlueText } from '../../BlueComponents';
import presentAlert from '../../components/Alert';
import { DynamicQRCode } from '../../components/DynamicQRCode';
import { useTheme } from '../../components/themes';
import usePrivacy from '../../hooks/usePrivacy';
import { disallowScreenshot } from 'react-native-screen-capture';
import loc from '../../loc';
import { BitcoinUnit } from '../../models/bitcoinUnits';
@ -26,7 +26,6 @@ const SendCreate = () => {
const size = transaction.virtualSize();
const { colors } = useTheme();
const { setOptions } = useNavigation();
const { enableBlur, disableBlur } = usePrivacy();
const styleHooks = StyleSheet.create({
transactionDetailsTitle: {
@ -48,11 +47,11 @@ const SendCreate = () => {
useEffect(() => {
console.log('send/create - useEffect');
enableBlur();
disallowScreenshot(true);
return () => {
disableBlur();
disallowScreenshot(false);
};
}, [disableBlur, enableBlur]);
}, []);
const exportTXN = useCallback(async () => {
const fileName = `${Date.now()}.txn`;

View file

@ -7,7 +7,7 @@ import { DynamicQRCode } from '../../components/DynamicQRCode';
import SaveFileButton from '../../components/SaveFileButton';
import { SquareButton } from '../../components/SquareButton';
import { useTheme } from '../../components/themes';
import usePrivacy from '../../hooks/usePrivacy';
import { disallowScreenshot } from 'react-native-screen-capture';
import loc from '../../loc';
import { useStorage } from '../../hooks/context/useStorage';
import { ExportMultisigCoordinationSetupStackRootParamList } from '../../navigation/ExportMultisigCoordinationSetupStack';
@ -75,7 +75,7 @@ const ExportMultisigCoordinationSetup: React.FC = () => {
const wallet: TWallet | undefined = wallets.find(w => w.getID() === walletID);
const dynamicQRCode = useRef<any>();
const { colors } = useTheme();
const { enableBlur, disableBlur } = usePrivacy();
const navigation = useNavigation();
const stylesHook = StyleSheet.create({
scrollViewContent: {
@ -99,7 +99,7 @@ const ExportMultisigCoordinationSetup: React.FC = () => {
dispatch({ type: ActionType.SET_LOADING, isLoading: true });
const task = InteractionManager.runAfterInteractions(() => {
enableBlur();
disallowScreenshot(true);
if (wallet) {
setTimeout(async () => {
try {
@ -125,7 +125,7 @@ const ExportMultisigCoordinationSetup: React.FC = () => {
return () => {
task.cancel();
disableBlur();
disallowScreenshot(false);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [walletID]),

View file

@ -18,8 +18,7 @@ import { AddWalletStackParamList } from '../../navigation/AddWalletStack';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { THDWalletForWatchOnly, TWallet } from '../../class/wallets/types';
import { navigate } from '../../NavigationService';
import { keepAwake } from 'react-native-screen-capture';
import usePrivacy from '../../hooks/usePrivacy';
import { keepAwake, disallowScreenshot } from 'react-native-screen-capture';
type RouteProps = RouteProp<AddWalletStackParamList, 'ImportWalletDiscovery'>;
type NavigationProp = NativeStackNavigationProp<AddWalletStackParamList, 'ImportWalletDiscovery'>;
@ -54,7 +53,6 @@ const ImportWalletDiscovery: React.FC = () => {
const [selected, setSelected] = useState<number>(0);
const [progress, setProgress] = useState<string | undefined>();
const importing = useRef<boolean>(false);
const { disableBlur } = usePrivacy();
const bip39 = useMemo(() => {
const hd = new HDSegwitBech32Wallet();
hd.setSecret(importText);
@ -147,7 +145,7 @@ const ImportWalletDiscovery: React.FC = () => {
const handleCustomDerivation = () => {
task.current?.stop();
keepAwake(false);
disableBlur();
disallowScreenshot(false);
navigation.navigate('ImportCustomDerivationPath', { importText, password });
};

View file

@ -3,7 +3,7 @@ import { useNavigation, useRoute } from '@react-navigation/native';
import { BackHandler, I18nManager, ScrollView, StyleSheet, Text, View } from 'react-native';
import Button from '../../components/Button';
import { useTheme } from '../../components/themes';
import usePrivacy from '../../hooks/usePrivacy';
import { disallowScreenshot } from 'react-native-screen-capture';
import loc from '../../loc';
import { useStorage } from '../../hooks/context/useStorage';
@ -13,7 +13,6 @@ const PleaseBackup: React.FC = () => {
const wallet = wallets.find(w => w.getID() === walletID);
const navigation = useNavigation();
const { colors } = useTheme();
const { enableBlur, disableBlur } = usePrivacy();
const stylesHook = StyleSheet.create({
flex: {
@ -38,10 +37,10 @@ const PleaseBackup: React.FC = () => {
useEffect(() => {
BackHandler.addEventListener('hardwareBackPress', handleBackButton);
enableBlur();
disallowScreenshot(true);
return () => {
BackHandler.removeEventListener('hardwareBackPress', handleBackButton);
disableBlur();
disallowScreenshot(false);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

View file

@ -41,7 +41,7 @@ import prompt from '../../helpers/prompt';
import { scanQrHelper } from '../../helpers/scan-qr';
import { unlockWithBiometrics, useBiometrics } from '../../hooks/useBiometrics';
import { useExtendedNavigation } from '../../hooks/useExtendedNavigation';
import usePrivacy from '../../hooks/usePrivacy';
import { disallowScreenshot } from 'react-native-screen-capture';
import loc from '../../loc';
import ActionSheet from '../ActionSheet';
import { useStorage } from '../../hooks/context/useStorage';
@ -78,7 +78,6 @@ const ViewEditMultisigCosigners: React.FC = () => {
Why the container view ? It was the easiest to get the ref for. No other reason.
*/
const discardChangesRef = useRef<View>(null);
const { enableBlur, disableBlur } = usePrivacy();
const stylesHook = StyleSheet.create({
root: {
@ -190,7 +189,7 @@ const ViewEditMultisigCosigners: React.FC = () => {
if (hasLoaded.current) return;
setIsLoading(true);
enableBlur();
disallowScreenshot(true);
const task = InteractionManager.runAfterInteractions(async () => {
if (!w.current) {
@ -206,7 +205,7 @@ const ViewEditMultisigCosigners: React.FC = () => {
setIsLoading(false);
});
return () => {
disableBlur();
disallowScreenshot(false);
task.cancel();
};
// eslint-disable-next-line react-hooks/exhaustive-deps

View file

@ -4,7 +4,7 @@ import { ActivityIndicator, FlatList, StyleSheet, View, Platform, UIManager } fr
import { WatchOnlyWallet } from '../../class';
import { AddressItem } from '../../components/addresses/AddressItem';
import { useTheme } from '../../components/themes';
import usePrivacy from '../../hooks/usePrivacy';
import { disallowScreenshot } from 'react-native-screen-capture';
import { useStorage } from '../../hooks/context/useStorage';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { DetailViewStackParamList } from '../../navigation/DetailViewStackParamList';
@ -131,7 +131,6 @@ const WalletAddresses: React.FC = () => {
const { colors } = useTheme();
const { setOptions } = useExtendedNavigation<NavigationProps>();
const { enableBlur, disableBlur } = usePrivacy();
const stylesHook = StyleSheet.create({
root: {
@ -177,12 +176,12 @@ const WalletAddresses: React.FC = () => {
useFocusEffect(
useCallback(() => {
enableBlur();
disallowScreenshot(true);
getAddresses();
return () => {
disableBlur();
disallowScreenshot(false);
};
}, [enableBlur, disableBlur, getAddresses]),
}, [getAddresses]),
);
const data =

View file

@ -8,7 +8,7 @@ import HandOffComponent from '../../components/HandOffComponent';
import QRCodeComponent from '../../components/QRCodeComponent';
import SafeArea from '../../components/SafeArea';
import { useTheme } from '../../components/themes';
import usePrivacy from '../../hooks/usePrivacy';
import { disallowScreenshot } from 'react-native-screen-capture';
import loc from '../../loc';
import { useStorage } from '../../hooks/context/useStorage';
import { HandOffActivityType } from '../../components/types';
@ -25,7 +25,6 @@ const WalletExport: React.FC = () => {
const wallet = wallets.find(w => w.getID() === walletID);
const [qrCodeSize, setQRCodeSize] = useState(90);
const appState = useRef(AppState.currentState);
const { enableBlur, disableBlur } = usePrivacy();
useEffect(() => {
const subscription = AppState.addEventListener('change', nextAppState => {
@ -55,7 +54,7 @@ const WalletExport: React.FC = () => {
useFocusEffect(
useCallback(() => {
enableBlur();
disallowScreenshot(true);
const task = InteractionManager.runAfterInteractions(async () => {
if (wallet) {
if (!wallet.getUserHasSavedExport()) {
@ -67,7 +66,7 @@ const WalletExport: React.FC = () => {
});
return () => {
task.cancel();
disableBlur();
disallowScreenshot(false);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [wallet]),

View file

@ -29,7 +29,7 @@ import QRCodeComponent from '../../components/QRCodeComponent';
import { useTheme } from '../../components/themes';
import confirm from '../../helpers/confirm';
import prompt from '../../helpers/prompt';
import usePrivacy from '../../hooks/usePrivacy';
import { disallowScreenshot } from 'react-native-screen-capture';
import loc from '../../loc';
import { useStorage } from '../../hooks/context/useStorage';
import { scanQrHelper } from '../../helpers/scan-qr';
@ -60,15 +60,14 @@ const WalletsAddMultisigStep2 = () => {
const [askPassphrase, setAskPassphrase] = useState(false);
const openScannerButton = useRef();
const data = useRef(new Array(n));
const { enableBlur, disableBlur } = usePrivacy();
useFocusEffect(
useCallback(() => {
enableBlur();
disallowScreenshot(true);
return () => {
disableBlur();
disallowScreenshot(false);
};
}, [disableBlur, enableBlur]),
}, []),
);
useEffect(() => {

View file

@ -5,7 +5,7 @@ import { BlueButtonLink, BlueFormLabel, BlueFormMultiInput, BlueSpacing20 } from
import Button from '../../components/Button';
import { useTheme } from '../../components/themes';
import { scanQrHelper } from '../../helpers/scan-qr';
import usePrivacy from '../../hooks/usePrivacy';
import { disallowScreenshot } from 'react-native-screen-capture';
import loc from '../../loc';
import {
DoneAndDismissKeyboardInputAccessory,
@ -28,7 +28,6 @@ const WalletsImport = () => {
const [, setSpeedBackdoor] = useState(0);
const [searchAccounts, setSearchAccounts] = useState(false);
const [askPassphrase, setAskPassphrase] = useState(false);
const { enableBlur, disableBlur } = usePrivacy();
// Styles
const styles = StyleSheet.create({
@ -60,11 +59,11 @@ const WalletsImport = () => {
});
useEffect(() => {
enableBlur();
disallowScreenshot(true);
return () => {
disableBlur();
disallowScreenshot(false);
};
}, [disableBlur, enableBlur]);
}, []);
useEffect(() => {
if (triggerImport) importButtonPressed();

View file

@ -7,7 +7,7 @@ import CopyTextToClipboard from '../../components/CopyTextToClipboard';
import QRCodeComponent from '../../components/QRCodeComponent';
import SafeArea from '../../components/SafeArea';
import { useTheme } from '../../components/themes';
import usePrivacy from '../../hooks/usePrivacy';
import { disallowScreenshot } from 'react-native-screen-capture';
import loc from '../../loc';
import { useStorage } from '../../hooks/context/useStorage';
@ -18,7 +18,6 @@ const PleaseBackupLNDHub = () => {
const navigation = useNavigation();
const { colors } = useTheme();
const [qrCodeSize, setQRCodeSize] = useState(90);
const { enableBlur, disableBlur } = usePrivacy();
const handleBackButton = useCallback(() => {
navigation.getParent().pop();
@ -39,13 +38,13 @@ const PleaseBackupLNDHub = () => {
});
useEffect(() => {
enableBlur();
disallowScreenshot(true);
BackHandler.addEventListener('hardwareBackPress', handleBackButton);
return () => {
disableBlur();
disallowScreenshot(false);
BackHandler.removeEventListener('hardwareBackPress', handleBackButton);
};
}, [disableBlur, enableBlur, handleBackButton]);
}, [handleBackButton]);
const pop = () => navigation.getParent().pop();

View file

@ -8,7 +8,7 @@ import CopyTextToClipboard from '../../components/CopyTextToClipboard';
import HandOffComponent from '../../components/HandOffComponent';
import QRCodeComponent from '../../components/QRCodeComponent';
import SafeArea from '../../components/SafeArea';
import usePrivacy from '../../hooks/usePrivacy';
import { disallowScreenshot } from 'react-native-screen-capture';
import loc from '../../loc';
import { styles, useDynamicStyles } from './xpub.styles';
import { useStorage } from '../../hooks/context/useStorage';
@ -33,15 +33,14 @@ const WalletXpub: React.FC = () => {
const stylesHook = useDynamicStyles(); // This now includes the theme implicitly
const [qrCodeSize, setQRCodeSize] = useState<number>(90);
const lastWalletIdRef = useRef<string | undefined>();
const { enableBlur, disableBlur } = usePrivacy();
useFocusEffect(
useCallback(() => {
disallowScreenshot(true);
// Skip execution if walletID hasn't changed
if (lastWalletIdRef.current === walletID) {
return;
}
enableBlur();
const task = InteractionManager.runAfterInteractions(async () => {
if (wallet) {
const walletXpub = wallet.getXpub();
@ -57,9 +56,9 @@ const WalletXpub: React.FC = () => {
lastWalletIdRef.current = walletID;
return () => {
task.cancel();
disableBlur();
disallowScreenshot(false);
};
}, [walletID, enableBlur, wallet, xpub, navigation, disableBlur]),
}, [walletID, wallet, xpub, navigation]),
);
useEffect(() => {