import React, { useRef, useState } from 'react'; import { useRoute } from '@react-navigation/native'; import { Keyboard, KeyboardAvoidingView, Platform, StyleSheet, TextInput, View } from 'react-native'; import { BlueButtonLink, BlueCard, BlueSpacing10, BlueSpacing20, BlueText } from '../../BlueComponents'; import Button from '../../components/Button'; import navigationStyle from '../../components/navigationStyle'; import SafeArea from '../../components/SafeArea'; import { useTheme } from '../../components/themes'; import { requestCameraAuthorization } from '../../helpers/scan-qr'; import loc from '../../loc'; import { useStorage } from '../../hooks/context/useStorage'; import { useExtendedNavigation } from '../../hooks/useExtendedNavigation'; const IsItMyAddress = () => { /** @type {AbstractWallet[]} */ const { wallets } = useStorage(); const { navigate } = useExtendedNavigation(); const { name } = useRoute(); const { colors } = useTheme(); const scanButtonRef = useRef(); const [address, setAddress] = useState(''); const [result, setResult] = useState(''); const [resultCleanAddress, setResultCleanAddress] = useState(); const stylesHooks = StyleSheet.create({ input: { borderColor: colors.formBorder, borderBottomColor: colors.formBorder, backgroundColor: colors.inputBackgroundColor, }, }); const handleUpdateAddress = nextValue => setAddress(nextValue.trim()); const checkAddress = () => { Keyboard.dismiss(); const cleanAddress = address.replace('bitcoin:', '').replace('BITCOIN:', '').replace('bitcoin=', '').split('?')[0]; const _result = []; for (const w of wallets) { if (w.weOwnAddress(cleanAddress)) { setResultCleanAddress(cleanAddress); _result.push(loc.formatString(loc.is_it_my_address.owns, { label: w.getLabel(), address: cleanAddress })); } } if (_result.length === 0) { setResult(_result.push(loc.is_it_my_address.no_wallet_owns_address)); setResultCleanAddress(); } setResult(_result.join('\n\n')); }; const onBarScanned = value => { setAddress(value); setResultCleanAddress(value); }; const importScan = () => { requestCameraAuthorization().then(() => { navigate('ScanQRCodeRoot', { screen: 'ScanQRCode', params: { launchedBy: name, onBarScanned, showFileImportButton: true, }, }); }); }; const clearAddressInput = () => { setAddress(''); setResult(); setResultCleanAddress(); }; const viewQRCode = () => { navigate('ReceiveDetailsRoot', { screen: 'ReceiveDetails', params: { address: resultCleanAddress, }, }); }; return (