Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix locked note not opening if vault not created

ammarahm-ed23b6059de314
diff --git a/apps/mobile/src/components/VaultDialog/index.js b/apps/mobile/src/components/VaultDialog/index.js
index cb745b91d..c1246f64a 100644
--- a/apps/mobile/src/components/VaultDialog/index.js
+++ b/apps/mobile/src/components/VaultDialog/index.js
@@ -1,22 +1,18 @@
-import React, {Component, createRef} from 'react';
-import {Platform} from 'react-native';
-import {InteractionManager, TouchableOpacity, View} from 'react-native';
import Clipboard from '@react-native-clipboard/clipboard';
+import React, { Component, createRef } from 'react';
+import { InteractionManager, View } from 'react-native';
import Share from 'react-native-share';
-import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import {notesnook} from '../../../e2e/test.ids';
+import { notesnook } from '../../../e2e/test.ids';
import BiometricService from '../../services/BiometricService';
-import {DDS} from '../../services/DeviceDetection';
+import { DDS } from '../../services/DeviceDetection';
import {
eSendEvent,
eSubscribeEvent,
- eUnSubscribeEvent,
- sendNoteEditedEvent,
- ToastEvent
+ eUnSubscribeEvent, ToastEvent
} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
-import {getElevation, toTXT} from '../../utils';
-import {db} from '../../utils/database';
+import { getElevation, toTXT } from '../../utils';
+import { db } from '../../utils/database';
import {
eClearEditor,
eCloseActionSheet,
@@ -24,18 +20,17 @@ import {
eOnLoadNote,
eOpenVaultDialog
} from '../../utils/Events';
-import {deleteItems} from '../../utils/functions';
-import {tabBarRef} from '../../utils/Refs';
-import {ph, SIZE} from '../../utils/SizeUtils';
-import {sleep} from '../../utils/TimeUtils';
-import {getNote} from '../../views/Editor/Functions';
-import {Button} from '../Button';
+import { deleteItems } from '../../utils/functions';
+import { tabBarRef } from '../../utils/Refs';
+import { sleep } from '../../utils/TimeUtils';
+import { getNote } from '../../views/Editor/Functions';
+import { Button } from '../Button';
import BaseDialog from '../Dialog/base-dialog';
import DialogButtons from '../Dialog/dialog-buttons';
import DialogHeader from '../Dialog/dialog-header';
import Input from '../Input';
import Seperator from '../Seperator';
-import {Toast} from '../Toast';
+import { Toast } from '../Toast';
import Paragraph from '../Typography/Paragraph';
let Keychain;
@@ -306,21 +301,21 @@ export class VaultDialog extends Component {
});
return;
}
- db.vault
- .unlock(this.password)
- .then(async () => {
- this.setState({
- wrongPassword: false
- });
- if (this.state.note.locked) {
- await this._unlockNote();
- } else {
+ if (this.state.note.locked) {
+ await this._unlockNote();
+ } else {
+ db.vault
+ .unlock(this.password)
+ .then(async () => {
+ this.setState({
+ wrongPassword: false
+ });
await this._lockNote();
- }
- })
- .catch(e => {
- this._takeErrorAction(e);
- });
+ })
+ .catch(e => {
+ this._takeErrorAction(e);
+ });
+ }
} else if (this.state.fingerprintAccess) {
this._enrollFingerprint(this.password);
} else if (this.state.clearVault) {
@@ -438,9 +433,10 @@ export class VaultDialog extends Component {
} else if (this.state.deleteNote) {
await this._deleteNote();
} else if (this.state.copyNote) {
- this._copyNote(note);
+ await this._copyNote(note);
}
} catch (e) {
+ console.log(e);
this._takeErrorAction(e);
}
};
@@ -552,12 +548,9 @@ export class VaultDialog extends Component {
});
}
- _copyNote(note) {
- let text = toTXT(note.content.data);
- text = `${note.title}\n \n ${text}`;
- console.log(text, 'TEXT');
- Clipboard.setString(text);
- Toast.show({
+ async _copyNote(note) {
+ Clipboard.setString(await toTXT(note));
+ ToastEvent.show({
heading: 'Note copied',
type: 'success',
message: 'Note has been copied to clipboard!',
@@ -568,19 +561,20 @@ export class VaultDialog extends Component {
async _shareNote(note) {
this.close();
- let text = toTXT(note.content.data);
- text = `${note.title}\n \n ${text}`;
try {
await Share.open({
heading: 'Share note',
failOnCancel: false,
- message: text
+ message: await toTXT(note)
});
} catch (e) {}
}
_takeErrorAction(e) {
- if (e.message === db.vault.ERRORS.wrongPassword) {
+ if (
+ e.message === db.vault.ERRORS.wrongPassword ||
+ e.message === 'FAILURE'
+ ) {
this.setState({
wrongPassword: true,
visible: true