mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-19 01:40:12 +01:00
Merge pull request #6418 from BlueWallet/SettingsContext
REF: SettingsContext
This commit is contained in:
commit
440e4d407e
@ -14,7 +14,7 @@ import About from './screen/settings/about';
|
||||
import DefaultView from './screen/settings/DefaultView';
|
||||
import ElectrumSettings from './screen/settings/electrumSettings';
|
||||
import EncryptStorage from './screen/settings/encryptStorage';
|
||||
import Language from './screen/settings/language';
|
||||
import Language from './screen/settings/Language';
|
||||
import LightningSettings from './screen/settings/lightningSettings';
|
||||
import NotificationSettings from './screen/settings/notificationSettings';
|
||||
import ReleaseNotes from './screen/settings/releasenotes';
|
||||
|
@ -13,10 +13,11 @@ import { BlueStorageContext } from './blue_modules/storage-context';
|
||||
import Notifications from './blue_modules/notifications';
|
||||
import { FiatUnit } from './models/fiatUnit';
|
||||
import { MultisigHDWallet } from './class';
|
||||
import { useSettings } from './components/Context/SettingsContext';
|
||||
|
||||
function WatchConnectivity() {
|
||||
const { walletsInitialized, wallets, fetchWalletTransactions, saveToDisk, txMetadata, preferredFiatCurrency } =
|
||||
useContext(BlueStorageContext);
|
||||
const { walletsInitialized, wallets, fetchWalletTransactions, saveToDisk, txMetadata } = useContext(BlueStorageContext);
|
||||
const { preferredFiatCurrency } = useSettings();
|
||||
const isReachable = useReachability();
|
||||
const isInstalled = useInstalled(); // true | false
|
||||
const messagesListenerActive = useRef(false);
|
||||
|
@ -1,15 +1,11 @@
|
||||
import React, { createContext, useEffect, useState } from 'react';
|
||||
import { useAsyncStorage } from '@react-native-async-storage/async-storage';
|
||||
|
||||
import React, { createContext, useContext, useEffect, useState } from 'react';
|
||||
import { startAndDecrypt } from './start-and-decrypt';
|
||||
import Notifications from '../blue_modules/notifications';
|
||||
import { LegacyWallet, TTXMetadata, WatchOnlyWallet, BlueApp as BlueAppClass } from '../class';
|
||||
import type { TWallet } from '../class/wallets/types';
|
||||
import presentAlert from '../components/Alert';
|
||||
import loc, { STORAGE_KEY as LOC_STORAGE_KEY } from '../loc';
|
||||
import { FiatUnit, TFiatUnit } from '../models/fiatUnit';
|
||||
import loc from '../loc';
|
||||
import * as BlueElectrum from './BlueElectrum';
|
||||
import { initCurrencyDaemon, PREFERRED_CURRENCY_STORAGE_KEY } from './currency';
|
||||
import triggerHapticFeedback, { HapticFeedbackTypes } from './hapticFeedback';
|
||||
import A from '../blue_modules/analytics';
|
||||
|
||||
@ -35,23 +31,13 @@ interface BlueStorageContextType {
|
||||
setWalletsInitialized: (initialized: boolean) => void;
|
||||
refreshAllWalletTransactions: (lastSnappedTo?: number, showUpdateStatusIndicator?: boolean) => Promise<void>;
|
||||
resetWallets: () => void;
|
||||
setPreferredFiatCurrency: () => void;
|
||||
preferredFiatCurrency: TFiatUnit;
|
||||
setLanguage: () => void;
|
||||
language: string | undefined;
|
||||
isHandOffUseEnabled: boolean;
|
||||
setIsHandOffUseEnabledAsyncStorage: (value: boolean) => Promise<void>;
|
||||
walletTransactionUpdateStatus: WalletTransactionsStatus | string;
|
||||
setWalletTransactionUpdateStatus: (status: WalletTransactionsStatus | string) => void;
|
||||
isElectrumDisabled: boolean;
|
||||
setIsElectrumDisabled: (value: boolean) => void;
|
||||
isPrivacyBlurEnabled: boolean;
|
||||
setIsPrivacyBlurEnabled: (value: boolean) => void;
|
||||
reloadTransactionsMenuActionFunction: () => void;
|
||||
setReloadTransactionsMenuActionFunction: (func: () => void) => void;
|
||||
|
||||
getTransactions: typeof BlueApp.getTransactions;
|
||||
isAdvancedModeEnabled: typeof BlueApp.isAdvancedModeEnabled;
|
||||
fetchWalletBalances: typeof BlueApp.fetchWalletBalances;
|
||||
fetchWalletTransactions: typeof BlueApp.fetchWalletTransactions;
|
||||
getBalance: typeof BlueApp.getBalance;
|
||||
@ -63,9 +49,6 @@ interface BlueStorageContextType {
|
||||
decryptStorage: typeof BlueApp.decryptStorage;
|
||||
isPasswordInUse: typeof BlueApp.isPasswordInUse;
|
||||
cachedPassword: typeof BlueApp.cachedPassword;
|
||||
setIsAdvancedModeEnabled: typeof BlueApp.setIsAdvancedModeEnabled;
|
||||
setDoNotTrack: typeof BlueApp.setDoNotTrack;
|
||||
isDoNotTrackEnabled: typeof BlueApp.isDoNotTrackEnabled;
|
||||
getItem: typeof BlueApp.getItem;
|
||||
setItem: typeof BlueApp.setItem;
|
||||
}
|
||||
@ -83,14 +66,8 @@ export const BlueStorageProvider = ({ children }: { children: React.ReactNode })
|
||||
WalletTransactionsStatus.NONE,
|
||||
);
|
||||
const [walletsInitialized, setWalletsInitialized] = useState<boolean>(false);
|
||||
const [preferredFiatCurrency, _setPreferredFiatCurrency] = useState<TFiatUnit>(FiatUnit.USD);
|
||||
const [language, _setLanguage] = useState<string | undefined>();
|
||||
const [isHandOffUseEnabled, setIsHandOffUseEnabled] = useState<boolean>(false);
|
||||
const [isElectrumDisabled, setIsElectrumDisabled] = useState<boolean>(true);
|
||||
const [isPrivacyBlurEnabled, setIsPrivacyBlurEnabled] = useState<boolean>(true);
|
||||
const [currentSharedCosigner, setCurrentSharedCosigner] = useState<string>('');
|
||||
const getPreferredCurrencyAsyncStorage = useAsyncStorage(PREFERRED_CURRENCY_STORAGE_KEY).getItem;
|
||||
const getLanguageAsyncStorage = useAsyncStorage(LOC_STORAGE_KEY).getItem;
|
||||
const [reloadTransactionsMenuActionFunction, setReloadTransactionsMenuActionFunction] = useState<() => void>(() => {});
|
||||
|
||||
useEffect(() => {
|
||||
@ -99,23 +76,10 @@ export const BlueStorageProvider = ({ children }: { children: React.ReactNode })
|
||||
|
||||
useEffect(() => {
|
||||
if (walletsInitialized) {
|
||||
initCurrencyDaemon();
|
||||
BlueElectrum.connectMain();
|
||||
}
|
||||
}, [walletsInitialized]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log(`Privacy blur: ${isPrivacyBlurEnabled}`);
|
||||
if (!isPrivacyBlurEnabled) {
|
||||
presentAlert({ message: 'Privacy blur has been disabled.' });
|
||||
}
|
||||
}, [isPrivacyBlurEnabled]);
|
||||
|
||||
const setIsHandOffUseEnabledAsyncStorage = (value: boolean) => {
|
||||
setIsHandOffUseEnabled(value);
|
||||
return BlueApp.setIsHandoffEnabled(value);
|
||||
};
|
||||
|
||||
const saveToDisk = async (force: boolean = false) => {
|
||||
if (BlueApp.getWallets().length === 0 && !force) {
|
||||
console.log('not saving empty wallets array');
|
||||
@ -131,47 +95,6 @@ export const BlueStorageProvider = ({ children }: { children: React.ReactNode })
|
||||
setWallets(BlueApp.getWallets());
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
try {
|
||||
const enabledHandoff = await BlueApp.isHandoffEnabled();
|
||||
setIsHandOffUseEnabled(!!enabledHandoff);
|
||||
} catch (_e) {
|
||||
setIsHandOffUseEnabledAsyncStorage(false);
|
||||
setIsHandOffUseEnabled(false);
|
||||
}
|
||||
})();
|
||||
}, []);
|
||||
|
||||
const getPreferredCurrency = async () => {
|
||||
// @ts-ignore TODO: fix this
|
||||
const item = JSON.parse(await getPreferredCurrencyAsyncStorage()) ?? FiatUnit.USD;
|
||||
_setPreferredFiatCurrency(item);
|
||||
return item;
|
||||
};
|
||||
|
||||
const setPreferredFiatCurrency = () => {
|
||||
getPreferredCurrency();
|
||||
};
|
||||
|
||||
const getLanguage = async () => {
|
||||
const item = await getLanguageAsyncStorage();
|
||||
if (item === null) {
|
||||
return;
|
||||
}
|
||||
_setLanguage(item);
|
||||
};
|
||||
|
||||
const setLanguage = () => {
|
||||
getLanguage();
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getPreferredCurrency();
|
||||
getLanguageAsyncStorage();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
const resetWallets = () => {
|
||||
setWallets(BlueApp.getWallets());
|
||||
};
|
||||
@ -272,7 +195,6 @@ export const BlueStorageProvider = ({ children }: { children: React.ReactNode })
|
||||
|
||||
let txMetadata = BlueApp.tx_metadata;
|
||||
const getTransactions = BlueApp.getTransactions;
|
||||
const isAdvancedModeEnabled = BlueApp.isAdvancedModeEnabled;
|
||||
const fetchWalletBalances = BlueApp.fetchWalletBalances;
|
||||
const fetchWalletTransactions = BlueApp.fetchWalletTransactions;
|
||||
const getBalance = BlueApp.getBalance;
|
||||
@ -283,9 +205,7 @@ export const BlueStorageProvider = ({ children }: { children: React.ReactNode })
|
||||
const decryptStorage = BlueApp.decryptStorage;
|
||||
const isPasswordInUse = BlueApp.isPasswordInUse;
|
||||
const cachedPassword = BlueApp.cachedPassword;
|
||||
const setIsAdvancedModeEnabled = BlueApp.setIsAdvancedModeEnabled;
|
||||
const setDoNotTrack = BlueApp.setDoNotTrack;
|
||||
const isDoNotTrackEnabled = BlueApp.isDoNotTrackEnabled;
|
||||
|
||||
const getItem = BlueApp.getItem;
|
||||
const setItem = BlueApp.setItem;
|
||||
|
||||
@ -304,7 +224,6 @@ export const BlueStorageProvider = ({ children }: { children: React.ReactNode })
|
||||
addAndSaveWallet,
|
||||
setItem,
|
||||
getItem,
|
||||
isAdvancedModeEnabled,
|
||||
fetchWalletBalances,
|
||||
fetchWalletTransactions,
|
||||
fetchAndSaveWalletTransactions,
|
||||
@ -321,24 +240,15 @@ export const BlueStorageProvider = ({ children }: { children: React.ReactNode })
|
||||
resetWallets,
|
||||
decryptStorage,
|
||||
isPasswordInUse,
|
||||
setIsAdvancedModeEnabled,
|
||||
setPreferredFiatCurrency,
|
||||
preferredFiatCurrency,
|
||||
setLanguage,
|
||||
language,
|
||||
isHandOffUseEnabled,
|
||||
setIsHandOffUseEnabledAsyncStorage,
|
||||
walletTransactionUpdateStatus,
|
||||
setWalletTransactionUpdateStatus,
|
||||
setDoNotTrack,
|
||||
isDoNotTrackEnabled,
|
||||
isElectrumDisabled,
|
||||
setIsElectrumDisabled,
|
||||
isPrivacyBlurEnabled,
|
||||
setIsPrivacyBlurEnabled,
|
||||
reloadTransactionsMenuActionFunction,
|
||||
setReloadTransactionsMenuActionFunction,
|
||||
};
|
||||
|
||||
return <BlueStorageContext.Provider value={value}>{children}</BlueStorageContext.Provider>;
|
||||
};
|
||||
|
||||
export const useStorage = () => useContext(BlueStorageContext);
|
||||
|
@ -9,12 +9,14 @@ import { formatBalance } from '../loc';
|
||||
import DeeplinkSchemaMatch from './deeplink-schema-match';
|
||||
import { TWallet } from './wallets/types';
|
||||
import useOnAppLaunch from '../hooks/useOnAppLaunch';
|
||||
import { useSettings } from '../components/Context/SettingsContext';
|
||||
|
||||
const DeviceQuickActionsStorageKey = 'DeviceQuickActionsEnabled';
|
||||
|
||||
function DeviceQuickActions(): JSX.Element | null {
|
||||
const { wallets, walletsInitialized, isStorageEncrypted, preferredFiatCurrency, addWallet, saveToDisk, setSharedCosigner } =
|
||||
useContext(BlueStorageContext);
|
||||
const { wallets, walletsInitialized, isStorageEncrypted, addWallet, saveToDisk, setSharedCosigner } = useContext(BlueStorageContext);
|
||||
const { preferredFiatCurrency } = useSettings();
|
||||
|
||||
const { isViewAllWalletsEnabled, getSelectedDefaultWallet } = useOnAppLaunch();
|
||||
|
||||
useEffect(() => {
|
||||
|
251
components/Context/SettingsContext.tsx
Normal file
251
components/Context/SettingsContext.tsx
Normal file
@ -0,0 +1,251 @@
|
||||
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';
|
||||
import { BlueApp } from '../../class';
|
||||
import presentAlert from '../Alert';
|
||||
import { STORAGE_KEY, saveLanguage } from '../../loc';
|
||||
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 DeviceQuickActions from '../../class/quick-actions';
|
||||
|
||||
interface SettingsContextType {
|
||||
preferredFiatCurrency: TFiatUnit;
|
||||
setPreferredFiatCurrencyStorage: (currency: TFiatUnit) => Promise<void>;
|
||||
language: string | undefined;
|
||||
setLanguageStorage: (language: string) => Promise<void>;
|
||||
isHandOffUseEnabled: boolean;
|
||||
setIsHandOffUseEnabledAsyncStorage: (value: boolean) => Promise<void>;
|
||||
isPrivacyBlurEnabled: boolean;
|
||||
setIsPrivacyBlurEnabledState: (value: boolean) => void;
|
||||
isAdvancedModeEnabled: boolean;
|
||||
setIsAdvancedModeEnabledStorage: (value: boolean) => Promise<void>;
|
||||
isDoNotTrackEnabled: boolean;
|
||||
setDoNotTrackStorage: (value: boolean) => Promise<void>;
|
||||
isWidgetBalanceDisplayAllowed: boolean;
|
||||
setIsWidgetBalanceDisplayAllowedStorage: (value: boolean) => Promise<void>;
|
||||
isLegacyURv1Enabled: boolean;
|
||||
setIsLegacyURv1EnabledStorage: (value: boolean) => Promise<void>;
|
||||
isClipboardGetContentEnabled: boolean;
|
||||
setIsClipboardGetContentEnabledStorage: (value: boolean) => Promise<void>;
|
||||
isQuickActionsEnabled: boolean;
|
||||
setIsQuickActionsEnabledStorage: (value: boolean) => Promise<void>;
|
||||
}
|
||||
|
||||
const defaultSettingsContext: SettingsContextType = {
|
||||
preferredFiatCurrency: FiatUnit.USD,
|
||||
setPreferredFiatCurrencyStorage: async () => {},
|
||||
language: 'en',
|
||||
setLanguageStorage: async () => {},
|
||||
isHandOffUseEnabled: false,
|
||||
setIsHandOffUseEnabledAsyncStorage: async () => {},
|
||||
isPrivacyBlurEnabled: true,
|
||||
setIsPrivacyBlurEnabledState: () => {},
|
||||
isAdvancedModeEnabled: false,
|
||||
setIsAdvancedModeEnabledStorage: async () => {},
|
||||
isDoNotTrackEnabled: false,
|
||||
setDoNotTrackStorage: async () => {},
|
||||
isWidgetBalanceDisplayAllowed: true,
|
||||
setIsWidgetBalanceDisplayAllowedStorage: async () => {},
|
||||
setIsLegacyURv1EnabledStorage: async () => {},
|
||||
isLegacyURv1Enabled: false,
|
||||
isClipboardGetContentEnabled: true,
|
||||
setIsClipboardGetContentEnabledStorage: async () => {},
|
||||
isQuickActionsEnabled: true,
|
||||
setIsQuickActionsEnabledStorage: async () => {},
|
||||
};
|
||||
|
||||
export const SettingsContext = createContext<SettingsContextType>(defaultSettingsContext);
|
||||
|
||||
export const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||
// FiatCurrency
|
||||
const [preferredFiatCurrency, setPreferredFiatCurrency] = useState<TFiatUnit>(FiatUnit.USD);
|
||||
// Language
|
||||
const [language, setLanguage] = useState<string>();
|
||||
// HandOff
|
||||
const [isHandOffUseEnabled, setIsHandOffUseEnabled] = useState<boolean>(false);
|
||||
// PrivacyBlur
|
||||
const [isPrivacyBlurEnabled, setIsPrivacyBlurEnabled] = useState<boolean>(true);
|
||||
// AdvancedMode
|
||||
const [isAdvancedModeEnabled, setIsAdvancedModeEnabled] = useState<boolean>(false);
|
||||
// DoNotTrack
|
||||
const [isDoNotTrackEnabled, setIsDoNotTrackEnabled] = useState<boolean>(false);
|
||||
// WidgetCommunication
|
||||
const [isWidgetBalanceDisplayAllowed, setIsWidgetBalanceDisplayAllowed] = useState<boolean>(true);
|
||||
// LegacyURv1
|
||||
const [isLegacyURv1Enabled, setIsLegacyURv1Enabled] = useState<boolean>(false);
|
||||
// Clipboard
|
||||
const [isClipboardGetContentEnabled, setIsClipboardGetContentEnabled] = useState<boolean>(false);
|
||||
// Quick Actions
|
||||
const [isQuickActionsEnabled, setIsQuickActionsEnabled] = useState<boolean>(true);
|
||||
|
||||
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();
|
||||
|
||||
useEffect(() => {
|
||||
const fetchSettings = async () => {
|
||||
const advMode = await advancedModeStorage.getItem();
|
||||
console.log('SettingsContext advMode:', advMode);
|
||||
const handOff = await isHandOffUseEnabledStorage.getItem();
|
||||
console.log('SettingsContext handOff:', handOff);
|
||||
const lang = (await languageStorage.getItem()) ?? 'en';
|
||||
console.log('SettingsContext lang:', lang);
|
||||
setIsAdvancedModeEnabled(advMode ? JSON.parse(advMode) : false);
|
||||
setIsHandOffUseEnabled(handOff ? JSON.parse(handOff) : false);
|
||||
const isBalanceDisplayAllowedStorage = await isBalanceDisplayAllowed();
|
||||
console.log('SettingsContext isBalanceDisplayAllowed:', isBalanceDisplayAllowedStorage);
|
||||
setIsWidgetBalanceDisplayAllowed(isBalanceDisplayAllowedStorage);
|
||||
setLanguage(lang);
|
||||
|
||||
const isURv1EnabledStorage = await isURv1Enabled();
|
||||
console.log('SettingsContext isURv1Enabled:', isURv1EnabledStorage);
|
||||
setIsLegacyURv1EnabledStorage(isURv1EnabledStorage);
|
||||
|
||||
const isClipboardGetContentEnabledStorage = await BlueClipboard().isReadClipboardAllowed();
|
||||
console.log('SettingsContext isClipboardGetContentEnabled:', isClipboardGetContentEnabledStorage);
|
||||
setIsClipboardGetContentEnabledStorage(isClipboardGetContentEnabledStorage);
|
||||
|
||||
// @ts-ignore: Fix later
|
||||
const isQuickActionsEnabledStorage = await DeviceQuickActions.getEnabled();
|
||||
console.log('SettingsContext isQuickActionsEnabled:', isQuickActionsEnabledStorage);
|
||||
setIsQuickActionsEnabledStorage(isQuickActionsEnabledStorage);
|
||||
};
|
||||
|
||||
fetchSettings();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (walletsInitialized) {
|
||||
initCurrencyDaemon().finally(() => {
|
||||
getPreferredCurrency().then(currency => {
|
||||
console.log('SettingsContext currency:', currency);
|
||||
setPreferredFiatCurrency(FiatUnit[currency.endPointKey]);
|
||||
});
|
||||
});
|
||||
}
|
||||
}, [walletsInitialized]);
|
||||
|
||||
const setPreferredFiatCurrencyStorage = useCallback(async (currency: TFiatUnit) => {
|
||||
await setPreferredFiatCurrency(currency);
|
||||
setPreferredFiatCurrency(currency);
|
||||
}, []);
|
||||
|
||||
const setLanguageStorage = useCallback(async (newLanguage: string) => {
|
||||
await saveLanguage(newLanguage);
|
||||
setLanguage(newLanguage);
|
||||
}, []);
|
||||
|
||||
const setIsAdvancedModeEnabledStorage = useCallback(
|
||||
async (value: boolean) => {
|
||||
await advancedModeStorage.setItem(JSON.stringify(value));
|
||||
setIsAdvancedModeEnabled(value);
|
||||
},
|
||||
[advancedModeStorage],
|
||||
);
|
||||
|
||||
const setDoNotTrackStorage = useCallback(
|
||||
async (value: boolean) => {
|
||||
await doNotTrackStorage.setItem(JSON.stringify(value));
|
||||
setIsDoNotTrackEnabled(value);
|
||||
},
|
||||
[doNotTrackStorage],
|
||||
);
|
||||
|
||||
const setIsHandOffUseEnabledAsyncStorage = useCallback(
|
||||
async (value: boolean) => {
|
||||
setIsHandOffUseEnabled(value);
|
||||
await isHandOffUseEnabledStorage.setItem;
|
||||
},
|
||||
[isHandOffUseEnabledStorage.setItem],
|
||||
);
|
||||
|
||||
const setIsWidgetBalanceDisplayAllowedStorage = useCallback(async (value: boolean) => {
|
||||
await setBalanceDisplayAllowed(value);
|
||||
setIsWidgetBalanceDisplayAllowed(value);
|
||||
}, []);
|
||||
|
||||
const setIsLegacyURv1EnabledStorage = useCallback(async (value: boolean) => {
|
||||
value ? await setUseURv1() : await clearUseURv1();
|
||||
await setIsLegacyURv1Enabled(value);
|
||||
}, []);
|
||||
|
||||
const setIsClipboardGetContentEnabledStorage = useCallback(async (value: boolean) => {
|
||||
await BlueClipboard().setReadClipboardAllowed(value);
|
||||
setIsClipboardGetContentEnabled(value);
|
||||
}, []);
|
||||
|
||||
const setIsQuickActionsEnabledStorage = useCallback(async (value: boolean) => {
|
||||
// @ts-ignore: Fix later
|
||||
await DeviceQuickActions.setEnabled(value);
|
||||
setIsQuickActionsEnabled(value);
|
||||
}, []);
|
||||
|
||||
const setIsPrivacyBlurEnabledState = useCallback(
|
||||
(value: boolean) => {
|
||||
setIsPrivacyBlurEnabled(value);
|
||||
console.log(`Privacy blur: ${isPrivacyBlurEnabled}`);
|
||||
if (!value) {
|
||||
presentAlert({ message: 'Privacy blur has been disabled.' });
|
||||
}
|
||||
},
|
||||
[isPrivacyBlurEnabled],
|
||||
);
|
||||
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
preferredFiatCurrency,
|
||||
setPreferredFiatCurrencyStorage,
|
||||
language,
|
||||
setLanguageStorage,
|
||||
isHandOffUseEnabled,
|
||||
setIsHandOffUseEnabledAsyncStorage,
|
||||
isPrivacyBlurEnabled,
|
||||
setIsPrivacyBlurEnabledState,
|
||||
isAdvancedModeEnabled,
|
||||
setIsAdvancedModeEnabledStorage,
|
||||
isDoNotTrackEnabled,
|
||||
setDoNotTrackStorage,
|
||||
isWidgetBalanceDisplayAllowed,
|
||||
setIsWidgetBalanceDisplayAllowedStorage,
|
||||
isLegacyURv1Enabled,
|
||||
setIsLegacyURv1EnabledStorage,
|
||||
isClipboardGetContentEnabled,
|
||||
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>;
|
||||
};
|
||||
|
||||
export const useSettings = () => useContext(SettingsContext);
|
@ -1,7 +1,7 @@
|
||||
import React, { useContext } from 'react';
|
||||
import React from 'react';
|
||||
// @ts-ignore: react-native-handoff is not in the type definition
|
||||
import Handoff from 'react-native-handoff';
|
||||
import { BlueStorageContext } from '../blue_modules/storage-context';
|
||||
import { useSettings } from './Context/SettingsContext';
|
||||
|
||||
interface HandOffComponentProps {
|
||||
url?: string;
|
||||
@ -19,7 +19,7 @@ interface HandOffComponentWithActivityTypes extends React.FC<HandOffComponentPro
|
||||
}
|
||||
|
||||
const HandOffComponent: HandOffComponentWithActivityTypes = props => {
|
||||
const { isHandOffUseEnabled } = useContext(BlueStorageContext);
|
||||
const { isHandOffUseEnabled } = useSettings();
|
||||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
console.log('HandOffComponent: props', props);
|
||||
|
@ -19,13 +19,15 @@ import TransactionOutgoingIcon from '../components/icons/TransactionOutgoingIcon
|
||||
import TransactionPendingIcon from '../components/icons/TransactionPendingIcon';
|
||||
import { useTheme } from './themes';
|
||||
import ListItem from './ListItem';
|
||||
import { useSettings } from './Context/SettingsContext';
|
||||
|
||||
export const TransactionListItem = React.memo(({ item, itemPriceUnit = BitcoinUnit.BTC, walletID }) => {
|
||||
const [subtitleNumberOfLines, setSubtitleNumberOfLines] = useState(1);
|
||||
const { colors } = useTheme();
|
||||
const { navigate } = useNavigation();
|
||||
const menuRef = useRef();
|
||||
const { txMetadata, wallets, preferredFiatCurrency, language } = useContext(BlueStorageContext);
|
||||
const { txMetadata, wallets } = useContext(BlueStorageContext);
|
||||
const { preferredFiatCurrency, language } = useSettings();
|
||||
const containerStyle = useMemo(
|
||||
() => ({
|
||||
backgroundColor: 'transparent',
|
||||
|
@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect, useRef, useContext, useCallback, useMemo } from 'react';
|
||||
import React, { useState, useEffect, useRef, useCallback, useMemo } from 'react';
|
||||
import { Image, Text, TouchableOpacity, View, I18nManager, StyleSheet, LayoutAnimation } from 'react-native';
|
||||
import Clipboard from '@react-native-clipboard/clipboard';
|
||||
import LinearGradient from 'react-native-linear-gradient';
|
||||
@ -6,11 +6,11 @@ import { HDSegwitBech32Wallet, LightningCustodianWallet, LightningLdkWallet, Mul
|
||||
import { BitcoinUnit } from '../models/bitcoinUnits';
|
||||
import WalletGradient from '../class/wallet-gradient';
|
||||
import loc, { formatBalance, formatBalanceWithoutSuffix } from '../loc';
|
||||
import { BlueStorageContext } from '../blue_modules/storage-context';
|
||||
import ToolTipMenu from './TooltipMenu';
|
||||
import { FiatUnit } from '../models/fiatUnit';
|
||||
import { TWallet } from '../class/wallets/types';
|
||||
import { BlurredBalanceView } from './BlurredBalanceView';
|
||||
import { useSettings } from './Context/SettingsContext';
|
||||
|
||||
interface TransactionsNavigationHeaderProps {
|
||||
wallet: TWallet;
|
||||
@ -43,8 +43,8 @@ const TransactionsNavigationHeader: React.FC<TransactionsNavigationHeaderProps>
|
||||
}) => {
|
||||
const [wallet, setWallet] = useState(initialWallet);
|
||||
const [allowOnchainAddress, setAllowOnchainAddress] = useState(false);
|
||||
const { preferredFiatCurrency } = useSettings();
|
||||
|
||||
const { preferredFiatCurrency } = useContext(BlueStorageContext);
|
||||
const menuRef = useRef(null);
|
||||
|
||||
const verifyIfWalletAllowsOnchainAddress = useCallback(() => {
|
||||
|
@ -24,6 +24,7 @@ import { BlueStorageContext, WalletTransactionsStatus } from '../blue_modules/st
|
||||
import { isTablet, isDesktop } from '../blue_modules/environment';
|
||||
import { useTheme } from './themes';
|
||||
import { BlurredBalanceView } from './BlurredBalanceView';
|
||||
import { useSettings } from './Context/SettingsContext';
|
||||
|
||||
const nStyles = StyleSheet.create({
|
||||
container: {
|
||||
@ -276,7 +277,7 @@ const cStyles = StyleSheet.create({
|
||||
const ListHeaderComponent = () => <View style={cStyles.separatorStyle} />;
|
||||
|
||||
const WalletsCarousel = forwardRef((props, ref) => {
|
||||
const { preferredFiatCurrency, language } = useContext(BlueStorageContext);
|
||||
const { preferredFiatCurrency, language } = useSettings();
|
||||
const { horizontal, data, handleLongPress, onPress, selectedWallet } = props;
|
||||
const renderItem = useCallback(
|
||||
({ item, index }) =>
|
||||
|
@ -1,9 +1,10 @@
|
||||
import React, { useContext, useEffect } from 'react';
|
||||
import DefaultPreference from 'react-native-default-preference';
|
||||
// @ts-ignore: fix later
|
||||
// @ts-ignore: no type definitions
|
||||
import RNWidgetCenter from 'react-native-widget-center';
|
||||
import { BlueStorageContext } from '../blue_modules/storage-context';
|
||||
import { TWallet } from '../class/wallets/types';
|
||||
import { useSettings } from './Context/SettingsContext';
|
||||
|
||||
enum WidgetCommunicationKeys {
|
||||
AllWalletsSatoshiBalance = 'WidgetCommunicationAllWalletsSatoshiBalance',
|
||||
@ -18,6 +19,7 @@ export const reloadAllTimelines = (): void => {
|
||||
|
||||
export const isBalanceDisplayAllowed = async (): Promise<boolean> => {
|
||||
try {
|
||||
await DefaultPreference.setName('group.io.bluewallet.bluewallet');
|
||||
const displayBalance = await DefaultPreference.get(WidgetCommunicationKeys.DisplayBalanceAllowed);
|
||||
return displayBalance === '1';
|
||||
} catch {
|
||||
@ -26,6 +28,7 @@ export const isBalanceDisplayAllowed = async (): Promise<boolean> => {
|
||||
};
|
||||
|
||||
export const setBalanceDisplayAllowed = async (value: boolean): Promise<void> => {
|
||||
await DefaultPreference.setName('group.io.bluewallet.bluewallet');
|
||||
if (value) {
|
||||
await DefaultPreference.set(WidgetCommunicationKeys.DisplayBalanceAllowed, '1');
|
||||
} else {
|
||||
@ -34,45 +37,45 @@ export const setBalanceDisplayAllowed = async (value: boolean): Promise<void> =>
|
||||
reloadAllTimelines();
|
||||
};
|
||||
|
||||
export const syncWidgetBalanceWithWallets = async (wallets: TWallet[], walletsInitialized: boolean): Promise<void> => {
|
||||
await DefaultPreference.setName('group.io.bluewallet.bluewallet');
|
||||
const { allWalletsBalance, latestTransactionTime } = await allWalletsBalanceAndTransactionTime(wallets, walletsInitialized);
|
||||
await DefaultPreference.set(WidgetCommunicationKeys.AllWalletsSatoshiBalance, String(allWalletsBalance));
|
||||
await DefaultPreference.set(WidgetCommunicationKeys.AllWalletsLatestTransactionTime, String(latestTransactionTime));
|
||||
reloadAllTimelines();
|
||||
};
|
||||
|
||||
const allWalletsBalanceAndTransactionTime = async (
|
||||
wallets: TWallet[],
|
||||
walletsInitialized: boolean,
|
||||
): Promise<{ allWalletsBalance: number; latestTransactionTime: number | string }> => {
|
||||
if (!walletsInitialized || !(await isBalanceDisplayAllowed())) {
|
||||
return { allWalletsBalance: 0, latestTransactionTime: 0 };
|
||||
}
|
||||
let balance = 0;
|
||||
let latestTransactionTime: number | string = 0;
|
||||
wallets.forEach((wallet: TWallet) => {
|
||||
if (wallet.hideBalance) return;
|
||||
balance += wallet.getBalance();
|
||||
const walletLatestTime = wallet.getLatestTransactionTimeEpoch();
|
||||
if (typeof latestTransactionTime === 'number' && walletLatestTime > latestTransactionTime) {
|
||||
latestTransactionTime =
|
||||
wallet.getTransactions()[0]?.confirmations === 0 ? WidgetCommunicationKeys.LatestTransactionIsUnconfirmed : walletLatestTime;
|
||||
}
|
||||
});
|
||||
|
||||
return { allWalletsBalance: balance, latestTransactionTime };
|
||||
};
|
||||
|
||||
const WidgetCommunication: React.FC = () => {
|
||||
const { wallets, walletsInitialized } = useContext(BlueStorageContext);
|
||||
const { isWidgetBalanceDisplayAllowed } = useSettings();
|
||||
|
||||
useEffect(() => {
|
||||
const allWalletsBalanceAndTransactionTime = async (): Promise<{
|
||||
allWalletsBalance: number;
|
||||
latestTransactionTime: number | string;
|
||||
}> => {
|
||||
if (!walletsInitialized || !(await isBalanceDisplayAllowed())) {
|
||||
return { allWalletsBalance: 0, latestTransactionTime: 0 };
|
||||
} else {
|
||||
let balance = 0;
|
||||
let latestTransactionTime: number | string = 0;
|
||||
wallets.forEach((wallet: TWallet) => {
|
||||
if (wallet.hideBalance) return;
|
||||
balance += wallet.getBalance();
|
||||
const walletLatestTime = wallet.getLatestTransactionTimeEpoch();
|
||||
|
||||
if (typeof latestTransactionTime === 'number' && walletLatestTime > latestTransactionTime) {
|
||||
latestTransactionTime =
|
||||
wallet.getTransactions()[0]?.confirmations === 0 ? WidgetCommunicationKeys.LatestTransactionIsUnconfirmed : walletLatestTime;
|
||||
}
|
||||
});
|
||||
return { allWalletsBalance: balance, latestTransactionTime };
|
||||
}
|
||||
};
|
||||
|
||||
const setValues = async (): Promise<void> => {
|
||||
await DefaultPreference.setName('group.io.bluewallet.bluewallet');
|
||||
const { allWalletsBalance, latestTransactionTime } = await allWalletsBalanceAndTransactionTime();
|
||||
await DefaultPreference.set(WidgetCommunicationKeys.AllWalletsSatoshiBalance, String(allWalletsBalance));
|
||||
await DefaultPreference.set(WidgetCommunicationKeys.AllWalletsLatestTransactionTime, String(latestTransactionTime));
|
||||
reloadAllTimelines();
|
||||
};
|
||||
|
||||
if (walletsInitialized) {
|
||||
setValues();
|
||||
syncWidgetBalanceWithWallets(wallets, walletsInitialized);
|
||||
}
|
||||
}, [wallets, walletsInitialized]);
|
||||
}, [wallets, walletsInitialized, isWidgetBalanceDisplayAllowed]);
|
||||
|
||||
return null;
|
||||
};
|
||||
|
@ -1,4 +1,5 @@
|
||||
import React from 'react';
|
||||
import { TWallet } from '../class/wallets/types';
|
||||
|
||||
export const isBalanceDisplayAllowed = async (): Promise<boolean> => {
|
||||
return true;
|
||||
@ -8,6 +9,8 @@ export const setBalanceDisplayAllowed = async (value: boolean): Promise<void> =>
|
||||
|
||||
export const reloadAllTimelines = (): void => {};
|
||||
|
||||
export const syncWidgetBalanceWithWallets = async (_wallets: TWallet[], _walletsInitialized: boolean): Promise<void> => {};
|
||||
|
||||
const WidgetCommunication: React.FC = () => {
|
||||
return null; // This component does not render anything.
|
||||
};
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { useContext, useEffect, useCallback } from 'react';
|
||||
import { useEffect, useCallback } from 'react';
|
||||
// @ts-ignore: react-native-obscure is not in the type definition
|
||||
import Obscure from 'react-native-obscure';
|
||||
import { BlueStorageContext } from '../blue_modules/storage-context';
|
||||
import { useSettings } from '../components/Context/SettingsContext';
|
||||
|
||||
export const usePrivacy = () => {
|
||||
const { isPrivacyBlurEnabled } = useContext(BlueStorageContext);
|
||||
const { isPrivacyBlurEnabled } = useSettings();
|
||||
|
||||
const enableBlur = useCallback(() => {
|
||||
if (!isPrivacyBlurEnabled) return;
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { useContext, useEffect, useCallback } from 'react';
|
||||
import { useEffect, useCallback } from 'react';
|
||||
// @ts-ignore: react-native-obscure is not in the type definition
|
||||
import { enabled } from 'react-native-privacy-snapshot';
|
||||
import { BlueStorageContext } from '../blue_modules/storage-context';
|
||||
import { useSettings } from '../components/Context/SettingsContext';
|
||||
|
||||
export const usePrivacy = () => {
|
||||
const { isPrivacyBlurEnabled } = useContext(BlueStorageContext);
|
||||
const { isPrivacyBlurEnabled } = useSettings();
|
||||
|
||||
const enableBlur = useCallback(() => {
|
||||
if (!isPrivacyBlurEnabled) return;
|
||||
|
5
index.js
5
index.js
@ -6,6 +6,7 @@ import { AppRegistry } from 'react-native';
|
||||
import App from './App';
|
||||
import { BlueStorageProvider } from './blue_modules/storage-context';
|
||||
import A from './blue_modules/analytics';
|
||||
import { SettingsProvider } from './components/Context/SettingsContext';
|
||||
|
||||
if (!Error.captureStackTrace) {
|
||||
// captureStackTrace is only available when debugging
|
||||
@ -19,7 +20,9 @@ const BlueAppComponent = () => {
|
||||
|
||||
return (
|
||||
<BlueStorageProvider>
|
||||
<App />
|
||||
<SettingsProvider>
|
||||
<App />
|
||||
</SettingsProvider>
|
||||
</BlueStorageProvider>
|
||||
);
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useNavigation } from '@react-navigation/native';
|
||||
import dayjs from 'dayjs';
|
||||
import React, { useContext, useLayoutEffect, useState } from 'react';
|
||||
import React, { useLayoutEffect, useState } from 'react';
|
||||
import { FlatList, NativeSyntheticEvent, StyleSheet, View } from 'react-native';
|
||||
import { BlueCard, BlueSpacing10, BlueText } from '../../BlueComponents';
|
||||
import {
|
||||
@ -10,16 +10,16 @@ import {
|
||||
mostRecentFetchedRate,
|
||||
setPreferredCurrency,
|
||||
} from '../../blue_modules/currency';
|
||||
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
||||
import presentAlert from '../../components/Alert';
|
||||
import ListItem from '../../components/ListItem';
|
||||
import { useTheme } from '../../components/themes';
|
||||
import loc from '../../loc';
|
||||
import { FiatUnit, FiatUnitSource, FiatUnitType, getFiatRate } from '../../models/fiatUnit';
|
||||
import { useSettings } from '../../components/Context/SettingsContext';
|
||||
dayjs.extend(require('dayjs/plugin/calendar'));
|
||||
|
||||
const Currency = () => {
|
||||
const { setPreferredFiatCurrency } = useContext(BlueStorageContext);
|
||||
const { setPreferredFiatCurrencyStorage } = useSettings();
|
||||
const [isSavingNewPreferredCurrency, setIsSavingNewPreferredCurrency] = useState(false);
|
||||
const [selectedCurrency, setSelectedCurrency] = useState<FiatUnitType>(FiatUnit.USD);
|
||||
const [currencyRate, setCurrencyRate] = useState<CurrencyRate>({ LastUpdated: null, Rate: null });
|
||||
@ -74,7 +74,7 @@ const Currency = () => {
|
||||
await initCurrencyDaemon(true);
|
||||
await fetchCurrency();
|
||||
setSelectedCurrency(item);
|
||||
setPreferredFiatCurrency();
|
||||
setPreferredFiatCurrencyStorage(FiatUnit[item.endPointKey]);
|
||||
} catch (error: any) {
|
||||
console.log(error);
|
||||
presentAlert({
|
||||
|
@ -1,13 +1,13 @@
|
||||
import React, { useContext, useEffect, useState } from 'react';
|
||||
import React, { useContext } from 'react';
|
||||
import { Platform, ScrollView, StyleSheet } from 'react-native';
|
||||
|
||||
import { useNavigation } from '@react-navigation/native';
|
||||
import { BlueCard, BlueLoading, BlueSpacing20, BlueText } from '../../BlueComponents';
|
||||
import { BlueCard, BlueSpacing20, BlueText } from '../../BlueComponents';
|
||||
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
||||
import { clearUseURv1, isURv1Enabled, setUseURv1 } from '../../blue_modules/ur';
|
||||
import ListItem, { PressableWrapper } from '../../components/ListItem';
|
||||
import { useTheme } from '../../components/themes';
|
||||
import loc from '../../loc';
|
||||
import { useSettings } from '../../components/Context/SettingsContext';
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
root: {
|
||||
@ -16,29 +16,17 @@ const styles = StyleSheet.create({
|
||||
});
|
||||
|
||||
const GeneralSettings: React.FC = () => {
|
||||
const { isAdvancedModeEnabled, setIsAdvancedModeEnabled, wallets, isHandOffUseEnabled, setIsHandOffUseEnabledAsyncStorage } =
|
||||
useContext(BlueStorageContext);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [isAdvancedModeSwitchEnabled, setIsAdvancedModeSwitchEnabled] = useState(false);
|
||||
const [isURv1SwitchEnabled, setIsURv1SwitchEnabled] = useState(false);
|
||||
const { wallets } = useContext(BlueStorageContext);
|
||||
const {
|
||||
isAdvancedModeEnabled,
|
||||
setIsAdvancedModeEnabledStorage,
|
||||
isHandOffUseEnabled,
|
||||
setIsHandOffUseEnabledAsyncStorage,
|
||||
isLegacyURv1Enabled,
|
||||
setIsLegacyURv1EnabledStorage,
|
||||
} = useSettings();
|
||||
const { navigate } = useNavigation();
|
||||
const { colors } = useTheme();
|
||||
const onAdvancedModeSwitch = async (value: boolean) => {
|
||||
await setIsAdvancedModeEnabled(value);
|
||||
setIsAdvancedModeSwitchEnabled(value);
|
||||
};
|
||||
const onLegacyURv1Switch = async (value: boolean) => {
|
||||
setIsURv1SwitchEnabled(value);
|
||||
return value ? setUseURv1() : clearUseURv1();
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
setIsAdvancedModeSwitchEnabled(await isAdvancedModeEnabled());
|
||||
setIsURv1SwitchEnabled(await isURv1Enabled());
|
||||
setIsLoading(false);
|
||||
})();
|
||||
});
|
||||
|
||||
const navigateToPrivacy = () => {
|
||||
// @ts-ignore: Fix later
|
||||
@ -51,9 +39,7 @@ const GeneralSettings: React.FC = () => {
|
||||
},
|
||||
};
|
||||
|
||||
return isLoading ? (
|
||||
<BlueLoading />
|
||||
) : (
|
||||
return (
|
||||
<ScrollView style={[styles.root, stylesWithThemeHook.root]}>
|
||||
{wallets.length > 1 && (
|
||||
<>
|
||||
@ -79,7 +65,7 @@ const GeneralSettings: React.FC = () => {
|
||||
<ListItem
|
||||
Component={PressableWrapper}
|
||||
title={loc.settings.general_adv_mode}
|
||||
switch={{ onValueChange: onAdvancedModeSwitch, value: isAdvancedModeSwitchEnabled, testID: 'AdvancedMode' }}
|
||||
switch={{ onValueChange: setIsAdvancedModeEnabledStorage, value: isAdvancedModeEnabled, testID: 'AdvancedMode' }}
|
||||
/>
|
||||
<BlueCard>
|
||||
<BlueText>{loc.settings.general_adv_mode_e}</BlueText>
|
||||
@ -88,7 +74,7 @@ const GeneralSettings: React.FC = () => {
|
||||
<ListItem
|
||||
Component={PressableWrapper}
|
||||
title="Legacy URv1 QR"
|
||||
switch={{ onValueChange: onLegacyURv1Switch, value: isURv1SwitchEnabled }}
|
||||
switch={{ onValueChange: setIsLegacyURv1EnabledStorage, value: isLegacyURv1Enabled }}
|
||||
/>
|
||||
<BlueSpacing20 />
|
||||
</ScrollView>
|
||||
|
@ -1,14 +1,14 @@
|
||||
import { useNavigation } from '@react-navigation/native';
|
||||
import React, { useContext, useEffect, useState } from 'react';
|
||||
import React, { useEffect } from 'react';
|
||||
import { FlatList, StyleSheet } from 'react-native';
|
||||
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
||||
|
||||
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
||||
import presentAlert from '../../components/Alert';
|
||||
import ListItem from '../../components/ListItem';
|
||||
import { useTheme } from '../../components/themes';
|
||||
import loc, { saveLanguage } from '../../loc';
|
||||
import loc from '../../loc';
|
||||
import { AvailableLanguages, TLanguage } from '../../loc/languages';
|
||||
import { useSettings } from '../../components/Context/SettingsContext';
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
flex: {
|
||||
@ -17,8 +17,7 @@ const styles = StyleSheet.create({
|
||||
});
|
||||
|
||||
const Language = () => {
|
||||
const { setLanguage, language } = useContext(BlueStorageContext);
|
||||
const [selectedLanguage, setSelectedLanguage] = useState<string>(loc.getLanguage());
|
||||
const { setLanguageStorage, language } = useSettings();
|
||||
const { setOptions } = useNavigation();
|
||||
const { colors } = useTheme();
|
||||
const insets = useSafeAreaInsets();
|
||||
@ -37,10 +36,8 @@ const Language = () => {
|
||||
}, [language]);
|
||||
|
||||
const onLanguageSelect = (item: TLanguage) => {
|
||||
const currentLanguage = AvailableLanguages.find(l => l.value === selectedLanguage);
|
||||
saveLanguage(item.value).then(() => {
|
||||
setSelectedLanguage(item.value);
|
||||
setLanguage();
|
||||
const currentLanguage = AvailableLanguages.find(l => l.value === language);
|
||||
setLanguageStorage(item.value).then(() => {
|
||||
if (currentLanguage?.isRTL !== item.isRTL) {
|
||||
presentAlert({ message: loc.settings.language_isRTL });
|
||||
}
|
||||
@ -48,7 +45,7 @@ const Language = () => {
|
||||
};
|
||||
|
||||
const renderItem = ({ item }: { item: TLanguage }) => {
|
||||
return <ListItem title={item.label} checkmark={selectedLanguage === item.value} onPress={() => onLanguageSelect(item)} />;
|
||||
return <ListItem title={item.label} checkmark={language === item.value} onPress={() => onLanguageSelect(item)} />;
|
||||
};
|
||||
|
||||
return (
|
@ -1,10 +1,10 @@
|
||||
import React, { useContext } from 'react';
|
||||
import React from 'react';
|
||||
import { ScrollView, StyleSheet, Platform } from 'react-native';
|
||||
import { BlueHeaderDefaultSub } from '../../BlueComponents';
|
||||
import loc from '../../loc';
|
||||
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
||||
import ListItem from '../../components/ListItem';
|
||||
import { useExtendedNavigation } from '../../hooks/useExtendedNavigation';
|
||||
import { useSettings } from '../../components/Context/SettingsContext';
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
root: {
|
||||
@ -22,7 +22,7 @@ const Settings = () => {
|
||||
const { navigate } = useExtendedNavigation();
|
||||
// By simply having it here, it'll re-render the UI if language is changed
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { language } = useContext(BlueStorageContext);
|
||||
const { language } = useSettings();
|
||||
|
||||
return (
|
||||
<ScrollView
|
||||
|
@ -5,24 +5,29 @@ 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 BlueClipboard from '../../blue_modules/clipboard';
|
||||
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
||||
import { isBalanceDisplayAllowed, setBalanceDisplayAllowed } from '../../components/WidgetCommunication';
|
||||
import { useTheme } from '../../components/themes';
|
||||
import ListItem from '../../components/ListItem';
|
||||
import A from '../../blue_modules/analytics';
|
||||
import { useSettings } from '../../components/Context/SettingsContext';
|
||||
|
||||
const SettingsPrivacy = () => {
|
||||
const { colors } = useTheme();
|
||||
const { isStorageEncrypted, isDoNotTrackEnabled, setDoNotTrack, setIsPrivacyBlurEnabled } = useContext(BlueStorageContext);
|
||||
const { isStorageEncrypted } = useContext(BlueStorageContext);
|
||||
const {
|
||||
isDoNotTrackEnabled,
|
||||
setDoNotTrackStorage,
|
||||
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 [isReadClipboardAllowed, setIsReadClipboardAllowed] = useState(false);
|
||||
const [doNotTrackSwitchValue, setDoNotTrackSwitchValue] = useState(false);
|
||||
|
||||
const [isDisplayWidgetBalanceAllowed, setIsDisplayWidgetBalanceAllowed] = useState(false);
|
||||
const [isQuickActionsEnabled, setIsQuickActionsEnabled] = useState(false);
|
||||
const [storageIsEncrypted, setStorageIsEncrypted] = useState(true);
|
||||
const [isPrivacyBlurEnabledTapped, setIsPrivacyBlurEnabledTapped] = useState(0);
|
||||
const styleHooks = StyleSheet.create({
|
||||
@ -34,11 +39,7 @@ const SettingsPrivacy = () => {
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
try {
|
||||
isDoNotTrackEnabled().then(setDoNotTrackSwitchValue);
|
||||
setIsReadClipboardAllowed(await BlueClipboard().isReadClipboardAllowed());
|
||||
setStorageIsEncrypted(await isStorageEncrypted());
|
||||
setIsQuickActionsEnabled(await DeviceQuickActions.getEnabled());
|
||||
setIsDisplayWidgetBalanceAllowed(await isBalanceDisplayAllowed());
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
@ -47,23 +48,11 @@ const SettingsPrivacy = () => {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
const onValueChange = async value => {
|
||||
setIsLoading(sections.CLIPBOARDREAD);
|
||||
try {
|
||||
await BlueClipboard().setReadClipboardAllowed(value);
|
||||
setIsReadClipboardAllowed(value);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
setIsLoading(false);
|
||||
};
|
||||
|
||||
const onDoNotTrackValueChange = async value => {
|
||||
setIsLoading(sections.ALL);
|
||||
try {
|
||||
await setDoNotTrack(value);
|
||||
setDoNotTrackStorage(value);
|
||||
A.setOptOut(value);
|
||||
setDoNotTrackSwitchValue(value);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
@ -73,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);
|
||||
}
|
||||
@ -84,8 +72,7 @@ const SettingsPrivacy = () => {
|
||||
const onWidgetsTotalBalanceValueChange = async value => {
|
||||
setIsLoading(sections.WIDGETS);
|
||||
try {
|
||||
await setBalanceDisplayAllowed(value);
|
||||
setIsDisplayWidgetBalanceAllowed(value);
|
||||
setIsWidgetBalanceDisplayAllowedStorage(value);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
@ -103,23 +90,28 @@ 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>
|
||||
{Platform.OS === 'android' ? <BlueHeaderDefaultSub leftText={loc.settings.general} /> : <></>}
|
||||
<ListItem
|
||||
hideChevron
|
||||
title={loc.settings.privacy_read_clipboard}
|
||||
Component={TouchableWithoutFeedback}
|
||||
switch={{ onValueChange, value: isReadClipboardAllowed, disabled: isLoading === sections.ALL, testID: 'ClipboardSwitch' }}
|
||||
switch={{
|
||||
onValueChange: setIsClipboardGetContentEnabledStorage,
|
||||
value: isClipboardGetContentEnabled,
|
||||
disabled: isLoading === sections.ALL,
|
||||
testID: 'ClipboardSwitch',
|
||||
}}
|
||||
/>
|
||||
<BlueCard>
|
||||
<BlueText>{loc.settings.privacy_clipboard_explanation}</BlueText>
|
||||
<Pressable accessibilityRole="button" onPress={onDisablePrivacyTapped}>
|
||||
<BlueText>{loc.settings.privacy_clipboard_explanation}</BlueText>
|
||||
</Pressable>
|
||||
</BlueCard>
|
||||
<BlueSpacing20 />
|
||||
{!storageIsEncrypted && (
|
||||
@ -144,7 +136,7 @@ const SettingsPrivacy = () => {
|
||||
hideChevron
|
||||
title={loc.settings.privacy_do_not_track}
|
||||
Component={TouchableWithoutFeedback}
|
||||
switch={{ onValueChange: onDoNotTrackValueChange, value: doNotTrackSwitchValue, disabled: isLoading === sections.ALL }}
|
||||
switch={{ onValueChange: onDoNotTrackValueChange, value: isDoNotTrackEnabled, disabled: isLoading === sections.ALL }}
|
||||
/>
|
||||
<BlueCard>
|
||||
<BlueText>{loc.settings.privacy_do_not_track_explanation}</BlueText>
|
||||
@ -161,7 +153,7 @@ const SettingsPrivacy = () => {
|
||||
Component={TouchableWithoutFeedback}
|
||||
switch={{
|
||||
onValueChange: onWidgetsTotalBalanceValueChange,
|
||||
value: isDisplayWidgetBalanceAllowed,
|
||||
value: isWidgetBalanceDisplayAllowed,
|
||||
disabled: isLoading === sections.ALL,
|
||||
}}
|
||||
/>
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useFocusEffect } from '@react-navigation/native';
|
||||
import { NativeStackScreenProps } from '@react-navigation/native-stack';
|
||||
import React, { useCallback, useContext, useEffect, useRef, useState } from 'react';
|
||||
import React, { useCallback, useContext, useRef, useState } from 'react';
|
||||
import {
|
||||
ActivityIndicator,
|
||||
Alert,
|
||||
@ -55,13 +55,15 @@ import ActionSheet from '../ActionSheet';
|
||||
import SaveFileButton from '../../components/SaveFileButton';
|
||||
import { useExtendedNavigation } from '../../hooks/useExtendedNavigation';
|
||||
import prompt from '../../helpers/prompt';
|
||||
import { useSettings } from '../../components/Context/SettingsContext';
|
||||
|
||||
type Props = NativeStackScreenProps<ViewEditMultisigCosignersStackParamsList, 'ViewEditMultisigCosigners'>;
|
||||
|
||||
const ViewEditMultisigCosigners = ({ route }: Props) => {
|
||||
const hasLoaded = useRef(false);
|
||||
const { colors } = useTheme();
|
||||
const { wallets, setWalletsWithNewOrder, isElectrumDisabled, isAdvancedModeEnabled } = useContext(BlueStorageContext);
|
||||
const { wallets, setWalletsWithNewOrder, isElectrumDisabled } = useContext(BlueStorageContext);
|
||||
const { isAdvancedModeEnabled } = useSettings();
|
||||
const { navigate, dispatch, addListener } = useExtendedNavigation();
|
||||
const openScannerButtonRef = useRef();
|
||||
const { walletId } = route.params;
|
||||
@ -80,7 +82,6 @@ const ViewEditMultisigCosigners = ({ route }: Props) => {
|
||||
const [exportFilename, setExportFilename] = useState('bw-cosigner.json');
|
||||
const [vaultKeyData, setVaultKeyData] = useState({ keyIndex: 1, xpub: '', seed: '', passphrase: '', path: '', fp: '', isLoading: false }); // string rendered in modal
|
||||
const [askPassphrase, setAskPassphrase] = useState(false);
|
||||
const [isAdvancedModeEnabledRender, setIsAdvancedModeEnabledRender] = useState(false);
|
||||
const data = useRef<any[]>();
|
||||
/* discardChangesRef is only so the action sheet can be shown on mac catalyst when a
|
||||
user tries to leave the screen with unsaved changes.
|
||||
@ -167,11 +168,6 @@ const ViewEditMultisigCosigners = ({ route }: Props) => {
|
||||
}, [isSaveButtonDisabled, addListener, dispatch]),
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
isAdvancedModeEnabled().then(setIsAdvancedModeEnabledRender);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
const saveFileButtonAfterOnPress = () => {
|
||||
setIsShareModalVisible(false);
|
||||
};
|
||||
@ -546,7 +542,7 @@ const ViewEditMultisigCosigners = ({ route }: Props) => {
|
||||
<BlueTextCentered>{loc.multisig.type_your_mnemonics}</BlueTextCentered>
|
||||
<BlueSpacing20 />
|
||||
<BlueFormMultiInput value={importText} onChangeText={setImportText} />
|
||||
{isAdvancedModeEnabledRender && (
|
||||
{isAdvancedModeEnabled && (
|
||||
<>
|
||||
<BlueSpacing10 />
|
||||
<View style={styles.row}>
|
||||
|
@ -31,11 +31,11 @@ import Button from '../../components/Button';
|
||||
import { LdkButton } from '../../components/LdkButton';
|
||||
import ListItem from '../../components/ListItem';
|
||||
import { useTheme } from '../../components/themes';
|
||||
import useAsyncPromise from '../../hooks/useAsyncPromise';
|
||||
import loc from '../../loc';
|
||||
import { Chain } from '../../models/bitcoinUnits';
|
||||
import WalletButton from '../../components/WalletButton';
|
||||
import A from '../../blue_modules/analytics';
|
||||
import { useSettings } from '../../components/Context/SettingsContext';
|
||||
|
||||
enum ButtonSelected {
|
||||
// @ts-ignore: Return later to update
|
||||
@ -123,8 +123,8 @@ const WalletsAdd: React.FC = () => {
|
||||
const entropyButtonText = state.entropyButtonText;
|
||||
//
|
||||
const colorScheme = useColorScheme();
|
||||
const { addWallet, saveToDisk, isAdvancedModeEnabled, wallets } = useContext(BlueStorageContext);
|
||||
const isAdvancedOptionsEnabled = useAsyncPromise(isAdvancedModeEnabled);
|
||||
const { addWallet, saveToDisk, wallets } = useContext(BlueStorageContext);
|
||||
const { isAdvancedModeEnabled } = useSettings();
|
||||
const { navigate, goBack, setOptions } = useNavigation();
|
||||
const stylesHook = {
|
||||
advancedText: {
|
||||
@ -423,7 +423,7 @@ const WalletsAdd: React.FC = () => {
|
||||
|
||||
<View style={styles.advanced}>
|
||||
{(() => {
|
||||
if (selectedWalletType === ButtonSelected.ONCHAIN && isAdvancedOptionsEnabled.data) {
|
||||
if (selectedWalletType === ButtonSelected.ONCHAIN && isAdvancedModeEnabled) {
|
||||
return (
|
||||
<View>
|
||||
<BlueSpacing20 />
|
||||
@ -478,7 +478,7 @@ const WalletsAdd: React.FC = () => {
|
||||
);
|
||||
}
|
||||
})()}
|
||||
{isAdvancedOptionsEnabled.data === true && selectedWalletType === ButtonSelected.ONCHAIN && !isLoading && (
|
||||
{isAdvancedModeEnabled === true && selectedWalletType === ButtonSelected.ONCHAIN && !isLoading && (
|
||||
<BlueButtonLink style={styles.import} title={entropyButtonText} onPress={navigateToEntropy} />
|
||||
)}
|
||||
<BlueSpacing20 />
|
||||
|
@ -1,4 +1,4 @@
|
||||
import React, { useState, useRef, useEffect, useContext } from 'react';
|
||||
import React, { useState, useRef, useEffect } from 'react';
|
||||
import { Keyboard, ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
|
||||
import LottieView from 'lottie-react-native';
|
||||
import { Icon } from 'react-native-elements';
|
||||
@ -8,11 +8,11 @@ import navigationStyle from '../../components/navigationStyle';
|
||||
import BottomModal from '../../components/BottomModal';
|
||||
import { MultisigHDWallet } from '../../class';
|
||||
import loc from '../../loc';
|
||||
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
||||
import { useTheme } from '../../components/themes';
|
||||
import Button from '../../components/Button';
|
||||
import ListItem from '../../components/ListItem';
|
||||
import SafeArea from '../../components/SafeArea';
|
||||
import { useSettings } from '../../components/Context/SettingsContext';
|
||||
|
||||
const WalletsAddMultisig = () => {
|
||||
const { colors } = useTheme();
|
||||
@ -23,8 +23,7 @@ const WalletsAddMultisig = () => {
|
||||
const [n, setN] = useState(3);
|
||||
const [isModalVisible, setIsModalVisible] = useState(false);
|
||||
const [format, setFormat] = useState(MultisigHDWallet.FORMAT_P2WSH);
|
||||
const { isAdvancedModeEnabled } = useContext(BlueStorageContext);
|
||||
const [isAdvancedModeEnabledRender, setIsAdvancedModeEnabledRender] = useState(false);
|
||||
const { isAdvancedModeEnabled } = useSettings();
|
||||
|
||||
const stylesHook = StyleSheet.create({
|
||||
root: {
|
||||
@ -65,11 +64,6 @@ const WalletsAddMultisig = () => {
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
isAdvancedModeEnabled().then(setIsAdvancedModeEnabledRender);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
const onLetsStartPress = () => {
|
||||
navigate('WalletsAddMultisigStep2', { m, n, format, walletLabel });
|
||||
};
|
||||
@ -227,7 +221,7 @@ const WalletsAddMultisig = () => {
|
||||
</Text>
|
||||
</Text>
|
||||
</View>
|
||||
{isAdvancedModeEnabledRender && (
|
||||
{isAdvancedModeEnabled && (
|
||||
<View>
|
||||
<ListItem
|
||||
testID="VaultAdvancedCustomize"
|
||||
|
@ -39,12 +39,13 @@ import usePrivacy from '../../hooks/usePrivacy';
|
||||
import prompt from '../../helpers/prompt';
|
||||
import A from '../../blue_modules/analytics';
|
||||
import SaveFileButton from '../../components/SaveFileButton';
|
||||
import { useSettings } from '../../components/Context/SettingsContext';
|
||||
|
||||
const staticCache = {};
|
||||
|
||||
const WalletsAddMultisigStep2 = () => {
|
||||
const { addWallet, saveToDisk, isElectrumDisabled, isAdvancedModeEnabled, sleep, currentSharedCosigner, setSharedCosigner } =
|
||||
useContext(BlueStorageContext);
|
||||
const { addWallet, saveToDisk, isElectrumDisabled, sleep, currentSharedCosigner, setSharedCosigner } = useContext(BlueStorageContext);
|
||||
const { isAdvancedModeEnabled } = useSettings();
|
||||
const { colors } = useTheme();
|
||||
|
||||
const navigation = useNavigation();
|
||||
@ -62,16 +63,10 @@ const WalletsAddMultisigStep2 = () => {
|
||||
const [vaultKeyData, setVaultKeyData] = useState({ keyIndex: 1, xpub: '', seed: '', isLoading: false }); // string rendered in modal
|
||||
const [importText, setImportText] = useState('');
|
||||
const [askPassphrase, setAskPassphrase] = useState(false);
|
||||
const [isAdvancedModeEnabledRender, setIsAdvancedModeEnabledRender] = useState(false);
|
||||
const openScannerButton = useRef();
|
||||
const data = useRef(new Array(n));
|
||||
const { enableBlur, disableBlur } = usePrivacy();
|
||||
|
||||
useEffect(() => {
|
||||
isAdvancedModeEnabled().then(setIsAdvancedModeEnabledRender);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
useFocusEffect(
|
||||
useCallback(() => {
|
||||
enableBlur();
|
||||
@ -607,7 +602,7 @@ const WalletsAddMultisigStep2 = () => {
|
||||
<BlueTextCentered>{loc.multisig.type_your_mnemonics}</BlueTextCentered>
|
||||
<BlueSpacing20 />
|
||||
<BlueFormMultiInput value={importText} onChangeText={setImportText} />
|
||||
{isAdvancedModeEnabledRender && (
|
||||
{isAdvancedModeEnabled && (
|
||||
<>
|
||||
<BlueSpacing10 />
|
||||
<View style={styles.row}>
|
||||
|
@ -50,6 +50,7 @@ import { useExtendedNavigation } from '../../hooks/useExtendedNavigation';
|
||||
import loc, { formatBalanceWithoutSuffix } from '../../loc';
|
||||
import { BitcoinUnit, Chain } from '../../models/bitcoinUnits';
|
||||
import SaveFileButton from '../../components/SaveFileButton';
|
||||
import { useSettings } from '../../components/Context/SettingsContext';
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
scrollViewContent: {
|
||||
@ -129,8 +130,7 @@ const WalletDetails = () => {
|
||||
const wallet = useRef(wallets.find(w => w.getID() === walletID)).current;
|
||||
const [walletName, setWalletName] = useState(wallet.getLabel());
|
||||
const [useWithHardwareWallet, setUseWithHardwareWallet] = useState(wallet.useWithHardwareWalletEnabled());
|
||||
const { isAdvancedModeEnabled } = useContext(BlueStorageContext);
|
||||
const [isAdvancedModeEnabledRender, setIsAdvancedModeEnabledRender] = useState(false);
|
||||
const { isAdvancedModeEnabled } = useSettings();
|
||||
const [isBIP47Enabled, setIsBIP47Enabled] = useState(wallet.isBIP47Enabled());
|
||||
const [hideTransactionsInWalletsList, setHideTransactionsInWalletsList] = useState(!wallet.getHideTransactionsInWalletsList());
|
||||
const { goBack, setOptions, popToTop, navigate } = useExtendedNavigation();
|
||||
@ -152,12 +152,12 @@ const WalletDetails = () => {
|
||||
const onMenuWillHide = () => setIsToolTipMenuVisible(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (isAdvancedModeEnabledRender && wallet.allowMasterFingerprint()) {
|
||||
if (isAdvancedModeEnabled && wallet.allowMasterFingerprint()) {
|
||||
InteractionManager.runAfterInteractions(() => {
|
||||
setMasterFingerprint(wallet.getMasterFingerprintHex());
|
||||
});
|
||||
}
|
||||
}, [isAdvancedModeEnabledRender, wallet]);
|
||||
}, [isAdvancedModeEnabled, wallet]);
|
||||
const stylesHook = StyleSheet.create({
|
||||
textLabel1: {
|
||||
color: colors.feeText,
|
||||
@ -214,8 +214,6 @@ const WalletDetails = () => {
|
||||
};
|
||||
|
||||
useLayoutEffect(() => {
|
||||
isAdvancedModeEnabled().then(setIsAdvancedModeEnabledRender);
|
||||
|
||||
setOptions({
|
||||
// eslint-disable-next-line react/no-unstable-nested-components
|
||||
headerRight: () => (
|
||||
@ -635,7 +633,7 @@ const WalletDetails = () => {
|
||||
</View>
|
||||
</>
|
||||
)}
|
||||
{isAdvancedModeEnabledRender && (
|
||||
{isAdvancedModeEnabled && (
|
||||
<View style={styles.row}>
|
||||
{wallet.allowMasterFingerprint() && (
|
||||
<View style={styles.marginRight16}>
|
||||
|
@ -1,4 +1,4 @@
|
||||
import React, { useEffect, useState, useContext } from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Platform, View, Keyboard, StyleSheet, Switch, TouchableWithoutFeedback } from 'react-native';
|
||||
import { useNavigation, useRoute } from '@react-navigation/native';
|
||||
import {
|
||||
@ -11,12 +11,12 @@ import {
|
||||
} from '../../BlueComponents';
|
||||
import navigationStyle from '../../components/navigationStyle';
|
||||
import loc from '../../loc';
|
||||
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
||||
import { requestCameraAuthorization } from '../../helpers/scan-qr';
|
||||
import { useTheme } from '../../components/themes';
|
||||
import Button from '../../components/Button';
|
||||
import SafeArea from '../../components/SafeArea';
|
||||
import usePrivacy from '../../hooks/usePrivacy';
|
||||
import { useSettings } from '../../components/Context/SettingsContext';
|
||||
|
||||
const WalletsImport = () => {
|
||||
const navigation = useNavigation();
|
||||
@ -24,11 +24,10 @@ const WalletsImport = () => {
|
||||
const route = useRoute();
|
||||
const label = route?.params?.label ?? '';
|
||||
const triggerImport = route?.params?.triggerImport ?? false;
|
||||
const { isAdvancedModeEnabled } = useContext(BlueStorageContext);
|
||||
const { isAdvancedModeEnabled } = useSettings();
|
||||
const [importText, setImportText] = useState(label);
|
||||
const [isToolbarVisibleForAndroid, setIsToolbarVisibleForAndroid] = useState(false);
|
||||
const [, setSpeedBackdoor] = useState(0);
|
||||
const [isAdvancedModeEnabledRender, setIsAdvancedModeEnabledRender] = useState(false);
|
||||
const [searchAccounts, setSearchAccounts] = useState(false);
|
||||
const [askPassphrase, setAskPassphrase] = useState(false);
|
||||
const { enableBlur, disableBlur } = usePrivacy();
|
||||
@ -70,7 +69,6 @@ const WalletsImport = () => {
|
||||
}, [disableBlur, enableBlur]);
|
||||
|
||||
useEffect(() => {
|
||||
isAdvancedModeEnabled().then(setIsAdvancedModeEnabledRender);
|
||||
if (triggerImport) importButtonPressed();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
@ -117,7 +115,7 @@ const WalletsImport = () => {
|
||||
|
||||
const renderOptionsAndImportButton = (
|
||||
<>
|
||||
{isAdvancedModeEnabledRender && (
|
||||
{isAdvancedModeEnabled && (
|
||||
<>
|
||||
<View style={styles.row}>
|
||||
<BlueText>{loc.wallets.import_passphrase}</BlueText>
|
||||
|
Loading…
Reference in New Issue
Block a user