From 1c15ae0a0c5e73471804d2ca15eedd200c42fff4 Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Thu, 13 Feb 2025 18:38:37 -0400 Subject: [PATCH] REF: Reuse AddressInput component --- components/AddressInput.tsx | 14 +----- components/AddressInputScanButton.tsx | 29 ++---------- screen/send/SendDetails.tsx | 3 -- screen/settings/ElectrumSettings.tsx | 5 -- screen/settings/LightningSettings.tsx | 64 +++++-------------------- screen/wallets/ManageWallets.tsx | 68 +++------------------------ 6 files changed, 23 insertions(+), 160 deletions(-) diff --git a/components/AddressInput.tsx b/components/AddressInput.tsx index b253c0943..143f86ab8 100644 --- a/components/AddressInput.tsx +++ b/components/AddressInput.tsx @@ -11,9 +11,7 @@ interface AddressInputProps { address?: string; placeholder?: string; onChangeText: (text: string) => void; - onBarScanned: (ret: { data?: any }) => void; scanButtonTapped?: () => void; - launchedBy?: string; editable?: boolean; inputAccessoryViewID?: string; onFocus?: () => void; @@ -43,9 +41,7 @@ const AddressInput = ({ testID = 'AddressInput', placeholder = loc.send.details_address, onChangeText, - onBarScanned, scanButtonTapped = () => {}, - launchedBy, editable = true, inputAccessoryViewID, onFocus = () => {}, @@ -108,15 +104,7 @@ const AddressInput = ({ keyboardType={keyboardType} {...(skipValidation ? { onBlur } : { onBlur: onBlurEditing })} /> - {editable ? ( - - ) : null} + {editable ? : null} ); }; diff --git a/components/AddressInputScanButton.tsx b/components/AddressInputScanButton.tsx index 5c7a0bcc6..bef64b3cf 100644 --- a/components/AddressInputScanButton.tsx +++ b/components/AddressInputScanButton.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useEffect, useMemo } from 'react'; +import React, { useCallback, useMemo } from 'react'; import { Image, Keyboard, Platform, StyleSheet, Text } from 'react-native'; import Clipboard from '@react-native-clipboard/clipboard'; import ToolTipMenu from './TooltipMenu'; @@ -9,33 +9,19 @@ import { useTheme } from './themes'; import RNQRGenerator from 'rn-qr-generator'; import { CommonToolTipActions } from '../typings/CommonToolTipActions'; import { useSettings } from '../hooks/context/useSettings'; -import { useRoute } from '@react-navigation/native'; import { useExtendedNavigation } from '../hooks/useExtendedNavigation'; interface AddressInputScanButtonProps { isLoading: boolean; - launchedBy?: string; scanButtonTapped: () => void; - onBarScanned: (ret: { data?: any }) => void; onChangeText: (text: string) => void; } -interface RouteParams { - onBarScanned?: any; -} - -export const AddressInputScanButton = ({ - isLoading, - launchedBy, - scanButtonTapped, - onBarScanned, - onChangeText, -}: AddressInputScanButtonProps) => { +export const AddressInputScanButton = ({ isLoading, scanButtonTapped, onChangeText }: AddressInputScanButtonProps) => { const { colors } = useTheme(); const { isClipboardGetContentEnabled } = useSettings(); const navigation = useExtendedNavigation(); - const params = useRoute().params as RouteParams; const stylesHook = StyleSheet.create({ scan: { backgroundColor: colors.scanLabel, @@ -67,17 +53,8 @@ export const AddressInputScanButton = ({ return availableActions; }, [isClipboardGetContentEnabled]); - useEffect(() => { - const data = params.onBarScanned; - if (data) { - onBarScanned({ data }); - navigation.setParams({ onBarScanned: undefined }); - } - }); - const onMenuItemPressed = useCallback( async (action: string) => { - if (onBarScanned === undefined) throw new Error('onBarScanned is required'); switch (action) { case CommonToolTipActions.ScanQR.id: scanButtonTapped(); @@ -147,7 +124,7 @@ export const AddressInputScanButton = ({ } Keyboard.dismiss(); }, - [navigation, onBarScanned, onChangeText, scanButtonTapped], + [navigation, onChangeText, scanButtonTapped], ); const buttonStyle = useMemo(() => [styles.scan, stylesHook.scan], [stylesHook.scan]); diff --git a/screen/send/SendDetails.tsx b/screen/send/SendDetails.tsx index beb6929d1..e0fedd0e1 100644 --- a/screen/send/SendDetails.tsx +++ b/screen/send/SendDetails.tsx @@ -81,7 +81,6 @@ const SendDetails = () => { const selectedDataProcessor = useRef(); const setParams = navigation.setParams; const route = useRoute(); - const name = route.name; const feeUnit = route.params?.feeUnit ?? BitcoinUnit.BTC; const amountUnit = route.params?.amountUnit ?? BitcoinUnit.BTC; const frozenBalance = route.params?.frozenBalance ?? 0; @@ -1312,11 +1311,9 @@ const SendDetails = () => { setIsLoading(false); setParams({ payjoinUrl: pjUrl }); }} - onBarScanned={processAddressData} address={item.address} isLoading={isLoading} inputAccessoryViewID={DismissKeyboardInputAccessoryViewID} - launchedBy={name} editable={isEditable} style={styles.addressInput} /> diff --git a/screen/settings/ElectrumSettings.tsx b/screen/settings/ElectrumSettings.tsx index 4244da490..324f97e30 100644 --- a/screen/settings/ElectrumSettings.tsx +++ b/screen/settings/ElectrumSettings.tsx @@ -416,10 +416,6 @@ const ElectrumSettings: React.FC = () => { } }; - const importScan = async () => { - navigation.navigate('ScanQRCode'); - }; - useEffect(() => { const data = params.onBarScanned; if (data) { @@ -494,7 +490,6 @@ const ElectrumSettings: React.FC = () => { address={host} onChangeText={text => setHost(text.trim())} editable={!isLoading} - onBarScanned={importScan} keyboardType="default" skipValidation onBlur={() => setIsAndroidAddressKeyboardVisible(false)} diff --git a/screen/settings/LightningSettings.tsx b/screen/settings/LightningSettings.tsx index 9fecf1dcc..ee0468712 100644 --- a/screen/settings/LightningSettings.tsx +++ b/screen/settings/LightningSettings.tsx @@ -1,9 +1,9 @@ import React, { useCallback, useEffect, useState } from 'react'; import { RouteProp, useRoute } from '@react-navigation/native'; -import { Alert, I18nManager, Linking, ScrollView, StyleSheet, TextInput, View } from 'react-native'; +import { Alert, I18nManager, Linking, ScrollView, StyleSheet } from 'react-native'; import { Button as ButtonRNElements } from '@rneui/themed'; import DefaultPreference from 'react-native-default-preference'; -import { BlueButtonLink, BlueCard, BlueLoading, BlueSpacing20, BlueText } from '../../BlueComponents'; +import { BlueCard, BlueLoading, BlueSpacing40, BlueText } from '../../BlueComponents'; import DeeplinkSchemaMatch from '../../class/deeplink-schema-match'; import { LightningCustodianWallet } from '../../class/wallets/lightning-custodian-wallet'; import presentAlert, { AlertType } from '../../components/Alert'; @@ -15,24 +15,9 @@ import { GROUP_IO_BLUEWALLET } from '../../blue_modules/currency'; import { clearLNDHub, getLNDHub, setLNDHub } from '../../helpers/lndHub'; import { DetailViewStackParamList } from '../../navigation/DetailViewStackParamList'; import { useExtendedNavigation } from '../../hooks/useExtendedNavigation'; +import AddressInput from '../../components/AddressInput'; const styles = StyleSheet.create({ - uri: { - flexDirection: 'row', - borderWidth: 1, - borderBottomWidth: 0.5, - minHeight: 44, - height: 44, - alignItems: 'center', - borderRadius: 4, - }, - uriText: { - flex: 1, - color: '#81868e', - marginHorizontal: 8, - minHeight: 36, - height: 36, - }, buttonStyle: { backgroundColor: 'transparent', flexDirection: I18nManager.isRTL ? 'row-reverse' : 'row', @@ -46,14 +31,7 @@ const LightningSettings: React.FC = () => { const [isLoading, setIsLoading] = useState(true); const [URI, setURI] = useState(); const { colors } = useTheme(); - const { navigate, setParams } = useExtendedNavigation(); - const styleHook = StyleSheet.create({ - uri: { - borderColor: colors.formBorder, - borderBottomColor: colors.formBorder, - backgroundColor: colors.inputBackgroundColor, - }, - }); + const { setParams } = useExtendedNavigation(); useEffect(() => { const fetchURI = async () => { @@ -123,12 +101,6 @@ const LightningSettings: React.FC = () => { setIsLoading(false); }, [URI]); - const importScan = () => { - navigate('ScanQRCode', { - showFileImportButton: true, - }); - }; - useEffect(() => { const data = params?.onBarScanned; if (data) { @@ -158,25 +130,15 @@ const LightningSettings: React.FC = () => { /> - - - - - - + + {isLoading ? :