From 13389ca2537830ddbe7f291c1357dbeadc899227 Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Fri, 25 Oct 2024 18:04:01 -0400 Subject: [PATCH] wip --- navigation/AddWalletStack.tsx | 13 ++++++--- screen/wallets/Add.tsx | 48 ++++++++++++++++++++------------- typings/CommonToolTipActions.ts | 1 + 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/navigation/AddWalletStack.tsx b/navigation/AddWalletStack.tsx index e8d9f736f..ae47a7b7a 100644 --- a/navigation/AddWalletStack.tsx +++ b/navigation/AddWalletStack.tsx @@ -31,9 +31,16 @@ export type AddWalletStackParamList = { importText: string; password: string | undefined; }; - PleaseBackup: undefined; - PleaseBackupLNDHub: undefined; - ProvideEntropy: undefined; + PleaseBackup: { + walletID: string; + }; + PleaseBackupLNDHub: { + walletID: string; + }; + ProvideEntropy: { + onGenerated: (entropy: Buffer) => void; + words: number; + }; WalletsAddMultisig: { walletLabel: string; }; diff --git a/screen/wallets/Add.tsx b/screen/wallets/Add.tsx index 0602bbb27..9c3429111 100644 --- a/screen/wallets/Add.tsx +++ b/screen/wallets/Add.tsx @@ -1,4 +1,3 @@ -import { useNavigation } from '@react-navigation/native'; import React, { useCallback, useEffect, useMemo, useReducer } from 'react'; import { ActivityIndicator, @@ -29,6 +28,9 @@ import { CommonToolTipActions } from '../../typings/CommonToolTipActions'; import { Action } from '../../components/types'; import { getLNDHub } from '../../helpers/lndHub'; import HeaderMenuButton from '../../components/HeaderMenuButton'; +import { useExtendedNavigation } from '../../hooks/useExtendedNavigation'; +import { NativeStackNavigationProp } from '@react-navigation/native-stack'; +import { AddWalletStackParamList } from '../../navigation/AddWalletStack'; enum ButtonSelected { // @ts-ignore: Return later to update @@ -98,6 +100,7 @@ const walletReducer = (state: State, action: TAction): State => { } }; +type NavigationProps = NativeStackNavigationProp; const WalletsAdd: React.FC = () => { const { colors } = useTheme(); @@ -113,7 +116,7 @@ const WalletsAdd: React.FC = () => { const colorScheme = useColorScheme(); // const { addWallet, saveToDisk } = useStorage(); - const { navigate, goBack, setOptions } = useNavigation(); + const { navigate, goBack, setOptions } = useExtendedNavigation(); const stylesHook = { advancedText: { color: colors.feeText, @@ -191,10 +194,16 @@ const WalletsAdd: React.FC = () => { onPress: () => {}, style: 'cancel', }, + { + text: loc.settings.electrum_reset, + onPress: () => { + confirmResetEntropy(ButtonSelected.ONCHAIN); + }, + style: 'destructive', + }, { text: loc.wallets.add_wallet_seed_length_12, onPress: () => { - // @ts-ignore: Return later to update navigate('ProvideEntropy', { onGenerated: entropyGenerated, words: 12 }); }, style: 'default', @@ -202,14 +211,13 @@ const WalletsAdd: React.FC = () => { { text: loc.wallets.add_wallet_seed_length_24, onPress: () => { - // @ts-ignore: Return later to update navigate('ProvideEntropy', { onGenerated: entropyGenerated, words: 24 }); }, }, ], { cancelable: true }, ); - }, [entropyGenerated, navigate]); + }, [confirmResetEntropy, entropyGenerated, navigate]); const toolTipActions = useMemo(() => { const walletSubactions: Action[] = [ @@ -249,10 +257,11 @@ const WalletsAdd: React.FC = () => { const entropyAction = { ...CommonToolTipActions.Entropy, text: entropyButtonText, + menuState: !!entropy, }; return selectedWalletType === ButtonSelected.ONCHAIN ? [walletAction, entropyAction] : [walletAction]; - }, [entropyButtonText, selectedIndex, selectedWalletType]); + }, [entropy, entropyButtonText, selectedIndex, selectedWalletType]); const handleOnLightningButtonPressed = useCallback(() => { confirmResetEntropy(ButtonSelected.OFFCHAIN); }, [confirmResetEntropy]); @@ -361,7 +370,6 @@ const WalletsAdd: React.FC = () => { A(A.ENUM.CREATED_WALLET); triggerHapticFeedback(HapticFeedbackTypes.NotificationSuccess); if (w.type === HDSegwitP2SHWallet.type || w.type === HDSegwitBech32Wallet.type) { - // @ts-ignore: Return later to update navigate('PleaseBackup', { walletID: w.getID(), }); @@ -371,7 +379,6 @@ const WalletsAdd: React.FC = () => { } } else if (selectedWalletType === ButtonSelected.VAULT) { setIsLoading(false); - // @ts-ignore: Return later to update navigate('WalletsAddMultisig', { walletLabel: label.trim().length > 0 ? label : loc.multisig.default_label }); } }; @@ -410,14 +417,12 @@ const WalletsAdd: React.FC = () => { A(A.ENUM.CREATED_WALLET); triggerHapticFeedback(HapticFeedbackTypes.NotificationSuccess); - // @ts-ignore: Return later to update navigate('PleaseBackupLNDHub', { walletID: wallet.getID(), }); }; const navigateToImportWallet = () => { - // @ts-ignore: Return later to update navigate('ImportWallet'); }; @@ -436,6 +441,19 @@ const WalletsAdd: React.FC = () => { Linking.openURL('https://bluewallet.io/lightning/'); }; + const LightningButtonMemo = useMemo( + () => ( + + ), + [selectedWalletType, handleOnLightningButtonPressed], + ); + return ( @@ -468,15 +486,7 @@ const WalletsAdd: React.FC = () => { onPress={handleOnVaultButtonPressed} size={styles.button} /> - {selectedWalletType === ButtonSelected.OFFCHAIN && ( - - )} + {selectedWalletType === ButtonSelected.OFFCHAIN && LightningButtonMemo} {selectedWalletType === ButtonSelected.OFFCHAIN && ( diff --git a/typings/CommonToolTipActions.ts b/typings/CommonToolTipActions.ts index 2e8f185b8..237c1fea7 100644 --- a/typings/CommonToolTipActions.ts +++ b/typings/CommonToolTipActions.ts @@ -150,6 +150,7 @@ export const CommonToolTipActions = { id: keys.Entropy, text: loc.wallets.add_entropy_provide, icon: icons.Entropy, + menuState: false, }, RemoveAllRecipients: { id: keys.RemoveAllRecipients,