2020-12-07 19:05:35 +01:00
|
|
|
import React, { useState, useContext } from 'react';
|
|
|
|
import { StyleSheet, View, KeyboardAvoidingView, Platform, TextInput } from 'react-native';
|
|
|
|
import loc from '../../loc';
|
|
|
|
import {
|
|
|
|
SafeBlueArea,
|
|
|
|
BlueCard,
|
|
|
|
BlueButton,
|
|
|
|
BlueSpacing10,
|
|
|
|
BlueSpacing20,
|
|
|
|
BlueFormLabel,
|
|
|
|
BlueNavigationStyle,
|
|
|
|
BlueText,
|
|
|
|
BlueButtonLink,
|
|
|
|
} from '../../BlueComponents';
|
|
|
|
import { BlueCurrentTheme } from '../../components/themes';
|
|
|
|
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
2020-12-07 19:24:24 +01:00
|
|
|
import { useNavigation, useRoute, useTheme } from '@react-navigation/native';
|
2020-12-07 19:05:35 +01:00
|
|
|
|
|
|
|
const IsItMyAddress = () => {
|
|
|
|
/** @type {AbstractWallet[]} */
|
|
|
|
const wallets = useContext(BlueStorageContext).wallets;
|
2020-12-07 19:24:24 +01:00
|
|
|
const { navigate } = useNavigation();
|
|
|
|
const { name } = useRoute();
|
|
|
|
const { colors } = useTheme();
|
2020-12-07 19:05:35 +01:00
|
|
|
|
|
|
|
const [address, setAddress] = useState('');
|
|
|
|
const [result, setResult] = useState('');
|
|
|
|
|
2020-12-07 19:24:24 +01:00
|
|
|
const stylesHooks = StyleSheet.create({
|
|
|
|
blueArea: {
|
|
|
|
backgroundColor: colors.background,
|
|
|
|
},
|
|
|
|
text: {
|
|
|
|
color: colors.foregroundColor,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
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-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)) {
|
|
|
|
_result.push(loc.formatString(loc.is_it_my_address.owns, { label: w.getLabel(), address: cleanAddress }));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2020-12-07 19:55:50 +01:00
|
|
|
const importScan = () => {
|
2020-12-07 19:24:24 +01:00
|
|
|
navigate('ScanQRCodeRoot', {
|
2020-12-07 19:05:35 +01:00
|
|
|
screen: 'ScanQRCode',
|
|
|
|
params: {
|
2020-12-07 19:24:24 +01:00
|
|
|
launchedBy: name,
|
|
|
|
onBarScanned,
|
2020-12-07 19:05:35 +01:00
|
|
|
showFileImportButton: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2020-12-07 19:24:24 +01:00
|
|
|
<SafeBlueArea style={[styles.blueArea, stylesHooks.blueArea]}>
|
2020-12-07 19:05:35 +01:00
|
|
|
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'position' : null} keyboardShouldPersistTaps="handled">
|
|
|
|
<View style={styles.wrapper}>
|
|
|
|
<BlueCard style={styles.mainCard}>
|
|
|
|
<View style={styles.topFormRow}>
|
|
|
|
<BlueFormLabel>{loc.is_it_my_address.enter_address}</BlueFormLabel>
|
|
|
|
</View>
|
|
|
|
<TextInput
|
2020-12-07 19:24:24 +01:00
|
|
|
style={[styles.text, stylesHooks.text]}
|
2020-12-07 19:05:35 +01:00
|
|
|
maxHeight={100}
|
|
|
|
minHeight={100}
|
|
|
|
maxWidth="100%"
|
|
|
|
minWidth="100%"
|
|
|
|
multiline
|
|
|
|
editable
|
|
|
|
value={address}
|
|
|
|
onChangeText={handleUpdateAddress}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<BlueSpacing10 />
|
|
|
|
<BlueButtonLink title={loc.wallets.import_scan_qr} onPress={importScan} />
|
|
|
|
<BlueSpacing10 />
|
|
|
|
<BlueButton title={loc.is_it_my_address.check_address} onPress={checkAddress} />
|
|
|
|
<BlueSpacing20 />
|
|
|
|
<BlueText>{result}</BlueText>
|
|
|
|
</BlueCard>
|
|
|
|
</View>
|
|
|
|
</KeyboardAvoidingView>
|
|
|
|
</SafeBlueArea>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default IsItMyAddress;
|
|
|
|
IsItMyAddress.navigationOptions = () => ({
|
|
|
|
...BlueNavigationStyle(),
|
|
|
|
title: loc.is_it_my_address.title,
|
|
|
|
});
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
wrapper: {
|
|
|
|
marginTop: 16,
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'flex-start',
|
|
|
|
},
|
|
|
|
blueArea: {
|
|
|
|
flex: 1,
|
|
|
|
paddingTop: 19,
|
|
|
|
},
|
|
|
|
broadcastResultWrapper: {
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'column',
|
|
|
|
justifyContent: 'center',
|
|
|
|
alignItems: 'center',
|
|
|
|
height: '100%',
|
|
|
|
width: '100%',
|
|
|
|
},
|
|
|
|
mainCard: {
|
|
|
|
padding: 0,
|
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'column',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'flex-start',
|
|
|
|
},
|
|
|
|
topFormRow: {
|
|
|
|
flex: 0.1,
|
|
|
|
flexBasis: 0.1,
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
paddingBottom: 10,
|
|
|
|
paddingTop: 0,
|
|
|
|
paddingRight: 100,
|
|
|
|
height: 30,
|
|
|
|
maxHeight: 30,
|
|
|
|
},
|
|
|
|
text: {
|
|
|
|
flex: 1,
|
|
|
|
borderColor: '#ebebeb',
|
|
|
|
backgroundColor: '#d2f8d6',
|
|
|
|
borderRadius: 4,
|
|
|
|
marginTop: 20,
|
|
|
|
color: BlueCurrentTheme.colors.foregroundColor,
|
|
|
|
fontWeight: '500',
|
|
|
|
fontSize: 14,
|
|
|
|
paddingHorizontal: 16,
|
|
|
|
paddingBottom: 16,
|
|
|
|
paddingTop: 16,
|
|
|
|
},
|
|
|
|
});
|