Merge pull request #5997 from BlueWallet/filecopy

FIX: Unable to import files in Android 13+
This commit is contained in:
GLaDOS 2024-01-11 11:08:46 +00:00 committed by GitHub
commit d88cc931b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 23 deletions

View file

@ -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>
);

View file

@ -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"

View file

@ -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);

View file

@ -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>

View file

@ -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));
}
};

View file

@ -284,7 +284,7 @@ const WalletsList = () => {
};
const onScanButtonPressed = () => {
scanQrHelper(navigate, routeName, false).then(onBarScanned);
scanQrHelper(navigate, routeName).then(onBarScanned);
};
const onBarScanned = value => {