From 3e5194131ff0da4cbffde2a75fd42a12d66024cb Mon Sep 17 00:00:00 2001 From: Mo Bitar Date: Tue, 1 May 2018 11:40:19 -0500 Subject: [PATCH] Decrypted export option --- src/containers/account/OptionsSection.js | 29 ++++++++++++++++++++---- src/screens/Account.js | 23 +++++++++---------- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/containers/account/OptionsSection.js b/src/containers/account/OptionsSection.js index 83a62ebd..124fde38 100644 --- a/src/containers/account/OptionsSection.js +++ b/src/containers/account/OptionsSection.js @@ -1,12 +1,13 @@ import React, { Component } from 'react'; +import {Alert} from 'react-native'; import GlobalStyles from "../../Styles" import {TextInput, View} from 'react-native'; - import SectionHeader from "../../components/SectionHeader"; import ButtonCell from "../../components/ButtonCell"; import TableSection from "../../components/TableSection"; import SectionedTableCell from "../../components/SectionedTableCell"; import SectionedAccessoryTableCell from "../../components/SectionedAccessoryTableCell"; +import SectionedOptionsTableCell from "../../components/SectionedOptionsTableCell"; export default class OptionsSection extends Component { @@ -15,13 +16,25 @@ export default class OptionsSection extends Component { this.state = {loadingExport: false}; } - onExportPress = () => { + onExportPress = (option) => { + let encrypted = option.key == "encrypted"; + if(encrypted && !this.props.encryptionAvailable) { + Alert.alert('Not Available', "You must be signed in, or have a local passcode set, to generate an encrypted export file.", [{text: 'OK'}]) + return; + } this.setState({loadingExport: true}); - this.props.onExportPress(() => { + this.props.onExportPress(encrypted, () => { this.setState({loadingExport: false}); }) } + exportOptions = () => { + return [ + {title: "Encrypted", key: "encrypted", selected: this.props.encryptionAvailable}, + {title: "Decrypted", key: "decrypted", selected: true} + ]; + } + render() { return ( @@ -32,7 +45,15 @@ export default class OptionsSection extends Component { } - + ); diff --git a/src/screens/Account.js b/src/screens/Account.js index 324d6c24..8aefe0db 100644 --- a/src/screens/Account.js +++ b/src/screens/Account.js @@ -231,7 +231,7 @@ export default class Account extends Abstract { ) } - async onExportPress(callback) { + async onExportPress(encrypted, callback) { var version = Auth.getInstance().protocolVersion(); var keys = KeysManager.get().activeKeys(); @@ -257,8 +257,6 @@ export default class Account extends Abstract { data["auth_params"] = authParams; } - var encrypted = keys && keys !== null; - var jsonString = JSON.stringify(data, null, 2 /* pretty print */); var base64String = base64.encode(jsonString); var fileType = App.isAndroid ? ".json" : "json"; // Android creates a tmp file and expects dot with extension @@ -270,10 +268,10 @@ export default class Account extends Abstract { isHTML: true, attachment: { data: App.isIOS ? jsonString : base64String, type: fileType, name: encrypted ? "SN-Encrypted-Backup" : 'SN-Decrypted-Backup' } }, (error, event) => { - callback(); - if(error) { - Alert.alert('Error', 'Unable to send email.'); - } + callback(); + if(error) { + Alert.alert('Error', 'Unable to send email.'); + } }); } @@ -425,17 +423,18 @@ export default class Account extends Abstract { {this.state.confirmRegistration && }