mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-26 08:55:56 +01:00
Merge pull request #5997 from BlueWallet/filecopy
FIX: Unable to import files in Android 13+
This commit is contained in:
commit
d88cc931b6
6 changed files with 41 additions and 23 deletions
|
@ -322,7 +322,11 @@ const AztecoRedeemRoot = () => {
|
|||
|
||||
const ScanQRCodeStack = createNativeStackNavigator();
|
||||
const ScanQRCodeRoot = () => (
|
||||
<ScanQRCodeStack.Navigator initialRouteName='ScanQRCode' name="ScanQRCodeRoot" screenOptions={{ headerShown: false, presentation: 'fullScreenModal' }}>
|
||||
<ScanQRCodeStack.Navigator
|
||||
initialRouteName="ScanQRCode"
|
||||
name="ScanQRCodeRoot"
|
||||
screenOptions={{ headerShown: false, presentation: 'fullScreenModal' }}
|
||||
>
|
||||
<ScanQRCodeStack.Screen name="ScanQRCode" component={ScanQRCode} initialParams={ScanQRCode.initialParams} />
|
||||
</ScanQRCodeStack.Navigator>
|
||||
);
|
||||
|
|
|
@ -10,11 +10,15 @@
|
|||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
||||
<uses-permission android:name="android.permission.CAMERA"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
|
||||
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
|
||||
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<uses-permission android:name="android.permission.ACTION_OPEN_DOCUMENT" />
|
||||
<uses-permission android:name="android.permission.ACTION_GET_CONTENT" />
|
||||
<uses-permission android:name="android.permission.ACTION_CREATE_DOCUMENT" />
|
||||
|
||||
<application
|
||||
android:name=".MainApplication"
|
||||
|
@ -24,7 +28,6 @@
|
|||
android:allowBackup="false"
|
||||
android:largeHeap="true"
|
||||
android:extractNativeLibs="true"
|
||||
android:requestLegacyExternalStorage="true"
|
||||
android:usesCleartextTraffic="true"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
|
|
|
@ -161,6 +161,7 @@ const takePhotoWithImagePickerAndReadPhoto = () => {
|
|||
const showFilePickerAndReadFile = async function () {
|
||||
try {
|
||||
const res = await DocumentPicker.pickSingle({
|
||||
copyTo: 'cachesDirectory',
|
||||
type:
|
||||
Platform.OS === 'ios'
|
||||
? [
|
||||
|
@ -174,22 +175,21 @@ const showFilePickerAndReadFile = async function () {
|
|||
: [DocumentPicker.types.allFiles],
|
||||
});
|
||||
|
||||
const uri = Platform.OS === 'ios' ? decodeURI(res.uri) : res.uri;
|
||||
// ^^ some weird difference on how spaces in filenames are treated on ios and android
|
||||
const fileCopyUri = decodeURI(res.fileCopyUri);
|
||||
|
||||
let file = false;
|
||||
if (res.uri.toLowerCase().endsWith('.psbt')) {
|
||||
if (res.fileCopyUri.toLowerCase().endsWith('.psbt')) {
|
||||
// this is either binary file from ElectrumDesktop OR string file with base64 string in there
|
||||
file = await _readPsbtFileIntoBase64(uri);
|
||||
return { data: file, uri: decodeURI(res.uri) };
|
||||
file = await _readPsbtFileIntoBase64(fileCopyUri);
|
||||
return { data: file, uri: decodeURI(res.fileCopyUri) };
|
||||
}
|
||||
|
||||
if (res?.type === DocumentPicker.types.images || res?.type?.startsWith('image/')) {
|
||||
return new Promise(resolve => {
|
||||
const uri2 = res.uri.toString().replace('file://', '');
|
||||
const uri2 = res.fileCopyUri.toString().replace('file://', '');
|
||||
LocalQRCode.decode(decodeURI(uri2), (error, result) => {
|
||||
if (!error) {
|
||||
resolve({ data: result, uri: decodeURI(res.uri) });
|
||||
resolve({ data: result, fileCopyUri });
|
||||
} else {
|
||||
resolve({ data: false, uri: false });
|
||||
}
|
||||
|
@ -197,8 +197,8 @@ const showFilePickerAndReadFile = async function () {
|
|||
});
|
||||
}
|
||||
|
||||
file = await RNFS.readFile(uri);
|
||||
return { data: file, uri: decodeURI(res.uri) };
|
||||
file = await RNFS.readFile(fileCopyUri);
|
||||
return { data: file, fileCopyUri };
|
||||
} catch (err) {
|
||||
if (!DocumentPicker.isCancel(err)) {
|
||||
alert(err.message);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { ScrollView, View, StyleSheet, Linking, Platform } from 'react-native';
|
||||
import { ScrollView, View, StyleSheet, Linking } from 'react-native';
|
||||
import wif from 'wif';
|
||||
import bip38 from 'bip38';
|
||||
import BIP32Factory from 'bip32';
|
||||
|
@ -19,6 +19,7 @@ import {
|
|||
import ecc from '../blue_modules/noble_ecc';
|
||||
import Button from '../components/Button';
|
||||
import SafeArea from '../components/SafeArea';
|
||||
import alert from '../components/Alert';
|
||||
const bitcoin = require('bitcoinjs-lib');
|
||||
const BlueCrypto = require('react-native-blue-crypto');
|
||||
const encryption = require('../blue_modules/encryption');
|
||||
|
@ -44,6 +45,20 @@ export default class Selftest extends Component {
|
|||
fs.writeFileAndExport('bluewallet-storagesave-test.txt', 'Success');
|
||||
};
|
||||
|
||||
onPressImportDocument = async () => {
|
||||
try {
|
||||
fs.showFilePickerAndReadFile().then(file => {
|
||||
if (file && file.data && file.data.length > 0) {
|
||||
alert(file.data);
|
||||
} else {
|
||||
alert('Error reading file');
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
};
|
||||
|
||||
async componentDidMount() {
|
||||
let errorMessage = '';
|
||||
let isOk = true;
|
||||
|
@ -300,12 +315,10 @@ export default class Selftest extends Component {
|
|||
);
|
||||
}
|
||||
})()}
|
||||
{Platform.OS === 'android' && (
|
||||
<>
|
||||
<BlueSpacing20 />
|
||||
<Button title="Test Save to Storage" onPress={this.onPressSaveToStorage} />
|
||||
</>
|
||||
)}
|
||||
<BlueSpacing20 />
|
||||
<Button title="Test Save to Storage" onPress={this.onPressSaveToStorage} />
|
||||
<BlueSpacing20 />
|
||||
<Button title="Test Save to File Import" onPress={this.onPressImportDocument} />
|
||||
</ScrollView>
|
||||
</BlueCard>
|
||||
</SafeArea>
|
||||
|
|
|
@ -461,9 +461,7 @@ const WalletsAddMultisigStep2 = () => {
|
|||
fs.showActionSheet({ anchor: findNodeHandle(openScannerButton.current) }).then(onBarScanned);
|
||||
} else {
|
||||
setIsProvideMnemonicsModalVisible(false);
|
||||
InteractionManager.runAfterInteractions(() =>
|
||||
scanQrHelper(navigation.navigate, onBarScanned)
|
||||
);
|
||||
InteractionManager.runAfterInteractions(() => scanQrHelper(navigation.navigate, onBarScanned));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -284,7 +284,7 @@ const WalletsList = () => {
|
|||
};
|
||||
|
||||
const onScanButtonPressed = () => {
|
||||
scanQrHelper(navigate, routeName, false).then(onBarScanned);
|
||||
scanQrHelper(navigate, routeName).then(onBarScanned);
|
||||
};
|
||||
|
||||
const onBarScanned = value => {
|
||||
|
|
Loading…
Add table
Reference in a new issue