Skip to content

Commit

Permalink
TST
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosrdz committed Jan 15, 2020
1 parent 335ad5f commit c2cea68
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 77 deletions.
1 change: 0 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:name=".MainApplication"
Expand Down
81 changes: 81 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 17 additions & 33 deletions screen/send/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
Text,
View,
Platform,
Alert,
PermissionsAndroid,
} from 'react-native';
import { BlueNavigationStyle, SafeBlueArea, BlueCard, BlueText } from '../../BlueComponents';
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -73,38 +73,22 @@ export default class SendCreate extends Component {
RNFS.unlink(filePath);
});
} else if (Platform.OS === 'android') {
Alert.alert(
'Export',
'Where would you like to export this transaction?',
[
{
text: 'External Storage',
onPress: async () => {
try {
await RNFS.writeFile('file://' + RNFS.ExternalStorageDirectoryPath + `/${fileName}`, this.state.tx, 'ascii');
alert('Successfully exported.');
} catch (e) {
console.log(e);
alert(e);
}
},
},
{
text: 'Documents Folder',
onPress: async () => {
try {
await RNFS.writeFile('file://' + RNFS.DocumentDirectoryPath + `/${fileName}`, this.state.tx, 'ascii');
alert('Successfully exported.');
} catch (e) {
console.log(e);
alert(e);
}
},
},
{ text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel' },
],
{ cancelable: true },
);
const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE, {
title: 'BlueWallet Storage Access Permission',
message: 'BlueWallet needs your permission to access your storage to save this transaction.',
buttonNeutral: 'Ask Me Later',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
});

if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log('Storage Permission: Granted');
const filePath = RNFS.ExternalCachesDirectoryPath + `/${this.fileName}`;
await RNFS.writeFile(filePath, this.state.tx);
alert(`This transaction has been saved in ${filePath}`);
} else {
console.log('Storage Permission: Denied');
}
}
};

Expand Down
62 changes: 19 additions & 43 deletions screen/send/psbtWithHardwareWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
View,
Dimensions,
Image,
Alert,
TextInput,
Clipboard,
Linking,
Platform,
PermissionsAndroid,
} from 'react-native';
import QRCode from 'react-native-qrcode-svg';
import { Icon, Text } from 'react-native-elements';
Expand Down Expand Up @@ -73,6 +73,7 @@ export default class PsbtWithHardwareWallet extends Component {
deepLinkPSBT: undefined,
txhex: props.navigation.getParam('txhex') || undefined,
};
this.fileName = `${Date.now()}.psbt`;
}

static getDerivedStateFromProps(nextProps, prevState) {
Expand Down Expand Up @@ -229,9 +230,8 @@ export default class PsbtWithHardwareWallet extends Component {
}

exportPSBT = async () => {
const fileName = `${Date.now()}.psbt`;
if (Platform.OS === 'ios') {
const filePath = RNFS.TemporaryDirectoryPath + `/${fileName}`;
const filePath = RNFS.TemporaryDirectoryPath + `/${this.fileName}`;
await RNFS.writeFile(filePath, this.state.isFirstPSBTAlreadyBase64 ? this.state.psbt : this.state.psbt.toBase64());
Share.open({
url: 'file://' + filePath,
Expand All @@ -241,46 +241,22 @@ export default class PsbtWithHardwareWallet extends Component {
RNFS.unlink(filePath);
});
} else if (Platform.OS === 'android') {
Alert.alert(
'Export',
'Where would you like to export this transaction?',
[
{
text: 'External Storage',
onPress: async () => {
try {
await RNFS.writeFile(
'file://' + RNFS.ExternalStorageDirectoryPath + `/${fileName}`,
this.state.isFirstPSBTAlreadyBase64 ? this.state.psbt : this.state.psbt.toBase64(),
'ascii',
);
alert('Successfully exported.');
} catch (e) {
console.log(e);
alert(e);
}
},
},
{
text: 'Documents Folder',
onPress: async () => {
try {
await RNFS.writeFile(
'file://' + RNFS.DocumentDirectoryPath + `/${fileName}`,
this.state.isFirstPSBTAlreadyBase64 ? this.state.psbt : this.state.psbt.toBase64(),
'ascii',
);
alert('Successfully exported.');
} catch (e) {
console.log(e);
alert(e);
}
},
},
{ text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel' },
],
{ cancelable: true },
);
const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE, {
title: 'BlueWallet Storage Access Permission',
message: 'BlueWallet needs your permission to access your storage to save this transaction.',
buttonNeutral: 'Ask Me Later',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
});

if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log('Storage Permission: Granted');
const filePath = RNFS.ExternalCachesDirectoryPath + `/${this.fileName}`;
await RNFS.writeFile(filePath, this.state.isFirstPSBTAlreadyBase64 ? this.state.psbt : this.state.psbt.toBase64());
alert(`This transaction has been saved in ${filePath}`);
} else {
console.log('Storage Permission: Denied');
}
}
};

Expand Down

0 comments on commit c2cea68

Please sign in to comment.