mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-15 11:59:21 +01:00
ADD: Allow image for importing wallet
This commit is contained in:
parent
2fe564b82f
commit
f8668f4045
1 changed files with 25 additions and 4 deletions
|
@ -5,6 +5,7 @@ import Share from 'react-native-share';
|
||||||
import loc from '../loc';
|
import loc from '../loc';
|
||||||
import { getSystemName } from 'react-native-device-info';
|
import { getSystemName } from 'react-native-device-info';
|
||||||
import DocumentPicker from 'react-native-document-picker';
|
import DocumentPicker from 'react-native-document-picker';
|
||||||
|
const LocalQRCode = require('@remobile/react-native-qrcode-local-image');
|
||||||
|
|
||||||
const isDesktop = getSystemName() === 'Mac OS X';
|
const isDesktop = getSystemName() === 'Mac OS X';
|
||||||
|
|
||||||
|
@ -83,7 +84,14 @@ const showFilePickerAndReadFile = async function () {
|
||||||
const res = await DocumentPicker.pick({
|
const res = await DocumentPicker.pick({
|
||||||
type:
|
type:
|
||||||
Platform.OS === 'ios'
|
Platform.OS === 'ios'
|
||||||
? ['io.bluewallet.psbt', 'io.bluewallet.psbt.txn', 'io.bluewallet.backup', DocumentPicker.types.plainText, 'public.json']
|
? [
|
||||||
|
'io.bluewallet.psbt',
|
||||||
|
'io.bluewallet.psbt.txn',
|
||||||
|
'io.bluewallet.backup',
|
||||||
|
DocumentPicker.types.plainText,
|
||||||
|
'public.json',
|
||||||
|
DocumentPicker.types.images,
|
||||||
|
]
|
||||||
: [DocumentPicker.types.allFiles],
|
: [DocumentPicker.types.allFiles],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -94,11 +102,24 @@ const showFilePickerAndReadFile = async function () {
|
||||||
if (res.uri.toLowerCase().endsWith('.psbt')) {
|
if (res.uri.toLowerCase().endsWith('.psbt')) {
|
||||||
// this is either binary file from ElectrumDesktop OR string file with base64 string in there
|
// this is either binary file from ElectrumDesktop OR string file with base64 string in there
|
||||||
file = await _readPsbtFileIntoBase64(uri);
|
file = await _readPsbtFileIntoBase64(uri);
|
||||||
|
return { data: file, uri: decodeURI(res.uri) };
|
||||||
} else {
|
} else {
|
||||||
file = await RNFS.readFile(uri);
|
if (res.type === DocumentPicker.types.images || res.type.startsWith('image/')) {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
const uri = Platform.OS === 'ios' ? res.uri.toString().replace('file://', '') : res.path.toString();
|
||||||
|
LocalQRCode.decode(decodeURI(uri), (error, result) => {
|
||||||
|
if (!error) {
|
||||||
|
resolve({ data: result, uri: decodeURI(res.uri) });
|
||||||
|
} else {
|
||||||
|
resolve({ data: false, uri: false });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
file = await RNFS.readFile(uri);
|
||||||
|
return { data: file, uri: decodeURI(res.uri) };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { data: file, uri: decodeURI(res.uri) };
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return { data: false, uri: false };
|
return { data: false, uri: false };
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue