2018-07-22 16:49:59 +02:00
|
|
|
/* global alert */
|
2019-12-27 03:21:07 +01:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2019-08-29 06:18:32 +02:00
|
|
|
import { KeyboardAvoidingView, Platform, Dimensions, View, TouchableWithoutFeedback, Keyboard } from 'react-native';
|
2018-07-22 16:49:59 +02:00
|
|
|
import {
|
|
|
|
BlueFormMultiInput,
|
|
|
|
BlueButtonLink,
|
|
|
|
BlueFormLabel,
|
2019-08-29 06:18:32 +02:00
|
|
|
BlueDoneAndDismissKeyboardInputAccessory,
|
2018-07-22 16:49:59 +02:00
|
|
|
BlueButton,
|
|
|
|
SafeBlueArea,
|
2018-10-23 00:51:30 +02:00
|
|
|
BlueSpacing20,
|
2018-12-25 21:53:24 +01:00
|
|
|
BlueNavigationStyle,
|
2018-07-22 16:49:59 +02:00
|
|
|
} from '../../BlueComponents';
|
2018-12-13 17:50:18 +01:00
|
|
|
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
|
2019-02-28 02:29:13 +01:00
|
|
|
import Privacy from '../../Privacy';
|
2019-12-27 03:21:07 +01:00
|
|
|
import { useNavigation, useNavigationParam } from 'react-navigation-hooks';
|
|
|
|
import WalletImport from '../../class/walletImport';
|
2018-07-22 16:49:59 +02:00
|
|
|
let loc = require('../../loc');
|
|
|
|
const { width } = Dimensions.get('window');
|
|
|
|
|
2019-12-27 03:21:07 +01:00
|
|
|
const WalletsImport = () => {
|
|
|
|
const [isToolbarVisibleForAndroid, setIsToolbarVisibleForAndroid] = useState(false);
|
|
|
|
const [importText, setImportText] = useState(useNavigationParam('label') || '');
|
|
|
|
const { navigate, dismiss } = useNavigation();
|
2018-07-22 16:49:59 +02:00
|
|
|
|
2019-12-27 03:21:07 +01:00
|
|
|
useEffect(() => {
|
2019-02-28 02:29:13 +01:00
|
|
|
Privacy.enableBlur();
|
2019-12-27 03:21:07 +01:00
|
|
|
return () => Privacy.disableBlur();
|
|
|
|
});
|
2019-02-28 02:29:13 +01:00
|
|
|
|
2019-12-27 03:21:07 +01:00
|
|
|
const importButtonPressed = () => {
|
|
|
|
if (importText.trim().length === 0) {
|
|
|
|
return;
|
2018-12-28 00:33:39 +01:00
|
|
|
}
|
2019-12-27 03:21:07 +01:00
|
|
|
importMnemonic(importText);
|
|
|
|
};
|
2018-07-22 16:49:59 +02:00
|
|
|
|
2020-02-25 15:42:11 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param importText
|
|
|
|
* @param additionalProperties key-values passed from outside. Used only to set up `masterFingerprint` property for watch-only wallet
|
|
|
|
*/
|
2020-01-01 04:31:04 +01:00
|
|
|
const importMnemonic = (importText, additionalProperties) => {
|
2018-07-22 16:49:59 +02:00
|
|
|
try {
|
2020-01-01 04:31:04 +01:00
|
|
|
WalletImport.processImportText(importText, additionalProperties);
|
2019-12-27 03:21:07 +01:00
|
|
|
dismiss();
|
|
|
|
} catch (error) {
|
|
|
|
alert(loc.wallets.import.error);
|
|
|
|
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
|
2018-07-22 16:49:59 +02:00
|
|
|
}
|
2019-12-27 03:21:07 +01:00
|
|
|
};
|
2018-07-22 16:49:59 +02:00
|
|
|
|
2020-02-25 15:42:11 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param value
|
|
|
|
* @param additionalProperties key-values passed from outside. Used only to set up `masterFingerprint` property for watch-only wallet
|
|
|
|
*/
|
2020-01-01 04:31:04 +01:00
|
|
|
const onBarScanned = (value, additionalProperties) => {
|
2019-12-27 03:21:07 +01:00
|
|
|
setImportText(value);
|
2020-01-01 04:31:04 +01:00
|
|
|
importMnemonic(value, additionalProperties);
|
2019-12-27 03:21:07 +01:00
|
|
|
};
|
2019-02-02 00:00:44 +01:00
|
|
|
|
2019-12-27 03:21:07 +01:00
|
|
|
return (
|
|
|
|
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={{ flex: 1, paddingTop: 40 }}>
|
|
|
|
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
|
|
|
|
<KeyboardAvoidingView behavior="position" enabled>
|
|
|
|
<BlueFormLabel>{loc.wallets.import.explanation}</BlueFormLabel>
|
|
|
|
<BlueSpacing20 />
|
|
|
|
<BlueFormMultiInput
|
|
|
|
value={importText}
|
|
|
|
contextMenuHidden
|
|
|
|
onChangeText={setImportText}
|
|
|
|
inputAccessoryViewID={BlueDoneAndDismissKeyboardInputAccessory.InputAccessoryViewID}
|
|
|
|
onFocus={() => setIsToolbarVisibleForAndroid(true)}
|
|
|
|
onBlur={() => setIsToolbarVisibleForAndroid(false)}
|
2019-02-02 00:00:44 +01:00
|
|
|
/>
|
2019-12-27 03:21:07 +01:00
|
|
|
{Platform.select({
|
|
|
|
ios: (
|
|
|
|
<BlueDoneAndDismissKeyboardInputAccessory
|
|
|
|
onClearTapped={() => {
|
|
|
|
setImportText('');
|
|
|
|
Keyboard.dismiss();
|
|
|
|
}}
|
|
|
|
onPasteTapped={text => {
|
|
|
|
setImportText(text);
|
|
|
|
Keyboard.dismiss();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
android: isToolbarVisibleForAndroid && (
|
|
|
|
<BlueDoneAndDismissKeyboardInputAccessory
|
|
|
|
onClearTapped={() => {
|
|
|
|
setImportText('');
|
|
|
|
Keyboard.dismiss();
|
|
|
|
}}
|
|
|
|
onPasteTapped={text => {
|
|
|
|
setImportText(text);
|
|
|
|
Keyboard.dismiss();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
})}
|
|
|
|
</KeyboardAvoidingView>
|
|
|
|
</TouchableWithoutFeedback>
|
|
|
|
|
|
|
|
<BlueSpacing20 />
|
|
|
|
<View
|
|
|
|
style={{
|
|
|
|
alignItems: 'center',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<BlueButton
|
|
|
|
disabled={importText.trim().length === 0}
|
|
|
|
title={loc.wallets.import.do_import}
|
|
|
|
buttonStyle={{
|
|
|
|
width: width / 1.5,
|
|
|
|
}}
|
|
|
|
onPress={importButtonPressed}
|
|
|
|
/>
|
|
|
|
<BlueButtonLink
|
2020-02-25 15:42:11 +01:00
|
|
|
title={loc.wallets.import.scan_qr}
|
2019-12-27 03:21:07 +01:00
|
|
|
onPress={() => {
|
2020-03-13 15:23:12 +01:00
|
|
|
navigate('ScanQRCode', { launchedBy: 'ImportWallet', onBarScanned, showFileImportButton: true });
|
2019-12-27 03:21:07 +01:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
</SafeBlueArea>
|
|
|
|
);
|
|
|
|
};
|
2018-07-22 16:49:59 +02:00
|
|
|
|
2019-12-27 03:21:07 +01:00
|
|
|
WalletsImport.navigationOptions = {
|
|
|
|
...BlueNavigationStyle(),
|
|
|
|
title: loc.wallets.import.title,
|
2018-07-22 16:49:59 +02:00
|
|
|
};
|
2019-12-27 03:21:07 +01:00
|
|
|
export default WalletsImport;
|