From 3ee765d2375f54129cb477e53c378c21a584cb33 Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Fri, 31 May 2024 11:52:29 -0400 Subject: [PATCH] REF: Proper file/dir structure for context providers --- App.tsx | 3 +-- components/CompanionDelegates.tsx | 2 +- .../Context/BlueStorageContext.tsx | 23 ++++++++----------- components/Context/SettingsContext.tsx | 10 +++----- components/DeviceQuickActions.tsx | 2 +- components/MenuElements.ios.tsx | 3 +-- components/TransactionListItem.tsx | 6 ++--- components/WalletsCarousel.js | 2 +- components/WatchConnectivity.ios.js | 2 +- components/WidgetCommunication.ios.tsx | 2 +- components/addresses/AddressItem.tsx | 2 +- hooks/context/useSettings.ts | 4 ++++ hooks/context/useStorage.ts | 4 ++++ hooks/useOnAppLaunch.ts | 2 +- screen/PlausibleDeniability.tsx | 2 +- screen/lnd/ldkInfo.tsx | 2 +- screen/lnd/lndCreateInvoice.js | 2 +- .../lndViewAdditionalInvoiceInformation.js | 2 +- screen/lnd/lndViewInvoice.js | 2 +- screen/lnd/lnurlAuth.js | 2 +- screen/receive/details.js | 2 +- screen/send/Confirm.tsx | 2 +- screen/send/coinControl.js | 8 +++---- screen/send/details.tsx | 2 +- screen/send/psbtMultisig.js | 2 +- screen/settings/SettingsPrivacy.tsx | 2 +- screen/settings/about.js | 2 +- screen/transactions/TransactionDetails.tsx | 2 +- screen/wallets/DrawerList.tsx | 2 +- .../ExportMultisigCoordinationSetup.tsx | 2 +- screen/wallets/addMultisigStep2.js | 2 +- screen/wallets/addresses.js | 2 +- screen/wallets/export.js | 2 +- screen/wallets/importCustomDerivationPath.js | 2 +- screen/wallets/importDiscovery.js | 2 +- screen/wallets/importSpeed.js | 2 +- screen/wallets/ldkViewLogs.js | 2 +- screen/wallets/pleaseBackupLNDHub.js | 2 +- screen/wallets/pleaseBackupLdk.js | 2 +- screen/wallets/reorderWallets.js | 2 +- screen/wallets/selectWallet.js | 2 +- screen/wallets/signVerify.js | 2 +- screen/wallets/xpub.tsx | 7 +++--- 43 files changed, 67 insertions(+), 69 deletions(-) rename blue_modules/storage-context.tsx => components/Context/BlueStorageContext.tsx (94%) create mode 100644 hooks/context/useSettings.ts create mode 100644 hooks/context/useStorage.ts diff --git a/App.tsx b/App.tsx index 1c98f69f8..390580ebd 100644 --- a/App.tsx +++ b/App.tsx @@ -4,13 +4,12 @@ import { NavigationContainer } from '@react-navigation/native'; import React from 'react'; import { useColorScheme } from 'react-native'; import { SafeAreaProvider } from 'react-native-safe-area-context'; - -import { BlueStorageProvider } from './blue_modules/storage-context'; import { LargeScreenProvider } from './components/Context/LargeScreenProvider'; import { SettingsProvider } from './components/Context/SettingsContext'; import { BlueDarkTheme, BlueDefaultTheme } from './components/themes'; import MasterView from './navigation/MasterView'; import { navigationRef } from './NavigationService'; +import { BlueStorageProvider } from './components/Context/BlueStorageContext'; const App = () => { const colorScheme = useColorScheme(); diff --git a/components/CompanionDelegates.tsx b/components/CompanionDelegates.tsx index 28d7b3f1f..87635743e 100644 --- a/components/CompanionDelegates.tsx +++ b/components/CompanionDelegates.tsx @@ -9,13 +9,13 @@ import BlueClipboard from '../blue_modules/clipboard'; import { updateExchangeRate } from '../blue_modules/currency'; import triggerHapticFeedback, { HapticFeedbackTypes } from '../blue_modules/hapticFeedback'; import Notifications from '../blue_modules/notifications'; -import { useStorage } from '../blue_modules/storage-context'; import { LightningCustodianWallet } from '../class'; import DeeplinkSchemaMatch from '../class/deeplink-schema-match'; import loc from '../loc'; import { Chain } from '../models/bitcoinUnits'; import { navigationRef } from '../NavigationService'; import ActionSheet from '../screen/ActionSheet'; +import { useStorage } from '../hooks/context/useStorage'; const MenuElements = lazy(() => import('../components/MenuElements')); const DeviceQuickActions = lazy(() => import('../components/DeviceQuickActions')); diff --git a/blue_modules/storage-context.tsx b/components/Context/BlueStorageContext.tsx similarity index 94% rename from blue_modules/storage-context.tsx rename to components/Context/BlueStorageContext.tsx index b6ac8156f..25646db84 100644 --- a/blue_modules/storage-context.tsx +++ b/components/Context/BlueStorageContext.tsx @@ -1,15 +1,14 @@ -import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react'; +import React, { createContext, useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { InteractionManager } from 'react-native'; - -import A from '../blue_modules/analytics'; -import Notifications from '../blue_modules/notifications'; -import { BlueApp as BlueAppClass, LegacyWallet, TCounterpartyMetadata, TTXMetadata, WatchOnlyWallet } from '../class'; -import type { TWallet } from '../class/wallets/types'; -import presentAlert from '../components/Alert'; -import loc from '../loc'; -import * as BlueElectrum from './BlueElectrum'; -import triggerHapticFeedback, { HapticFeedbackTypes } from './hapticFeedback'; -import { startAndDecrypt } from './start-and-decrypt'; +import A from '../../blue_modules/analytics'; +import Notifications from '../../blue_modules/notifications'; +import { BlueApp as BlueAppClass, LegacyWallet, TCounterpartyMetadata, TTXMetadata, WatchOnlyWallet } from '../../class'; +import type { TWallet } from '../../class/wallets/types'; +import presentAlert from '../../components/Alert'; +import loc from '../../loc'; +import * as BlueElectrum from '../../blue_modules/BlueElectrum'; +import triggerHapticFeedback, { HapticFeedbackTypes } from '../../blue_modules/hapticFeedback'; +import { startAndDecrypt } from '../../blue_modules/start-and-decrypt'; const BlueApp = BlueAppClass.getInstance(); @@ -305,5 +304,3 @@ export const BlueStorageProvider = ({ children }: { children: React.ReactNode }) return {children}; }; - -export const useStorage = () => useContext(BlueStorageContext); diff --git a/components/Context/SettingsContext.tsx b/components/Context/SettingsContext.tsx index 8d1a36a08..c1b3a2cf5 100644 --- a/components/Context/SettingsContext.tsx +++ b/components/Context/SettingsContext.tsx @@ -1,10 +1,8 @@ import { useAsyncStorage } from '@react-native-async-storage/async-storage'; -import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react'; +import React, { createContext, useCallback, useEffect, useMemo, useState } from 'react'; import DefaultPreference from 'react-native-default-preference'; - import BlueClipboard from '../../blue_modules/clipboard'; import { getPreferredCurrency, GROUP_IO_BLUEWALLET, initCurrencyDaemon } from '../../blue_modules/currency'; -import { useStorage } from '../../blue_modules/storage-context'; import { clearUseURv1, isURv1Enabled, setUseURv1 } from '../../blue_modules/ur'; import { BlueApp } from '../../class'; import { saveLanguage, STORAGE_KEY } from '../../loc'; @@ -13,6 +11,7 @@ import { getEnabled as getIsDeviceQuickActionsEnabled, setEnabled as setIsDevice import presentAlert from '../Alert'; import { getIsHandOffUseEnabled, setIsHandOffUseEnabled } from '../HandOffComponent'; import { isBalanceDisplayAllowed, setBalanceDisplayAllowed } from '../WidgetCommunication'; +import { useStorage } from '../../hooks/context/useStorage'; interface SettingsContextType { preferredFiatCurrency: TFiatUnit; @@ -86,7 +85,6 @@ export const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({ chil const advancedModeStorage = useAsyncStorage(BlueApp.ADVANCED_MODE_ENABLED); const languageStorage = useAsyncStorage(STORAGE_KEY); - const { walletsInitialized } = useStorage(); useEffect(() => { @@ -282,6 +280,4 @@ export const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({ chil ); return {children}; -}; - -export const useSettings = () => useContext(SettingsContext); +}; \ No newline at end of file diff --git a/components/DeviceQuickActions.tsx b/components/DeviceQuickActions.tsx index 739a956d6..0ca764bbd 100644 --- a/components/DeviceQuickActions.tsx +++ b/components/DeviceQuickActions.tsx @@ -32,7 +32,7 @@ export async function getEnabled(): Promise { } function DeviceQuickActions() { - const { wallets, walletsInitialized, isStorageEncrypted, addWallet, saveToDisk, setSharedCosigner } = useContext(BlueStorageContext); + const { wallets, walletsInitialized, isStorageEncrypted, addWallet, saveToDisk, setSharedCosigner } = useStorage(); const { preferredFiatCurrency, isQuickActionsEnabled } = useSettings(); const { isViewAllWalletsEnabled, getSelectedDefaultWallet } = useOnAppLaunch(); diff --git a/components/MenuElements.ios.tsx b/components/MenuElements.ios.tsx index c12abc0bf..6e60b21e1 100644 --- a/components/MenuElements.ios.tsx +++ b/components/MenuElements.ios.tsx @@ -1,7 +1,6 @@ import { CommonActions } from '@react-navigation/native'; import { useCallback, useContext, useEffect } from 'react'; import { NativeEventEmitter, NativeModules, Platform } from 'react-native'; - import { BlueStorageContext } from '../blue_modules/storage-context'; import * as NavigationService from '../NavigationService'; @@ -12,7 +11,7 @@ EventEmitter on the native side should receive a payload and rebuild menus. const eventEmitter = Platform.OS === 'ios' || Platform.OS === 'macos' ? new NativeEventEmitter(NativeModules.EventEmitter) : undefined; const MenuElements = () => { - const { walletsInitialized, reloadTransactionsMenuActionFunction } = useContext(BlueStorageContext); + const { walletsInitialized, reloadTransactionsMenuActionFunction } = useStorage(); // BlueWallet -> Settings const openSettings = useCallback(() => { diff --git a/components/TransactionListItem.tsx b/components/TransactionListItem.tsx index 8140a940e..f9f6c861e 100644 --- a/components/TransactionListItem.tsx +++ b/components/TransactionListItem.tsx @@ -1,8 +1,7 @@ -import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react'; +import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import AsyncStorage from '@react-native-async-storage/async-storage'; import Clipboard from '@react-native-clipboard/clipboard'; import { Linking, StyleSheet, View } from 'react-native'; -import { BlueStorageContext } from '../blue_modules/storage-context'; import Lnurl from '../class/lnurl'; import { LightningTransaction, Transaction } from '../class/wallets/types'; import TransactionExpiredIcon from '../components/icons/TransactionExpiredIcon'; @@ -22,6 +21,7 @@ import { Action, ToolTipMenuProps } from './types'; import { useExtendedNavigation } from '../hooks/useExtendedNavigation'; import { NativeStackNavigationProp } from '@react-navigation/native-stack'; import { DetailViewStackParamList } from '../navigation/DetailViewStackParamList'; +import { useStorage } from '../hooks/context/useStorage'; interface TransactionListItemProps { itemPriceUnit: BitcoinUnit; @@ -36,7 +36,7 @@ export const TransactionListItem: React.FC = React.mem const { colors } = useTheme(); const { navigate } = useExtendedNavigation(); const menuRef = useRef(); - const { txMetadata, counterpartyMetadata, wallets } = useContext(BlueStorageContext); + const { txMetadata, counterpartyMetadata, wallets } = useStorage(); const { preferredFiatCurrency, language } = useSettings(); const containerStyle = useMemo( () => ({ diff --git a/components/WalletsCarousel.js b/components/WalletsCarousel.js index 660696c93..eeac50283 100644 --- a/components/WalletsCarousel.js +++ b/components/WalletsCarousel.js @@ -157,7 +157,7 @@ const iStyles = StyleSheet.create({ export const WalletCarouselItem = React.memo(({ item, _, onPress, handleLongPress, isSelectedWallet, customStyle }) => { const scaleValue = new Animated.Value(1.0); const { colors } = useTheme(); - const { walletTransactionUpdateStatus } = useContext(BlueStorageContext); + const { walletTransactionUpdateStatus } = useStorage(); const { width } = useWindowDimensions(); const itemWidth = width * 0.82 > 375 ? 375 : width * 0.82; const isLargeScreen = useIsLargeScreen(); diff --git a/components/WatchConnectivity.ios.js b/components/WatchConnectivity.ios.js index 08d87b766..774a19f4a 100644 --- a/components/WatchConnectivity.ios.js +++ b/components/WatchConnectivity.ios.js @@ -17,7 +17,7 @@ import { FiatUnit } from '../models/fiatUnit'; import { useSettings } from './Context/SettingsContext'; function WatchConnectivity() { - const { walletsInitialized, wallets, fetchWalletTransactions, saveToDisk, txMetadata } = useContext(BlueStorageContext); + const { walletsInitialized, wallets, fetchWalletTransactions, saveToDisk, txMetadata } = useStorage(); const { preferredFiatCurrency } = useSettings(); const isReachable = useReachability(); const isInstalled = useInstalled(); // true | false diff --git a/components/WidgetCommunication.ios.tsx b/components/WidgetCommunication.ios.tsx index 5dcb3de30..77f360a19 100644 --- a/components/WidgetCommunication.ios.tsx +++ b/components/WidgetCommunication.ios.tsx @@ -62,7 +62,7 @@ const allWalletsBalanceAndTransactionTime = async ( }; const WidgetCommunication: React.FC = () => { - const { wallets, walletsInitialized } = useContext(BlueStorageContext); + const { wallets, walletsInitialized } = useStorage(); const { isWidgetBalanceDisplayAllowed } = useSettings(); useEffect(() => { diff --git a/components/addresses/AddressItem.tsx b/components/addresses/AddressItem.tsx index f44a3514c..f8ba7e1f4 100644 --- a/components/addresses/AddressItem.tsx +++ b/components/addresses/AddressItem.tsx @@ -5,7 +5,6 @@ import { StyleSheet, Text, View } from 'react-native'; import { ListItem } from 'react-native-elements'; import Share from 'react-native-share'; import triggerHapticFeedback, { HapticFeedbackTypes } from '../../blue_modules/hapticFeedback'; -import { useStorage } from '../../blue_modules/storage-context'; import confirm from '../../helpers/confirm'; import { useBiometrics } from '../../hooks/useBiometrics'; import loc, { formatBalance } from '../../loc'; @@ -18,6 +17,7 @@ import { Action, ToolTipMenuProps } from '../types'; import { AddressTypeBadge } from './AddressTypeBadge'; import { NativeStackNavigationProp } from '@react-navigation/native-stack'; import { DetailViewStackParamList } from '../../navigation/DetailViewStackParamList'; +import { useStorage } from '../../hooks/context/useStorage'; interface AddressItemProps { // todo: fix `any` after addresses.js is converted to the church of holy typescript diff --git a/hooks/context/useSettings.ts b/hooks/context/useSettings.ts new file mode 100644 index 000000000..c3b5dcd6a --- /dev/null +++ b/hooks/context/useSettings.ts @@ -0,0 +1,4 @@ +import { useContext } from 'react'; +import { SettingsContext } from '../../components/Context/SettingsContext'; + +export const useSettings = () => useContext(SettingsContext); diff --git a/hooks/context/useStorage.ts b/hooks/context/useStorage.ts new file mode 100644 index 000000000..5e4b84621 --- /dev/null +++ b/hooks/context/useStorage.ts @@ -0,0 +1,4 @@ +import { useContext } from 'react'; +import { BlueStorageContext } from '../../components/Context/BlueStorageContext'; + +export const useStorage = () => useStorage(); diff --git a/hooks/useOnAppLaunch.ts b/hooks/useOnAppLaunch.ts index a4a6de605..c752d8fb7 100644 --- a/hooks/useOnAppLaunch.ts +++ b/hooks/useOnAppLaunch.ts @@ -5,7 +5,7 @@ import { TWallet } from '../class/wallets/types'; const useOnAppLaunch = () => { const STORAGE_KEY = 'ONAPP_LAUNCH_SELECTED_DEFAULT_WALLET_KEY'; - const { wallets } = useContext(BlueStorageContext); + const { wallets } = useStorage(); const getSelectedDefaultWallet = useCallback(async (): Promise => { let selectedWallet: TWallet | undefined; diff --git a/screen/PlausibleDeniability.tsx b/screen/PlausibleDeniability.tsx index 98df4f9dd..3cdd6e140 100644 --- a/screen/PlausibleDeniability.tsx +++ b/screen/PlausibleDeniability.tsx @@ -38,7 +38,7 @@ function reducer(state: State, action: Action): State { // Component const PlausibleDeniability: React.FC = () => { - const { cachedPassword, isPasswordInUse, createFakeStorage, resetWallets } = useContext(BlueStorageContext); + const { cachedPassword, isPasswordInUse, createFakeStorage, resetWallets } = useStorage(); const [state, dispatch] = useReducer(reducer, initialState); const navigation = useNavigation>>(); diff --git a/screen/lnd/ldkInfo.tsx b/screen/lnd/ldkInfo.tsx index 42063b4e0..f03ab3133 100644 --- a/screen/lnd/ldkInfo.tsx +++ b/screen/lnd/ldkInfo.tsx @@ -34,7 +34,7 @@ type LdkInfoRouteProps = RouteProp< const LdkInfo = () => { const { walletID } = useRoute().params; - const { wallets } = useContext(BlueStorageContext); + const { wallets } = useStorage(); const refreshDataInterval = useRef(); const sectionList = useRef(); const wallet = wallets.find(w => w.getID() === walletID) as LightningLdkWallet; diff --git a/screen/lnd/lndCreateInvoice.js b/screen/lnd/lndCreateInvoice.js index 31cb33935..eb879d082 100644 --- a/screen/lnd/lndCreateInvoice.js +++ b/screen/lnd/lndCreateInvoice.js @@ -34,7 +34,7 @@ import { BitcoinUnit, Chain } from '../../models/bitcoinUnits'; import * as NavigationService from '../../NavigationService'; const LNDCreateInvoice = () => { - const { wallets, saveToDisk, setSelectedWalletID } = useContext(BlueStorageContext); + const { wallets, saveToDisk, setSelectedWalletID } = useStorage(); const { walletID, uri } = useRoute().params; const wallet = useRef(wallets.find(item => item.getID() === walletID) || wallets.find(item => item.chain === Chain.OFFCHAIN)); const createInvoiceRef = useRef(); diff --git a/screen/lnd/lndViewAdditionalInvoiceInformation.js b/screen/lnd/lndViewAdditionalInvoiceInformation.js index 43fbce08d..f0489096e 100644 --- a/screen/lnd/lndViewAdditionalInvoiceInformation.js +++ b/screen/lnd/lndViewAdditionalInvoiceInformation.js @@ -14,7 +14,7 @@ import loc from '../../loc'; const LNDViewAdditionalInvoiceInformation = () => { const { walletID } = useRoute().params; - const { wallets } = useContext(BlueStorageContext); + const { wallets } = useStorage(); const wallet = wallets.find(w => w.getID() === walletID); const [walletInfo, setWalletInfo] = useState(); const { colors } = useTheme(); diff --git a/screen/lnd/lndViewInvoice.js b/screen/lnd/lndViewInvoice.js index 25c9f9539..a8c45b625 100644 --- a/screen/lnd/lndViewInvoice.js +++ b/screen/lnd/lndViewInvoice.js @@ -19,7 +19,7 @@ import LNDCreateInvoice from './lndCreateInvoice'; const LNDViewInvoice = () => { const { invoice, walletID } = useRoute().params; - const { wallets, setSelectedWalletID, fetchAndSaveWalletTransactions } = useContext(BlueStorageContext); + const { wallets, setSelectedWalletID, fetchAndSaveWalletTransactions } = useStorage(); const wallet = wallets.find(w => w.getID() === walletID); const { colors, closeImage } = useTheme(); const { goBack, navigate, setParams, setOptions, getParent } = useNavigation(); diff --git a/screen/lnd/lnurlAuth.js b/screen/lnd/lnurlAuth.js index af707b0d2..1500c110e 100644 --- a/screen/lnd/lnurlAuth.js +++ b/screen/lnd/lnurlAuth.js @@ -24,7 +24,7 @@ const AuthState = { }; const LnurlAuth = () => { - const { wallets } = useContext(BlueStorageContext); + const { wallets } = useStorage(); const { name } = useRoute(); const { walletID, lnurl } = useRoute().params; const wallet = useMemo(() => wallets.find(w => w.getID() === walletID), [wallets, walletID]); diff --git a/screen/receive/details.js b/screen/receive/details.js index c104bf25b..a69c36c72 100644 --- a/screen/receive/details.js +++ b/screen/receive/details.js @@ -35,7 +35,7 @@ import { SuccessView } from '../send/success'; const ReceiveDetails = () => { const { walletID, address } = useRoute().params; - const { wallets, saveToDisk, sleep, isElectrumDisabled, fetchAndSaveWalletTransactions } = useContext(BlueStorageContext); + const { wallets, saveToDisk, sleep, isElectrumDisabled, fetchAndSaveWalletTransactions } = useStorage(); const wallet = wallets.find(w => w.getID() === walletID); const [customLabel, setCustomLabel] = useState(); const [customAmount, setCustomAmount] = useState(); diff --git a/screen/send/Confirm.tsx b/screen/send/Confirm.tsx index 19126a256..b0fcd1c3a 100644 --- a/screen/send/Confirm.tsx +++ b/screen/send/Confirm.tsx @@ -66,7 +66,7 @@ type ConfirmRouteProp = RouteProp; type ConfirmNavigationProp = NativeStackNavigationProp; const Confirm: React.FC = () => { - const { wallets, fetchAndSaveWalletTransactions, counterpartyMetadata, isElectrumDisabled } = useContext(BlueStorageContext); + const { wallets, fetchAndSaveWalletTransactions, counterpartyMetadata, isElectrumDisabled } = useStorage(); const { isBiometricUseCapableAndEnabled, unlockWithBiometrics } = useBiometrics(); const navigation = useExtendedNavigation(); const route = useRoute(); // Get the route and its params diff --git a/screen/send/coinControl.js b/screen/send/coinControl.js index 2e215e4c9..c5701ec46 100644 --- a/screen/send/coinControl.js +++ b/screen/send/coinControl.js @@ -62,7 +62,7 @@ const OutputList = ({ onDeSelect, }) => { const { colors } = useTheme(); - const { txMetadata } = useContext(BlueStorageContext); + const { txMetadata } = useStorage(); const memo = oMemo || txMetadata[txid]?.memo || ''; const color = `#${txid.substring(0, 6)}`; const amount = formatBalance(value, balanceUnit, true); @@ -124,7 +124,7 @@ OutputList.propTypes = { const OutputModal = ({ item: { address, txid, value, vout, confirmations = 0 }, balanceUnit = BitcoinUnit.BTC, oMemo }) => { const { colors } = useTheme(); - const { txMetadata } = useContext(BlueStorageContext); + const { txMetadata } = useStorage(); const memo = oMemo || txMetadata[txid]?.memo || ''; const fullId = `${txid}:${vout}`; const color = `#${txid.substring(0, 6)}`; @@ -198,7 +198,7 @@ const mStyles = StyleSheet.create({ const OutputModalContent = ({ output, wallet, onUseCoin, frozen, setFrozen }) => { const { colors } = useTheme(); - const { txMetadata, saveToDisk } = useContext(BlueStorageContext); + const { txMetadata, saveToDisk } = useStorage(); const [memo, setMemo] = useState(wallet.getUTXOMetadata(output.txid, output.vout).memo || txMetadata[output.txid]?.memo || ''); const onMemoChange = value => setMemo(value); const switchValue = useMemo(() => ({ value: frozen, onValueChange: value => setFrozen(value) }), [frozen, setFrozen]); @@ -256,7 +256,7 @@ const CoinControl = () => { const navigation = useNavigation(); const { width } = useWindowDimensions(); const { walletID, onUTXOChoose } = useRoute().params; - const { wallets, saveToDisk, sleep } = useContext(BlueStorageContext); + const { wallets, saveToDisk, sleep } = useStorage(); const wallet = wallets.find(w => w.getID() === walletID); // sort by height ascending, txid , vout ascending const utxo = wallet.getUtxo(true).sort((a, b) => a.height - b.height || a.txid.localeCompare(b.txid) || a.vout - b.vout); diff --git a/screen/send/details.tsx b/screen/send/details.tsx index 0c88ead3a..11d9d1d57 100644 --- a/screen/send/details.tsx +++ b/screen/send/details.tsx @@ -75,7 +75,7 @@ type NavigationProps = NativeStackNavigationProp; const SendDetails = () => { - const { wallets, setSelectedWalletID, sleep, txMetadata, saveToDisk } = useContext(BlueStorageContext); + const { wallets, setSelectedWalletID, sleep, txMetadata, saveToDisk } = useStorage(); const navigation = useExtendedNavigation(); const route = useRoute(); const name = route.name; diff --git a/screen/send/psbtMultisig.js b/screen/send/psbtMultisig.js index fe0af7cc5..080cb1dcb 100644 --- a/screen/send/psbtMultisig.js +++ b/screen/send/psbtMultisig.js @@ -20,7 +20,7 @@ const shortenAddress = addr => { }; const PsbtMultisig = () => { - const { wallets } = useContext(BlueStorageContext); + const { wallets } = useStorage(); const { navigate, setParams } = useNavigation(); const { colors } = useTheme(); const [flatListHeight, setFlatListHeight] = useState(0); diff --git a/screen/settings/SettingsPrivacy.tsx b/screen/settings/SettingsPrivacy.tsx index 8d52e37d2..a92e009e3 100644 --- a/screen/settings/SettingsPrivacy.tsx +++ b/screen/settings/SettingsPrivacy.tsx @@ -22,7 +22,7 @@ enum SettingsPrivacySection { const SettingsPrivacy: React.FC = () => { const { colors } = useTheme(); - const { isStorageEncrypted } = useContext(BlueStorageContext); + const { isStorageEncrypted } = useStorage(); const { isDoNotTrackEnabled, setDoNotTrackStorage, diff --git a/screen/settings/about.js b/screen/settings/about.js index 9e6bedd13..b39aa6142 100644 --- a/screen/settings/about.js +++ b/screen/settings/about.js @@ -22,7 +22,7 @@ const About = () => { const { navigate } = useNavigation(); const { colors } = useTheme(); const { width, height } = useWindowDimensions(); - const { isElectrumDisabled } = useContext(BlueStorageContext); + const { isElectrumDisabled } = useStorage(); const styles = StyleSheet.create({ copyToClipboard: { justifyContent: 'center', diff --git a/screen/transactions/TransactionDetails.tsx b/screen/transactions/TransactionDetails.tsx index 77d4e98ac..d7476b1c7 100644 --- a/screen/transactions/TransactionDetails.tsx +++ b/screen/transactions/TransactionDetails.tsx @@ -69,7 +69,7 @@ type NavigationProps = NativeStackNavigationProp { const { setOptions, navigate } = useExtendedNavigation(); const { hash, walletID } = useRoute().params; - const { saveToDisk, txMetadata, counterpartyMetadata, wallets, getTransactions } = useContext(BlueStorageContext); + const { saveToDisk, txMetadata, counterpartyMetadata, wallets, getTransactions } = useStorage(); const [from, setFrom] = useState([]); const [to, setTo] = useState([]); const [isLoading, setIsLoading] = useState(true); diff --git a/screen/wallets/DrawerList.tsx b/screen/wallets/DrawerList.tsx index be36af71d..134c13208 100644 --- a/screen/wallets/DrawerList.tsx +++ b/screen/wallets/DrawerList.tsx @@ -84,7 +84,7 @@ const DrawerList: React.FC = memo(({ navigation }) => { const [state, dispatch] = useReducer(walletReducer, initialState); const walletsCarousel = useRef>(null); - const { wallets, selectedWalletID } = useContext(BlueStorageContext); + const { wallets, selectedWalletID } = useStorage(); const { colors } = useTheme(); const isFocused = useIsFocused(); diff --git a/screen/wallets/ExportMultisigCoordinationSetup.tsx b/screen/wallets/ExportMultisigCoordinationSetup.tsx index d3d225a96..0235e1e3b 100644 --- a/screen/wallets/ExportMultisigCoordinationSetup.tsx +++ b/screen/wallets/ExportMultisigCoordinationSetup.tsx @@ -65,7 +65,7 @@ const ExportMultisigCoordinationSetup: React.FC = () => { const { isLoading, isShareButtonTapped, qrCodeContents } = state; const { params } = useRoute>(); const walletID = params.walletID; - const { wallets } = useContext(BlueStorageContext); + const { wallets } = useStorage(); const wallet: TWallet | undefined = wallets.find(w => w.getID() === walletID); const dynamicQRCode = useRef(); const { colors } = useTheme(); diff --git a/screen/wallets/addMultisigStep2.js b/screen/wallets/addMultisigStep2.js index 3e2211966..d5c0759fa 100644 --- a/screen/wallets/addMultisigStep2.js +++ b/screen/wallets/addMultisigStep2.js @@ -44,7 +44,7 @@ import loc from '../../loc'; const staticCache = {}; const WalletsAddMultisigStep2 = () => { - const { addWallet, saveToDisk, isElectrumDisabled, sleep, currentSharedCosigner, setSharedCosigner } = useContext(BlueStorageContext); + const { addWallet, saveToDisk, isElectrumDisabled, sleep, currentSharedCosigner, setSharedCosigner } = useStorage(); const { isAdvancedModeEnabled } = useSettings(); const { colors } = useTheme(); diff --git a/screen/wallets/addresses.js b/screen/wallets/addresses.js index a3b9bbb41..633e92388 100644 --- a/screen/wallets/addresses.js +++ b/screen/wallets/addresses.js @@ -59,7 +59,7 @@ const WalletAddresses = () => { const [currentTab, setCurrentTab] = useState(TABS.EXTERNAL); - const { wallets } = useContext(BlueStorageContext); + const { wallets } = useStorage(); const { walletID } = useRoute().params; diff --git a/screen/wallets/export.js b/screen/wallets/export.js index 9c5ab0d0f..18902bd78 100644 --- a/screen/wallets/export.js +++ b/screen/wallets/export.js @@ -14,7 +14,7 @@ import usePrivacy from '../../hooks/usePrivacy'; import loc from '../../loc'; const WalletExport = () => { - const { wallets, saveToDisk } = useContext(BlueStorageContext); + const { wallets, saveToDisk } = useStorage(); const { walletID } = useRoute().params; const [isLoading, setIsLoading] = useState(true); const { goBack } = useNavigation(); diff --git a/screen/wallets/importCustomDerivationPath.js b/screen/wallets/importCustomDerivationPath.js index 3273f63d1..f1f2d77d7 100644 --- a/screen/wallets/importCustomDerivationPath.js +++ b/screen/wallets/importCustomDerivationPath.js @@ -27,7 +27,7 @@ const ImportCustomDerivationPath = () => { const route = useRoute(); const importText = route.params.importText; const password = route.params.password; - const { addAndSaveWallet } = useContext(BlueStorageContext); + const { addAndSaveWallet } = useStorage(); const [path, setPath] = useState("m/84'/0'/0'"); const [wallets, setWallets] = useState({}); const [used, setUsed] = useState({}); diff --git a/screen/wallets/importDiscovery.js b/screen/wallets/importDiscovery.js index ecc24d7fe..177f05780 100644 --- a/screen/wallets/importDiscovery.js +++ b/screen/wallets/importDiscovery.js @@ -22,7 +22,7 @@ const ImportWalletDiscovery = () => { const route = useRoute(); const { importText, askPassphrase, searchAccounts } = route.params; const task = useRef(); - const { addAndSaveWallet } = useContext(BlueStorageContext); + const { addAndSaveWallet } = useStorage(); const [loading, setLoading] = useState(true); const [wallets, setWallets] = useState([]); const [password, setPassword] = useState(); diff --git a/screen/wallets/importSpeed.js b/screen/wallets/importSpeed.js index 3cb3e145f..4304c98a0 100644 --- a/screen/wallets/importSpeed.js +++ b/screen/wallets/importSpeed.js @@ -17,7 +17,7 @@ const WalletsImportWallet = () => { const [importText, setImportText] = useState(); const [walletType, setWalletType] = useState(); const [passphrase, setPassphrase] = useState(); - const { addAndSaveWallet } = useContext(BlueStorageContext); + const { addAndSaveWallet } = useStorage(); const styles = StyleSheet.create({ root: { diff --git a/screen/wallets/ldkViewLogs.js b/screen/wallets/ldkViewLogs.js index 0fc49a400..038fd9128 100644 --- a/screen/wallets/ldkViewLogs.js +++ b/screen/wallets/ldkViewLogs.js @@ -15,7 +15,7 @@ import loc from '../../loc'; const LdkViewLogs = () => { const { colors } = useTheme(); - const { wallets } = useContext(BlueStorageContext); + const { wallets } = useStorage(); const { walletID } = useRoute().params; /** @type {LightningLdkWallet} */ const wallet = wallets.find(w => w.getID() === walletID); diff --git a/screen/wallets/pleaseBackupLNDHub.js b/screen/wallets/pleaseBackupLNDHub.js index 8d31b16d3..0459209db 100644 --- a/screen/wallets/pleaseBackupLNDHub.js +++ b/screen/wallets/pleaseBackupLNDHub.js @@ -13,7 +13,7 @@ import usePrivacy from '../../hooks/usePrivacy'; import loc from '../../loc'; const PleaseBackupLNDHub = () => { - const { wallets } = useContext(BlueStorageContext); + const { wallets } = useStorage(); const { walletID } = useRoute().params; const wallet = wallets.find(w => w.getID() === walletID); const navigation = useNavigation(); diff --git a/screen/wallets/pleaseBackupLdk.js b/screen/wallets/pleaseBackupLdk.js index b7c5b382c..88746be5b 100644 --- a/screen/wallets/pleaseBackupLdk.js +++ b/screen/wallets/pleaseBackupLdk.js @@ -13,7 +13,7 @@ import usePrivacy from '../../hooks/usePrivacy'; import loc from '../../loc'; const PleaseBackupLdk = () => { - const { wallets } = useContext(BlueStorageContext); + const { wallets } = useStorage(); const { walletID } = useRoute().params; /** @type {LightningLdkWallet} */ const wallet = wallets.find(w => w.getID() === walletID); diff --git a/screen/wallets/reorderWallets.js b/screen/wallets/reorderWallets.js index 70d6f8899..8e199e415 100644 --- a/screen/wallets/reorderWallets.js +++ b/screen/wallets/reorderWallets.js @@ -22,7 +22,7 @@ const styles = StyleSheet.create({ const ReorderWallets = () => { const sortableList = useRef(); const { colors } = useTheme(); - const { wallets, setWalletsWithNewOrder } = useContext(BlueStorageContext); + const { wallets, setWalletsWithNewOrder } = useStorage(); const colorScheme = useColorScheme(); const { navigate, setOptions } = useExtendedNavigation(); const [searchQuery, setSearchQuery] = useState(''); diff --git a/screen/wallets/selectWallet.js b/screen/wallets/selectWallet.js index 8df53f586..b47c30c11 100644 --- a/screen/wallets/selectWallet.js +++ b/screen/wallets/selectWallet.js @@ -18,7 +18,7 @@ const SelectWallet = () => { const { chainType, onWalletSelect, availableWallets, noWalletExplanationText, onChainRequireSend = false } = useRoute().params; const [isLoading, setIsLoading] = useState(true); const { pop, navigate, setOptions, getParent } = useNavigation(); - const { wallets } = useContext(BlueStorageContext); + const { wallets } = useStorage(); const { colors, closeImage } = useTheme(); const isModal = useNavigationState(state => state.routes.length) === 1; let data = !onChainRequireSend diff --git a/screen/wallets/signVerify.js b/screen/wallets/signVerify.js index ea95c7c92..37eedcc42 100644 --- a/screen/wallets/signVerify.js +++ b/screen/wallets/signVerify.js @@ -25,7 +25,7 @@ import loc from '../../loc'; const SignVerify = () => { const { colors } = useTheme(); - const { wallets, sleep } = useContext(BlueStorageContext); + const { wallets, sleep } = useStorage(); const { params } = useRoute(); const [isKeyboardVisible, setIsKeyboardVisible] = useState(false); const [address, setAddress] = useState(params.address ?? ''); diff --git a/screen/wallets/xpub.tsx b/screen/wallets/xpub.tsx index 845830e63..2fabe76f1 100644 --- a/screen/wallets/xpub.tsx +++ b/screen/wallets/xpub.tsx @@ -1,9 +1,7 @@ import { NavigationProp, RouteProp, useFocusEffect, useNavigation, useRoute } from '@react-navigation/native'; -import React, { useCallback, useContext, useEffect, useRef, useState } from 'react'; +import React, { useCallback, useEffect, useRef, useState } from 'react'; import { ActivityIndicator, InteractionManager, View } from 'react-native'; import Share from 'react-native-share'; - -import { BlueStorageContext } from '../../blue_modules/storage-context'; import { BlueSpacing20, BlueText } from '../../BlueComponents'; import Button from '../../components/Button'; import CopyTextToClipboard from '../../components/CopyTextToClipboard'; @@ -13,6 +11,7 @@ import SafeArea from '../../components/SafeArea'; import usePrivacy from '../../hooks/usePrivacy'; import loc from '../../loc'; import { styles, useDynamicStyles } from './xpub.styles'; +import { useStorage } from '../../hooks/context/useStorage'; type WalletXpubRouteProp = RouteProp<{ params: { walletID: string; xpub: string } }, 'params'>; export type RootStackParamList = { @@ -23,7 +22,7 @@ export type RootStackParamList = { }; const WalletXpub: React.FC = () => { - const { wallets } = useContext(BlueStorageContext); + const { wallets } = useStorage(); const route = useRoute(); const { walletID, xpub } = route.params; const wallet = wallets.find(w => w.getID() === walletID);