2024-05-31 19:22:22 +02:00
|
|
|
import React, { useRef, useState } from 'react';
|
|
|
|
import { useRoute } from '@react-navigation/native';
|
2024-05-20 11:54:13 +02:00
|
|
|
import { Keyboard, KeyboardAvoidingView, Platform, StyleSheet, TextInput, View } from 'react-native';
|
|
|
|
import { BlueButtonLink, BlueCard, BlueSpacing10, BlueSpacing20, BlueText } from '../../BlueComponents';
|
2023-11-15 09:40:22 +01:00
|
|
|
import Button from '../../components/Button';
|
2024-05-20 11:54:13 +02:00
|
|
|
import navigationStyle from '../../components/navigationStyle';
|
2023-12-27 07:52:11 +01:00
|
|
|
import SafeArea from '../../components/SafeArea';
|
2024-05-20 11:54:13 +02:00
|
|
|
import { useTheme } from '../../components/themes';
|
|
|
|
import { requestCameraAuthorization } from '../../helpers/scan-qr';
|
|
|
|
import loc from '../../loc';
|
2024-05-31 19:22:22 +02:00
|
|
|
import { useStorage } from '../../hooks/context/useStorage';
|
|
|
|
import { useExtendedNavigation } from '../../hooks/useExtendedNavigation';
|
2020-12-07 19:05:35 +01:00
|
|
|
|
|
|
|
const IsItMyAddress = () => {
|
|
|
|
/** @type {AbstractWallet[]} */
|
2024-05-31 19:22:22 +02:00
|
|
|
const { wallets } = useStorage();
|
|
|
|
const { navigate } = useExtendedNavigation();
|
2020-12-07 19:24:24 +01:00
|
|
|
const { name } = useRoute();
|
|
|
|
const { colors } = useTheme();
|
2021-02-27 01:23:59 +01:00
|
|
|
const scanButtonRef = useRef();
|
2020-12-07 19:05:35 +01:00
|
|
|
|
|
|
|
const [address, setAddress] = useState('');
|
|
|
|
const [result, setResult] = useState('');
|
2021-09-28 02:53:07 +02:00
|
|
|
const [resultCleanAddress, setResultCleanAddress] = useState();
|
2020-12-07 19:05:35 +01:00
|
|
|
|
2020-12-07 19:24:24 +01:00
|
|
|
const stylesHooks = StyleSheet.create({
|
2020-12-12 19:49:52 +01:00
|
|
|
input: {
|
|
|
|
borderColor: colors.formBorder,
|
|
|
|
borderBottomColor: colors.formBorder,
|
|
|
|
backgroundColor: colors.inputBackgroundColor,
|
|
|
|
},
|
2020-12-07 19:24:24 +01:00
|
|
|
});
|
|
|
|
|
2020-12-07 19:05:35 +01:00
|
|
|
const handleUpdateAddress = nextValue => setAddress(nextValue.trim());
|
|
|
|
|
2020-12-07 19:55:50 +01:00
|
|
|
const checkAddress = () => {
|
2020-12-23 11:32:38 +01:00
|
|
|
Keyboard.dismiss();
|
2020-12-07 19:05:35 +01:00
|
|
|
const cleanAddress = address.replace('bitcoin:', '').replace('BITCOIN:', '').replace('bitcoin=', '').split('?')[0];
|
|
|
|
const _result = [];
|
|
|
|
for (const w of wallets) {
|
|
|
|
if (w.weOwnAddress(cleanAddress)) {
|
2021-09-28 02:53:07 +02:00
|
|
|
setResultCleanAddress(cleanAddress);
|
2020-12-07 19:05:35 +01:00
|
|
|
_result.push(loc.formatString(loc.is_it_my_address.owns, { label: w.getLabel(), address: cleanAddress }));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-12 19:49:52 +01:00
|
|
|
if (_result.length === 0) {
|
|
|
|
setResult(_result.push(loc.is_it_my_address.no_wallet_owns_address));
|
2021-09-28 02:53:07 +02:00
|
|
|
setResultCleanAddress();
|
2020-12-12 19:49:52 +01:00
|
|
|
}
|
|
|
|
|
2020-12-07 19:05:35 +01:00
|
|
|
setResult(_result.join('\n\n'));
|
|
|
|
};
|
|
|
|
|
2020-12-07 19:55:50 +01:00
|
|
|
const onBarScanned = value => {
|
2020-12-07 19:05:35 +01:00
|
|
|
setAddress(value);
|
2021-09-28 02:53:07 +02:00
|
|
|
setResultCleanAddress(value);
|
2020-12-07 19:05:35 +01:00
|
|
|
};
|
|
|
|
|
2020-12-07 19:55:50 +01:00
|
|
|
const importScan = () => {
|
2023-10-17 15:35:10 +02:00
|
|
|
requestCameraAuthorization().then(() => {
|
2023-10-17 15:39:32 +02:00
|
|
|
navigate('ScanQRCodeRoot', {
|
|
|
|
screen: 'ScanQRCode',
|
|
|
|
params: {
|
|
|
|
launchedBy: name,
|
|
|
|
onBarScanned,
|
|
|
|
showFileImportButton: true,
|
|
|
|
},
|
|
|
|
});
|
2023-02-25 17:20:46 +01:00
|
|
|
});
|
2023-10-17 15:39:32 +02:00
|
|
|
};
|
2020-12-07 19:05:35 +01:00
|
|
|
|
2020-12-12 19:49:52 +01:00
|
|
|
const clearAddressInput = () => {
|
|
|
|
setAddress('');
|
|
|
|
setResult();
|
2021-09-28 02:53:07 +02:00
|
|
|
setResultCleanAddress();
|
|
|
|
};
|
|
|
|
|
|
|
|
const viewQRCode = () => {
|
|
|
|
navigate('ReceiveDetailsRoot', {
|
|
|
|
screen: 'ReceiveDetails',
|
|
|
|
params: {
|
|
|
|
address: resultCleanAddress,
|
|
|
|
},
|
|
|
|
});
|
2020-12-12 19:49:52 +01:00
|
|
|
};
|
|
|
|
|
2020-12-07 19:05:35 +01:00
|
|
|
return (
|
2023-12-27 07:52:11 +01:00
|
|
|
<SafeArea style={styles.blueArea}>
|
2021-02-25 02:56:06 +01:00
|
|
|
<KeyboardAvoidingView
|
|
|
|
enabled={!Platform.isPad}
|
|
|
|
behavior={Platform.OS === 'ios' ? 'position' : null}
|
|
|
|
keyboardShouldPersistTaps="handled"
|
|
|
|
>
|
2020-12-07 19:05:35 +01:00
|
|
|
<View style={styles.wrapper}>
|
|
|
|
<BlueCard style={styles.mainCard}>
|
2020-12-12 19:49:52 +01:00
|
|
|
<View style={[styles.input, stylesHooks.input]}>
|
|
|
|
<TextInput
|
|
|
|
style={styles.text}
|
|
|
|
maxHeight={100}
|
|
|
|
minHeight={100}
|
|
|
|
maxWidth="100%"
|
|
|
|
minWidth="100%"
|
|
|
|
multiline
|
|
|
|
editable
|
|
|
|
placeholder={loc.is_it_my_address.enter_address}
|
|
|
|
placeholderTextColor="#81868e"
|
|
|
|
value={address}
|
|
|
|
onChangeText={handleUpdateAddress}
|
2021-03-02 14:38:02 +01:00
|
|
|
testID="AddressInput"
|
2020-12-12 19:49:52 +01:00
|
|
|
/>
|
2020-12-07 19:05:35 +01:00
|
|
|
</View>
|
|
|
|
|
|
|
|
<BlueSpacing10 />
|
2021-02-27 01:23:59 +01:00
|
|
|
<BlueButtonLink ref={scanButtonRef} title={loc.wallets.import_scan_qr} onPress={importScan} />
|
2020-12-07 19:05:35 +01:00
|
|
|
<BlueSpacing10 />
|
2023-11-15 09:40:22 +01:00
|
|
|
<Button title={loc.send.input_clear} onPress={clearAddressInput} />
|
2020-12-12 19:49:52 +01:00
|
|
|
<BlueSpacing20 />
|
2021-09-28 02:53:07 +02:00
|
|
|
{resultCleanAddress && (
|
|
|
|
<>
|
2023-11-15 09:40:22 +01:00
|
|
|
<Button title={loc.is_it_my_address.view_qrcode} onPress={viewQRCode} />
|
2021-09-28 02:53:07 +02:00
|
|
|
<BlueSpacing20 />
|
|
|
|
</>
|
|
|
|
)}
|
2023-11-15 13:54:04 +01:00
|
|
|
<Button
|
2021-03-02 14:38:02 +01:00
|
|
|
disabled={address.trim().length === 0}
|
|
|
|
title={loc.is_it_my_address.check_address}
|
|
|
|
onPress={checkAddress}
|
|
|
|
testID="CheckAddress"
|
|
|
|
/>
|
2020-12-07 19:05:35 +01:00
|
|
|
<BlueSpacing20 />
|
2021-03-02 14:38:02 +01:00
|
|
|
<BlueText testID="Result">{result}</BlueText>
|
2020-12-07 19:05:35 +01:00
|
|
|
</BlueCard>
|
|
|
|
</View>
|
|
|
|
</KeyboardAvoidingView>
|
2023-12-27 07:52:11 +01:00
|
|
|
</SafeArea>
|
2020-12-07 19:05:35 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default IsItMyAddress;
|
2021-02-15 09:03:54 +01:00
|
|
|
IsItMyAddress.navigationOptions = navigationStyle({}, opts => ({ ...opts, title: loc.is_it_my_address.title }));
|
2020-12-07 19:05:35 +01:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
wrapper: {
|
|
|
|
marginTop: 16,
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'flex-start',
|
|
|
|
},
|
|
|
|
mainCard: {
|
|
|
|
padding: 0,
|
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'column',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'flex-start',
|
|
|
|
},
|
2020-12-12 19:49:52 +01:00
|
|
|
input: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
borderWidth: 1,
|
|
|
|
borderBottomWidth: 0.5,
|
|
|
|
alignItems: 'center',
|
2020-12-07 19:05:35 +01:00
|
|
|
borderRadius: 4,
|
2020-12-12 19:49:52 +01:00
|
|
|
},
|
|
|
|
text: {
|
|
|
|
padding: 8,
|
|
|
|
minHeight: 33,
|
|
|
|
color: '#81868e',
|
2020-12-07 19:05:35 +01:00
|
|
|
},
|
|
|
|
});
|