From a1b52f563c6bdd65ab7938eebe654e198ffb1c08 Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Wed, 8 May 2024 21:04:52 -0400 Subject: [PATCH] REF: Lazy load SendDetailsStack --- Navigation.tsx | 74 +++++++--------------- navigation/LazyLoadSendDetailsStack.tsx | 59 ++++++++++++++++++ navigation/SendDetailsStack.tsx | 83 +++++++++++++++++++++++++ screen/send/coinControl.js | 3 - screen/send/confirm.js | 3 - screen/send/create.js | 9 --- screen/send/details.js | 9 --- screen/send/psbtMultisig.js | 4 -- screen/send/psbtMultisigQRCode.js | 3 - screen/send/psbtWithHardwareWallet.js | 8 --- screen/wallets/selectWallet.js | 4 -- 11 files changed, 164 insertions(+), 95 deletions(-) create mode 100644 navigation/LazyLoadSendDetailsStack.tsx create mode 100644 navigation/SendDetailsStack.tsx diff --git a/Navigation.tsx b/Navigation.tsx index 2a9fcb797..a88ffb692 100644 --- a/Navigation.tsx +++ b/Navigation.tsx @@ -43,14 +43,7 @@ import ReceiveDetails from './screen/receive/details'; import ScanQRCode from './screen/send/ScanQRCode'; import Broadcast from './screen/send/Broadcast'; -import CoinControl from './screen/send/coinControl'; -import Confirm from './screen/send/confirm'; -import SendCreate from './screen/send/create'; -import SendDetails from './screen/send/details'; import IsItMyAddress from './screen/send/isItMyAddress'; -import PsbtMultisig from './screen/send/psbtMultisig'; -import PsbtMultisigQRCode from './screen/send/psbtMultisigQRCode'; -import PsbtWithHardwareWallet from './screen/send/psbtWithHardwareWallet'; import Success from './screen/send/success'; import UnlockWith from './screen/UnlockWith'; @@ -77,46 +70,7 @@ import { BlueStorageContext } from './blue_modules/storage-context'; import { useIsLargeScreen } from './hooks/useIsLargeScreen'; import { HeaderRightButton } from './components/HeaderRightButton'; import WalletExportStack from './navigation/WalletExportStack'; - -// CreateTransactionStackNavigator === SendDetailsStack -const SendDetailsStack = createNativeStackNavigator(); -const SendDetailsRoot = () => { - const theme = useTheme(); - - return ( - - - - - - - - - - - - ); -}; +import SendDetailsStack from './navigation/SendDetailsStack'; const LNDCreateInvoiceStack = createNativeStackNavigator(); const LNDCreateInvoiceRoot = () => { @@ -129,7 +83,11 @@ const LNDCreateInvoiceRoot = () => { component={LNDCreateInvoice} options={LNDCreateInvoice.navigationOptions(theme)} /> - + { options={ScanLndInvoice.navigationOptions(theme)} initialParams={ScanLndInvoice.initialParams} /> - + @@ -172,7 +134,11 @@ const LDKOpenChannelRoot = () => { return ( - + { headerLargeTitle: true, })(theme)} /> - + @@ -451,7 +421,7 @@ const DetailViewStackScreensStack = () => { diff --git a/navigation/LazyLoadSendDetailsStack.tsx b/navigation/LazyLoadSendDetailsStack.tsx new file mode 100644 index 000000000..ee123686c --- /dev/null +++ b/navigation/LazyLoadSendDetailsStack.tsx @@ -0,0 +1,59 @@ +import React, { lazy, Suspense } from 'react'; +import { LazyLoadingIndicator } from './LazyLoadingIndicator'; + +const SendDetails = lazy(() => import('../screen/send/details')); +const Confirm = lazy(() => import('../screen/send/confirm')); +const PsbtWithHardwareWallet = lazy(() => import('../screen/send/psbtWithHardwareWallet')); +const CreateTransaction = lazy(() => import('../screen/send/create')); +const PsbtMultisig = lazy(() => import('../screen/send/psbtMultisig')); +const PsbtMultisigQRCode = lazy(() => import('../screen/send/psbtMultisigQRCode')); +const Success = lazy(() => import('../screen/send/success')); +const SelectWallet = lazy(() => import('../screen/wallets/selectWallet')); +const CoinControl = lazy(() => import('../screen/send/coinControl')); + +// Export each component with its lazy loader and optional configurations +export const SendDetailsComponent = () => ( + }> + + +); +export const ConfirmComponent = () => ( + }> + + +); +export const PsbtWithHardwareWalletComponent = () => ( + }> + + +); +export const CreateTransactionComponent = () => ( + }> + + +); +export const PsbtMultisigComponent = () => ( + }> + + +); +export const PsbtMultisigQRCodeComponent = () => ( + }> + + +); +export const SuccessComponent = () => ( + }> + + +); +export const SelectWalletComponent = () => ( + }> + + +); +export const CoinControlComponent = () => ( + }> + + +); diff --git a/navigation/SendDetailsStack.tsx b/navigation/SendDetailsStack.tsx new file mode 100644 index 000000000..1264fadfb --- /dev/null +++ b/navigation/SendDetailsStack.tsx @@ -0,0 +1,83 @@ +import React from 'react'; +import { createNativeStackNavigator } from '@react-navigation/native-stack'; +import { + SendDetailsComponent, + ConfirmComponent, + PsbtWithHardwareWalletComponent, + CreateTransactionComponent, + PsbtMultisigComponent, + PsbtMultisigQRCodeComponent, + SuccessComponent, + SelectWalletComponent, + CoinControlComponent, +} from './LazyLoadSendDetailsStack'; +import { useTheme } from '../components/themes'; +import navigationStyle, { navigationStyleTx } from '../components/navigationStyle'; +import loc from '../loc'; + +export type SendDetailsStackParamList = { + SendDetails: { isEditable: boolean }; // Now expects an isEditable boolean + Confirm: undefined; + PsbtWithHardwareWallet: undefined; + CreateTransaction: undefined; + PsbtMultisig: undefined; + PsbtMultisigQRCode: undefined; + Success: undefined; + SelectWallet: undefined; + CoinControl: undefined; +}; + +const Stack = createNativeStackNavigator(); + +const SendDetailsStack = () => { + const theme = useTheme(); + + return ( + + ({ + ...options, + title: loc.send.header, + statusBarStyle: 'light', + }))(theme)} + initialParams={{ isEditable: true }} // Correctly typed now + /> + + + + + + + + + + ); +}; + +export default SendDetailsStack; diff --git a/screen/send/coinControl.js b/screen/send/coinControl.js index 0f28ca5c1..392d8c033 100644 --- a/screen/send/coinControl.js +++ b/screen/send/coinControl.js @@ -21,7 +21,6 @@ import * as RNLocalize from 'react-native-localize'; import loc, { formatBalance } from '../../loc'; import { BitcoinUnit } from '../../models/bitcoinUnits'; import { BlueSpacing10, BlueSpacing20 } from '../../BlueComponents'; -import navigationStyle from '../../components/navigationStyle'; import BottomModal from '../../components/BottomModal'; import { FContainer, FButton } from '../../components/FloatButtons'; import debounce from '../../blue_modules/debounce'; @@ -475,6 +474,4 @@ const styles = StyleSheet.create({ }, }); -CoinControl.navigationOptions = navigationStyle({}, opts => ({ ...opts, title: loc.cc.header })); - export default CoinControl; diff --git a/screen/send/confirm.js b/screen/send/confirm.js index 00090e88f..e95393583 100644 --- a/screen/send/confirm.js +++ b/screen/send/confirm.js @@ -8,7 +8,6 @@ import * as bitcoin from 'bitcoinjs-lib'; import PayjoinTransaction from '../../class/payjoin-transaction'; import { BlueText, BlueCard } from '../../BlueComponents'; -import navigationStyle from '../../components/navigationStyle'; import { BitcoinUnit } from '../../models/bitcoinUnits'; import Biometric from '../../class/biometrics'; import loc, { formatBalance, formatBalanceWithoutSuffix } from '../../loc'; @@ -340,5 +339,3 @@ const styles = StyleSheet.create({ fontWeight: 'bold', }, }); - -Confirm.navigationOptions = navigationStyle({}, opts => ({ ...opts, title: loc.send.confirm_header })); diff --git a/screen/send/create.js b/screen/send/create.js index dd7165cbf..511a81685 100644 --- a/screen/send/create.js +++ b/screen/send/create.js @@ -7,9 +7,7 @@ import Share from 'react-native-share'; import RNFS from 'react-native-fs'; import BigNumber from 'bignumber.js'; import * as bitcoin from 'bitcoinjs-lib'; - import { BlueText } from '../../BlueComponents'; -import navigationStyle from '../../components/navigationStyle'; import { BitcoinUnit } from '../../models/bitcoinUnits'; import loc from '../../loc'; import { DynamicQRCode } from '../../components/DynamicQRCode'; @@ -240,10 +238,3 @@ const styles = StyleSheet.create({ alignSelf: 'center', }, }); - -SendCreate.navigationOptions = navigationStyle({}, (options, { theme, navigation, route }) => { - return { - ...options, - title: loc.send.create_details, - }; -}); diff --git a/screen/send/details.js b/screen/send/details.js index 756bdbbcb..348398b43 100644 --- a/screen/send/details.js +++ b/screen/send/details.js @@ -41,7 +41,6 @@ import CoinsSelected from '../../components/CoinsSelected'; import InputAccessoryAllFunds from '../../components/InputAccessoryAllFunds'; import ListItem from '../../components/ListItem'; import ToolTipMenu from '../../components/TooltipMenu'; -import { navigationStyleTx } from '../../components/navigationStyle'; import { useTheme } from '../../components/themes'; import prompt from '../../helpers/prompt'; import { requestCameraAuthorization, scanQrHelper } from '../../helpers/scan-qr'; @@ -1653,11 +1652,3 @@ const styles = StyleSheet.create({ marginVertical: 8, }, }); - -SendDetails.navigationOptions = navigationStyleTx({}, options => ({ - ...options, - title: loc.send.header, - statusBarStyle: 'light', -})); - -SendDetails.initialParams = { isEditable: true }; diff --git a/screen/send/psbtMultisig.js b/screen/send/psbtMultisig.js index 854ee94e2..886ec070d 100644 --- a/screen/send/psbtMultisig.js +++ b/screen/send/psbtMultisig.js @@ -4,9 +4,7 @@ import { Icon } from 'react-native-elements'; import { useNavigation, useRoute } from '@react-navigation/native'; import * as bitcoin from 'bitcoinjs-lib'; import BigNumber from 'bignumber.js'; - import { BlueCard, BlueText } from '../../BlueComponents'; -import navigationStyle from '../../components/navigationStyle'; import loc from '../../loc'; import { BitcoinUnit } from '../../models/bitcoinUnits'; import { BlueStorageContext } from '../../blue_modules/storage-context'; @@ -403,6 +401,4 @@ const styles = StyleSheet.create({ }, }); -PsbtMultisig.navigationOptions = navigationStyle({}, opts => ({ ...opts, title: loc.multisig.header })); - export default PsbtMultisig; diff --git a/screen/send/psbtMultisigQRCode.js b/screen/send/psbtMultisigQRCode.js index 2f2b68814..b3cd38873 100644 --- a/screen/send/psbtMultisigQRCode.js +++ b/screen/send/psbtMultisigQRCode.js @@ -7,7 +7,6 @@ import presentAlert from '../../components/Alert'; import { DynamicQRCode } from '../../components/DynamicQRCode'; import SafeArea from '../../components/SafeArea'; import { SquareButton } from '../../components/SquareButton'; -import navigationStyle from '../../components/navigationStyle'; import { useTheme } from '../../components/themes'; import { scanQrHelper } from '../../helpers/scan-qr'; import loc from '../../loc'; @@ -129,6 +128,4 @@ const styles = StyleSheet.create({ }, }); -PsbtMultisigQRCode.navigationOptions = navigationStyle({}, opts => ({ ...opts, title: loc.multisig.header })); - export default PsbtMultisigQRCode; diff --git a/screen/send/psbtWithHardwareWallet.js b/screen/send/psbtWithHardwareWallet.js index a3bd43262..ea5ce92a2 100644 --- a/screen/send/psbtWithHardwareWallet.js +++ b/screen/send/psbtWithHardwareWallet.js @@ -15,7 +15,6 @@ import presentAlert from '../../components/Alert'; import CopyToClipboardButton from '../../components/CopyToClipboardButton'; import { DynamicQRCode } from '../../components/DynamicQRCode'; import { SecondButton } from '../../components/SecondButton'; -import navigationStyle from '../../components/navigationStyle'; import { useTheme } from '../../components/themes'; import { requestCameraAuthorization } from '../../helpers/scan-qr'; import loc from '../../loc'; @@ -300,13 +299,6 @@ const PsbtWithHardwareWallet = () => { export default PsbtWithHardwareWallet; -PsbtWithHardwareWallet.navigationOptions = navigationStyle({}, opts => ({ - ...opts, - title: loc.send.header, - gestureEnabled: false, - fullScreenGestureEnabled: false, -})); - const styles = StyleSheet.create({ scrollViewContent: { flexGrow: 1, diff --git a/screen/wallets/selectWallet.js b/screen/wallets/selectWallet.js index 1e80b3a52..eed764fce 100644 --- a/screen/wallets/selectWallet.js +++ b/screen/wallets/selectWallet.js @@ -2,9 +2,7 @@ import React, { useContext, useEffect, useState } from 'react'; import { View, ActivityIndicator, Image, Text, TouchableOpacity, I18nManager, FlatList, StyleSheet } from 'react-native'; import LinearGradient from 'react-native-linear-gradient'; import { useRoute, useNavigation, useNavigationState } from '@react-navigation/native'; - import { BlueText, BlueSpacing20 } from '../../BlueComponents'; -import navigationStyle from '../../components/navigationStyle'; import WalletGradient from '../../class/wallet-gradient'; import loc, { formatBalance, transactionTimeToReadable } from '../../loc'; import { LightningLdkWallet, MultisigHDWallet, LightningCustodianWallet } from '../../class'; @@ -212,6 +210,4 @@ const SelectWallet = () => { } }; -SelectWallet.navigationOptions = navigationStyle({}, opts => ({ ...opts, headerTitle: loc.wallets.select_wallet })); - export default SelectWallet;