Merge pull request #1514 from BlueWallet/marcosrdz-patch-4

ADD: If Desktop, show Import file option
This commit is contained in:
Overtorment 2020-09-01 14:01:20 +01:00 committed by GitHub
commit 4cb77a3ce3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 114 additions and 8 deletions

View File

@ -299,6 +299,7 @@
"add_entropy_provide": "Provide entropy via dice rolls",
"add_entropy_remain": "{gen} bytes of generated entropy. Remaining {rem} bytes will be obtained from the System random number generator.",
"add_import_wallet": "Import wallet",
"import_file": "Import File",
"add_lightning": "Lightning",
"add_lndhub": "Connect to your LNDHub",
"add_lndhub_error": "The provided node address is not valid LNDHub node.",

View File

@ -16,9 +16,16 @@ import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
import Privacy from '../../Privacy';
import { useNavigation, useRoute, useTheme } from '@react-navigation/native';
import WalletImport from '../../class/wallet-import';
import Clipboard from '@react-native-community/clipboard';
import ActionSheet from '../ActionSheet';
import ImagePicker from 'react-native-image-picker';
import loc from '../../loc';
import { getSystemName } from 'react-native-device-info';
import RNFS from 'react-native-fs';
import DocumentPicker from 'react-native-document-picker';
const LocalQRCode = require('@remobile/react-native-qrcode-local-image');
const { width } = Dimensions.get('window');
const isDesktop = getSystemName() === 'Mac OS X';
const WalletsImport = () => {
const [isToolbarVisibleForAndroid, setIsToolbarVisibleForAndroid] = useState(false);
@ -87,14 +94,112 @@ const WalletsImport = () => {
};
const importScan = () => {
navigation.navigate('ScanQRCodeRoot', {
screen: 'ScanQRCode',
params: {
launchedBy: route.name,
onBarScanned: onBarScanned,
showFileImportButton: true,
if (isDesktop) {
showActionSheet();
} else {
navigation.navigate('ScanQRCodeRoot', {
screen: 'ScanQRCode',
params: {
launchedBy: route.name,
onBarScanned: onBarScanned,
showFileImportButton: true,
},
});
}
};
const choosePhoto = () => {
ImagePicker.launchImageLibrary(
{
title: null,
mediaType: 'photo',
takePhotoButtonTitle: null,
},
});
response => {
if (response.uri) {
const uri = Platform.OS === 'ios' ? response.uri.toString().replace('file://', '') : response.path.toString();
LocalQRCode.decode(uri, (error, result) => {
if (!error) {
onBarScanned(result);
} else {
alert(loc.send.qr_error_no_qrcode);
}
});
}
},
);
};
const takePhoto = () => {
ImagePicker.launchCamera(
{
title: null,
mediaType: 'photo',
takePhotoButtonTitle: null,
},
response => {
if (response.uri) {
const uri = Platform.OS === 'ios' ? response.uri.toString().replace('file://', '') : response.path.toString();
LocalQRCode.decode(uri, (error, result) => {
if (!error) {
onBarScanned(result);
} else {
alert(loc.send.qr_error_no_qrcode);
}
});
}
},
);
};
const copyFromClipbard = async () => {
onBarScanned(await Clipboard.getString());
};
const handleImportFileButtonPressed = async () => {
try {
const res = await DocumentPicker.pick({
type: [DocumentPicker.types.allFiles],
});
const file = await RNFS.readFile(res.uri);
if (file) {
onBarScanned(file);
} else {
throw new Error();
}
} catch (err) {
if (!DocumentPicker.isCancel(err)) {
alert(loc.wallets.import_error);
}
}
};
const showActionSheet = async () => {
const isClipboardEmpty = (await Clipboard.getString()).replace(' ', '').length === 0;
let copyFromClipboardIndex;
if (Platform.OS === 'ios') {
const options = [loc._.cancel, 'Take Photo', loc.wallets.list_long_choose];
if (!isClipboardEmpty) {
options.push(loc.wallets.list_long_clipboard);
copyFromClipboardIndex = options.length - 1;
}
options.push(loc.wallets.import_file);
const impoortFileButtonIndex = options.length - 1;
ActionSheet.showActionSheetWithOptions({ options, cancelButtonIndex: 0 }, buttonIndex => {
if (buttonIndex === 1) {
takePhoto();
} else if (buttonIndex === 2) {
choosePhoto();
} else if (buttonIndex === copyFromClipboardIndex) {
copyFromClipbard();
} else if (impoortFileButtonIndex) {
handleImportFileButtonPressed();
}
});
}
};
return (
@ -162,7 +267,7 @@ const WalletsImport = () => {
);
};
WalletsImport.navigationOptions = ({ navigation, route }) => ({
WalletsImport.navigationOptions = () => ({
...BlueNavigationStyle(),
title: loc.wallets.import_title,
});