import React, { useEffect, useState, useContext } from 'react'; import { Platform, View, Keyboard, StyleSheet, Switch, TouchableWithoutFeedback } from 'react-native'; import { useNavigation, useRoute } from '@react-navigation/native'; import { BlueButtonLink, BlueDoneAndDismissKeyboardInputAccessory, BlueFormLabel, BlueFormMultiInput, BlueSpacing20, BlueText, } from '../../BlueComponents'; import navigationStyle from '../../components/navigationStyle'; import Privacy from '../../blue_modules/Privacy'; 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'; const WalletsImport = () => { const navigation = useNavigation(); const { colors } = useTheme(); const route = useRoute(); const label = route?.params?.label ?? ''; const triggerImport = route?.params?.triggerImport ?? false; const { isAdvancedModeEnabled } = useContext(BlueStorageContext); 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 styles = StyleSheet.create({ root: { paddingTop: 10, backgroundColor: colors.elevated, }, center: { flex: 1, marginHorizontal: 16, backgroundColor: colors.elevated, }, row: { flexDirection: 'row', alignItems: 'center', marginHorizontal: 16, marginTop: 10, justifyContent: 'space-between', }, }); const onBlur = () => { const valueWithSingleWhitespace = importText.replace(/^\s+|\s+$|\s+(?=\s)/g, ''); setImportText(valueWithSingleWhitespace); return valueWithSingleWhitespace; }; useEffect(() => { Privacy.enableBlur(); Keyboard.addListener(Platform.OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow', () => setIsToolbarVisibleForAndroid(true)); Keyboard.addListener(Platform.OS === 'ios' ? 'keyboardWillHide' : 'keyboardDidHide', () => setIsToolbarVisibleForAndroid(false)); return () => { Keyboard.removeAllListeners(Platform.OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow'); Keyboard.removeAllListeners(Platform.OS === 'ios' ? 'keyboardWillHide' : 'keyboardDidHide'); Privacy.disableBlur(); }; }, []); useEffect(() => { isAdvancedModeEnabled().then(setIsAdvancedModeEnabledRender); if (triggerImport) importButtonPressed(); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const importButtonPressed = () => { const textToImport = onBlur(); if (textToImport.trim().length === 0) { return; } importMnemonic(textToImport); }; const importMnemonic = text => { navigation.navigate('ImportWalletDiscovery', { importText: text, askPassphrase, searchAccounts }); }; const onBarScanned = value => { if (value && value.data) value = value.data + ''; // no objects here, only strings setImportText(value); setTimeout(() => importMnemonic(value), 500); }; const importScan = () => { requestCameraAuthorization().then(() => navigation.navigate('ScanQRCodeRoot', { screen: 'ScanQRCode', params: { launchedBy: route.name, onBarScanned, showFileImportButton: true, }, }), ); }; const speedBackdoorTap = () => { setSpeedBackdoor(v => { v += 1; if (v < 5) return v; navigation.navigate('ImportSpeed'); return 0; }); }; const renderOptionsAndImportButton = ( <> {isAdvancedModeEnabledRender && ( <> {loc.wallets.import_passphrase} {loc.wallets.import_search_accounts} )} <>