2021-02-15 11:08:05 +05:00
|
|
|
import React, {Component, createRef} from 'react';
|
|
|
|
|
import {InteractionManager, TouchableOpacity, View} from 'react-native';
|
2020-03-02 13:52:09 +05:00
|
|
|
import Share from 'react-native-share';
|
2020-11-17 20:17:50 +05:00
|
|
|
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
|
2021-02-15 11:08:05 +05:00
|
|
|
import {notesnook} from '../../../e2e/test.ids';
|
2021-02-16 13:23:43 +05:00
|
|
|
import BiometricService from '../../services/BiometricService';
|
2021-02-15 11:08:05 +05:00
|
|
|
import {DDS} from '../../services/DeviceDetection';
|
2020-03-10 23:19:16 +05:00
|
|
|
import {
|
2020-11-02 20:45:56 +05:00
|
|
|
eSendEvent,
|
|
|
|
|
eSubscribeEvent,
|
|
|
|
|
eUnSubscribeEvent,
|
2020-12-31 21:11:32 +05:00
|
|
|
sendNoteEditedEvent,
|
2021-02-15 11:08:05 +05:00
|
|
|
ToastEvent,
|
2020-10-13 17:02:14 +05:00
|
|
|
} from '../../services/EventManager';
|
2021-02-15 11:08:05 +05:00
|
|
|
import Navigation from '../../services/Navigation';
|
|
|
|
|
import {getElevation, toTXT} from '../../utils';
|
|
|
|
|
import {db} from '../../utils/DB';
|
2020-03-10 23:19:16 +05:00
|
|
|
import {
|
2020-03-21 10:03:11 +05:00
|
|
|
eCloseVaultDialog,
|
2020-03-10 23:19:16 +05:00
|
|
|
eOnLoadNote,
|
|
|
|
|
eOpenVaultDialog,
|
2020-10-13 17:02:14 +05:00
|
|
|
} from '../../utils/Events';
|
2021-02-16 16:11:10 +05:00
|
|
|
import {deleteItems} from '../../utils/functions';
|
2021-02-15 11:08:05 +05:00
|
|
|
import {tabBarRef} from '../../utils/Refs';
|
|
|
|
|
import {ph, SIZE} from '../../utils/SizeUtils';
|
|
|
|
|
import {Button} from '../Button';
|
2020-09-27 13:05:26 +05:00
|
|
|
import BaseDialog from '../Dialog/base-dialog';
|
|
|
|
|
import DialogButtons from '../Dialog/dialog-buttons';
|
|
|
|
|
import DialogHeader from '../Dialog/dialog-header';
|
2020-12-20 13:04:05 +05:00
|
|
|
import Input from '../Input';
|
2021-02-15 11:08:05 +05:00
|
|
|
import {Toast} from '../Toast';
|
2020-11-17 20:17:50 +05:00
|
|
|
import Paragraph from '../Typography/Paragraph';
|
|
|
|
|
|
2021-02-11 01:36:12 +05:00
|
|
|
let Keychain;
|
2020-03-03 15:37:48 +05:00
|
|
|
const passInputRef = createRef();
|
2020-03-10 23:19:16 +05:00
|
|
|
const confirmPassRef = createRef();
|
2020-11-25 11:46:44 +05:00
|
|
|
const changePassInputRef = createRef();
|
2020-01-17 21:05:38 +05:00
|
|
|
export class VaultDialog extends Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
|
|
|
|
visible: false,
|
2020-03-10 23:19:16 +05:00
|
|
|
wrongPassword: false,
|
2020-11-25 11:46:44 +05:00
|
|
|
loading: false,
|
2020-03-10 23:19:16 +05:00
|
|
|
note: {},
|
|
|
|
|
vault: false,
|
|
|
|
|
locked: true,
|
|
|
|
|
permanant: false,
|
|
|
|
|
goToEditor: false,
|
|
|
|
|
share: false,
|
|
|
|
|
passwordsDontMatch: false,
|
2020-03-14 12:13:00 +05:00
|
|
|
deleteNote: false,
|
2020-11-02 20:45:56 +05:00
|
|
|
focusIndex: null,
|
2020-11-17 20:17:50 +05:00
|
|
|
biometricUnlock: false,
|
2020-12-22 00:24:08 +05:00
|
|
|
isBiometryEnrolled: false,
|
2020-11-17 20:17:50 +05:00
|
|
|
isBiometryAvailable: false,
|
|
|
|
|
fingerprintAccess: false,
|
2020-11-25 11:46:44 +05:00
|
|
|
changePassword: false,
|
2020-12-20 13:04:05 +05:00
|
|
|
copyNote: false,
|
2020-12-22 00:24:08 +05:00
|
|
|
revokeFingerprintAccess: false,
|
2021-02-16 16:11:10 +05:00
|
|
|
title: 'Unlock Note',
|
|
|
|
|
description: null,
|
2020-01-17 21:05:38 +05:00
|
|
|
};
|
|
|
|
|
this.password = null;
|
2020-03-17 15:09:15 +05:00
|
|
|
this.confirmPassword = null;
|
2020-11-25 11:46:44 +05:00
|
|
|
this.newPassword = null;
|
2021-02-16 16:11:10 +05:00
|
|
|
(this.title = !this.state.novault
|
|
|
|
|
? 'Create Vault'
|
|
|
|
|
: this.state.fingerprintAccess
|
|
|
|
|
? 'Vault Fingerprint Unlock'
|
|
|
|
|
: this.state.revokeFingerprintAccess
|
|
|
|
|
? 'Revoke Vault Fingerprint Unlock'
|
|
|
|
|
: this.state.changePassword
|
|
|
|
|
? 'Change Vault Password'
|
|
|
|
|
: this.state.note.locked
|
|
|
|
|
? this.state.deleteNote
|
|
|
|
|
? 'Delete note'
|
|
|
|
|
: this.state.share
|
|
|
|
|
? 'Share note'
|
|
|
|
|
: this.state.copyNote
|
|
|
|
|
? 'Copy note'
|
|
|
|
|
: this.state.goToEditor
|
|
|
|
|
? 'Unlock note'
|
|
|
|
|
: 'Unlock note'
|
|
|
|
|
: 'Lock note'),
|
|
|
|
|
(this.description = !this.state.novault
|
|
|
|
|
? 'Set a password to create vault'
|
|
|
|
|
: this.state.fingerprintAccess
|
|
|
|
|
? 'Enter vault password to enable fingerprint unlocking'
|
|
|
|
|
: this.state.revokeFingerprintAccess
|
|
|
|
|
? 'Disable vault fingerprint unlock '
|
|
|
|
|
: this.state.changePassword
|
|
|
|
|
? 'Setup a new password for the vault.'
|
|
|
|
|
: this.state.permanant
|
|
|
|
|
? 'Enter password to remove note from vault.'
|
|
|
|
|
: this.state.note.locked
|
|
|
|
|
? this.state.deleteNote
|
|
|
|
|
? 'Unlock note to delete it.'
|
|
|
|
|
: this.state.share
|
|
|
|
|
? 'Unlock note to share it.'
|
|
|
|
|
: this.state.copyNote
|
|
|
|
|
? 'Unlock note to copy it.'
|
|
|
|
|
: this.state.goToEditor
|
|
|
|
|
? 'Unlock note to open it in editor'
|
|
|
|
|
: 'Enter vault password to unlock note.'
|
|
|
|
|
: 'Enter vault password to lock note.');
|
2020-01-17 21:05:38 +05:00
|
|
|
}
|
2020-01-17 00:23:16 +05:00
|
|
|
|
2020-03-10 23:19:16 +05:00
|
|
|
componentDidMount() {
|
|
|
|
|
eSubscribeEvent(eOpenVaultDialog, this.open);
|
|
|
|
|
eSubscribeEvent(eCloseVaultDialog, this.close);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
|
eUnSubscribeEvent(eOpenVaultDialog, this.open);
|
|
|
|
|
eUnSubscribeEvent(eCloseVaultDialog, this.close);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-17 20:17:50 +05:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {import('../../services/EventManager').vaultType} data
|
|
|
|
|
*/
|
|
|
|
|
open = async (data) => {
|
2021-02-15 11:08:05 +05:00
|
|
|
if (!Keychain) {
|
|
|
|
|
Keychain = require('react-native-keychain');
|
|
|
|
|
}
|
2021-02-16 13:23:43 +05:00
|
|
|
let biometry = await BiometricService.isBiometryAvailable();
|
2020-11-17 20:17:50 +05:00
|
|
|
let available = false;
|
2021-02-16 13:23:43 +05:00
|
|
|
let fingerprint = await BiometricService.hasInternetCredentials('nn_vault');
|
2020-12-22 00:24:08 +05:00
|
|
|
|
2021-02-16 13:23:43 +05:00
|
|
|
if (biometry) {
|
2020-11-17 20:17:50 +05:00
|
|
|
available = true;
|
|
|
|
|
}
|
2020-01-17 21:05:38 +05:00
|
|
|
this.setState({
|
2020-11-17 20:17:50 +05:00
|
|
|
note: data.item,
|
|
|
|
|
novault: data.novault,
|
|
|
|
|
locked: data.locked,
|
|
|
|
|
permanant: data.permanant,
|
|
|
|
|
goToEditor: data.goToEditor,
|
|
|
|
|
share: data.share,
|
|
|
|
|
deleteNote: data.deleteNote,
|
|
|
|
|
copyNote: data.copyNote,
|
|
|
|
|
isBiometryAvailable: available,
|
|
|
|
|
biometricUnlock: fingerprint,
|
2020-12-22 00:24:08 +05:00
|
|
|
isBiometryEnrolled: fingerprint,
|
2020-11-17 20:17:50 +05:00
|
|
|
fingerprintAccess: data.fingerprintAccess,
|
2020-11-25 11:46:44 +05:00
|
|
|
changePassword: data.changePassword,
|
2020-12-22 00:24:08 +05:00
|
|
|
revokeFingerprintAccess: data.revokeFingerprintAccess,
|
2021-02-16 16:11:10 +05:00
|
|
|
title: data.title,
|
|
|
|
|
description: data.description,
|
2020-01-17 21:05:38 +05:00
|
|
|
});
|
2020-12-22 00:24:08 +05:00
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
fingerprint &&
|
|
|
|
|
data.novault &&
|
|
|
|
|
!data.fingerprintAccess &&
|
|
|
|
|
!data.revokeFingerprintAccess
|
|
|
|
|
) {
|
2021-02-16 16:11:10 +05:00
|
|
|
await this._onPressFingerprintAuth(data.title, data.description);
|
2020-12-22 00:24:08 +05:00
|
|
|
} else {
|
|
|
|
|
this.setState({
|
|
|
|
|
visible: true,
|
|
|
|
|
});
|
2020-11-17 20:17:50 +05:00
|
|
|
}
|
2020-01-17 21:05:38 +05:00
|
|
|
};
|
2020-03-03 15:33:33 +05:00
|
|
|
|
2020-03-10 23:19:16 +05:00
|
|
|
close = () => {
|
2020-11-25 11:46:44 +05:00
|
|
|
if (this.state.loading) {
|
2020-11-25 12:09:07 +05:00
|
|
|
ToastEvent.show(
|
|
|
|
|
'Please wait and do not close the app.',
|
|
|
|
|
'success',
|
|
|
|
|
'local',
|
|
|
|
|
);
|
2020-11-25 11:46:44 +05:00
|
|
|
return;
|
|
|
|
|
}
|
2021-02-16 13:23:43 +05:00
|
|
|
Navigation.setRoutesToUpdate([
|
|
|
|
|
Navigation.routeNames.Notes,
|
|
|
|
|
Navigation.routeNames.Favorites,
|
|
|
|
|
Navigation.routeNames.NotesPage,
|
|
|
|
|
Navigation.routeNames.Notebook,
|
|
|
|
|
]);
|
2020-03-03 15:33:33 +05:00
|
|
|
|
2020-03-19 11:05:52 +05:00
|
|
|
this.password = null;
|
|
|
|
|
this.confirmPassword = null;
|
2020-03-02 13:52:09 +05:00
|
|
|
this.setState({
|
|
|
|
|
visible: false,
|
2020-03-10 23:19:16 +05:00
|
|
|
note: {},
|
|
|
|
|
locked: false,
|
|
|
|
|
permanant: false,
|
|
|
|
|
goToEditor: false,
|
|
|
|
|
share: false,
|
|
|
|
|
novault: false,
|
2020-03-14 12:13:00 +05:00
|
|
|
deleteNote: false,
|
2020-03-19 11:05:52 +05:00
|
|
|
passwordsDontMatch: false,
|
2020-03-02 13:52:09 +05:00
|
|
|
});
|
2020-01-17 21:05:38 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onPress = async () => {
|
2020-12-22 00:24:08 +05:00
|
|
|
if (this.state.revokeFingerprintAccess) {
|
|
|
|
|
await this._revokeFingerprintAccess();
|
2020-12-31 21:40:19 +05:00
|
|
|
this.close();
|
2020-12-22 00:24:08 +05:00
|
|
|
return;
|
|
|
|
|
}
|
2020-11-25 11:46:44 +05:00
|
|
|
if (this.state.loading) return;
|
2020-12-20 13:04:05 +05:00
|
|
|
|
2020-11-25 12:09:07 +05:00
|
|
|
if (!this.password) {
|
|
|
|
|
ToastEvent.show('You must fill all the fields.', 'error', 'local');
|
2020-12-20 13:04:05 +05:00
|
|
|
return;
|
2020-11-25 12:09:07 +05:00
|
|
|
}
|
2020-12-20 13:04:05 +05:00
|
|
|
if (this.password && this.password.length < 3) {
|
|
|
|
|
ToastEvent.show('Password too short', 'error', 'local');
|
2020-03-14 12:59:52 +05:00
|
|
|
|
2020-12-20 13:04:05 +05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!this.state.novault) {
|
2020-03-17 15:09:15 +05:00
|
|
|
if (this.password !== this.confirmPassword) {
|
2020-03-14 12:59:52 +05:00
|
|
|
ToastEvent.show('Passwords do not match', 'error', 'local');
|
2020-03-17 15:09:15 +05:00
|
|
|
this.setState({
|
|
|
|
|
passwordsDontMatch: true,
|
|
|
|
|
});
|
2020-03-10 23:19:16 +05:00
|
|
|
return;
|
|
|
|
|
}
|
2020-03-17 15:09:15 +05:00
|
|
|
|
|
|
|
|
this._createVault();
|
2020-11-25 11:46:44 +05:00
|
|
|
} else if (this.state.changePassword) {
|
|
|
|
|
this.setState({
|
|
|
|
|
loading: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
db.vault
|
|
|
|
|
.changePassword(this.password, this.newPassword)
|
|
|
|
|
.then((result) => {
|
|
|
|
|
this.setState({
|
|
|
|
|
loading: false,
|
|
|
|
|
});
|
|
|
|
|
if (this.state.biometricUnlock) {
|
|
|
|
|
this._enrollFingerprint(this.newPassword);
|
|
|
|
|
}
|
|
|
|
|
ToastEvent.show('Vault password changed', 'success');
|
|
|
|
|
this.close();
|
|
|
|
|
})
|
|
|
|
|
.catch((e) => {
|
|
|
|
|
this.setState({
|
|
|
|
|
loading: false,
|
|
|
|
|
});
|
2020-11-25 12:10:25 +05:00
|
|
|
if (e.message === db.vault.ERRORS.wrongPassword) {
|
2020-11-25 11:46:44 +05:00
|
|
|
ToastEvent.show('Current password incorrect.', 'error', 'local');
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-03-10 23:19:16 +05:00
|
|
|
} else if (this.state.locked) {
|
|
|
|
|
if (!this.password || this.password.trim() === 0) {
|
2020-03-14 12:59:52 +05:00
|
|
|
ToastEvent.show('Password is invalid', 'error', 'local');
|
2020-03-14 12:13:00 +05:00
|
|
|
this.setState({
|
|
|
|
|
wrongPassword: true,
|
|
|
|
|
});
|
2020-03-03 15:44:31 +05:00
|
|
|
return;
|
2020-01-17 21:05:38 +05:00
|
|
|
}
|
2020-12-20 13:04:05 +05:00
|
|
|
db.vault
|
|
|
|
|
.unlock(this.password)
|
|
|
|
|
.then(async () => {
|
|
|
|
|
this.setState({
|
|
|
|
|
wrongPassword: false,
|
|
|
|
|
});
|
|
|
|
|
if (this.state.note.locked) {
|
|
|
|
|
await this._unlockNote();
|
|
|
|
|
} else {
|
|
|
|
|
await this._lockNote();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((e) => {
|
|
|
|
|
this._takeErrorAction(e);
|
|
|
|
|
});
|
2020-12-31 21:40:19 +05:00
|
|
|
} else if (this.state.fingerprintAccess) {
|
2020-11-25 11:46:44 +05:00
|
|
|
this._enrollFingerprint(this.password);
|
2020-03-10 23:19:16 +05:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
async _lockNote() {
|
|
|
|
|
if (!this.password || this.password.trim() === 0) {
|
2020-03-14 12:59:52 +05:00
|
|
|
ToastEvent.show('Password is invalid', 'error', 'local');
|
2020-03-10 23:19:16 +05:00
|
|
|
return;
|
|
|
|
|
} else {
|
2020-09-09 11:10:35 +05:00
|
|
|
db.vault.add(this.state.note.id).then((e) => {
|
2020-03-10 23:19:16 +05:00
|
|
|
this.close();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-03 15:33:33 +05:00
|
|
|
|
2020-03-10 23:19:16 +05:00
|
|
|
async _unlockNote() {
|
|
|
|
|
if (!this.password || this.password.trim() === 0) {
|
2020-03-14 12:59:52 +05:00
|
|
|
ToastEvent.show('Password is invalid', 'error', 'local');
|
2020-03-10 23:19:16 +05:00
|
|
|
return;
|
2020-12-22 00:24:08 +05:00
|
|
|
}
|
|
|
|
|
if (this.state.permanant) {
|
|
|
|
|
this._permanantUnlock();
|
2020-03-10 23:19:16 +05:00
|
|
|
} else {
|
2020-12-22 00:24:08 +05:00
|
|
|
await this._openNote();
|
2020-03-10 23:19:16 +05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-31 21:29:30 +05:00
|
|
|
_openNote = async () => {
|
|
|
|
|
try {
|
|
|
|
|
let note = await db.vault.open(this.state.note.id, this.password);
|
|
|
|
|
if (this.state.biometricUnlock && !this.state.isBiometryEnrolled) {
|
|
|
|
|
await this._enrollFingerprint(this.password);
|
|
|
|
|
}
|
|
|
|
|
if (this.state.goToEditor) {
|
|
|
|
|
this._openInEditor(note);
|
|
|
|
|
} else if (this.state.share) {
|
2020-12-31 21:33:14 +05:00
|
|
|
await this._shareNote(note);
|
2020-12-31 21:29:30 +05:00
|
|
|
} else if (this.state.deleteNote) {
|
|
|
|
|
await this._deleteNote();
|
|
|
|
|
} else if (this.state.copyNote) {
|
|
|
|
|
this._copyNote(note);
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
this._takeErrorAction(e);
|
|
|
|
|
}
|
|
|
|
|
};
|
2020-03-14 12:13:00 +05:00
|
|
|
async _deleteNote() {
|
2021-02-16 16:11:10 +05:00
|
|
|
try {
|
|
|
|
|
await db.vault.remove(this.state.note.id, this.password);
|
|
|
|
|
await deleteItems(this.state.note);
|
|
|
|
|
this.close();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
this._takeErrorAction(e);
|
|
|
|
|
}
|
2020-03-10 23:19:16 +05:00
|
|
|
}
|
|
|
|
|
|
2020-11-25 11:46:44 +05:00
|
|
|
async _enrollFingerprint(password) {
|
2020-11-17 20:17:50 +05:00
|
|
|
try {
|
2021-01-01 15:37:47 +05:00
|
|
|
this.setState(
|
|
|
|
|
{
|
|
|
|
|
loading: true,
|
|
|
|
|
},
|
|
|
|
|
async () => {
|
2021-02-16 13:23:43 +05:00
|
|
|
await BiometricService.storeCredentials(password);
|
2021-01-01 15:37:47 +05:00
|
|
|
this.setState({
|
|
|
|
|
loading: false,
|
|
|
|
|
});
|
|
|
|
|
eSendEvent('vaultUpdated');
|
2021-02-16 13:23:43 +05:00
|
|
|
ToastEvent.show('Biometric unlocking enabled!', 'success');
|
2021-01-01 15:37:47 +05:00
|
|
|
this.close();
|
|
|
|
|
},
|
|
|
|
|
);
|
2020-11-17 20:17:50 +05:00
|
|
|
} catch (e) {
|
|
|
|
|
this._takeErrorAction(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-10 23:19:16 +05:00
|
|
|
async _createVault() {
|
|
|
|
|
await db.vault.create(this.password);
|
2021-02-16 13:23:43 +05:00
|
|
|
|
2020-11-17 20:17:50 +05:00
|
|
|
if (this.state.biometricUnlock) {
|
2021-02-16 13:23:43 +05:00
|
|
|
await this._enrollFingerprint(this.password);
|
2020-11-17 20:17:50 +05:00
|
|
|
}
|
2020-03-10 23:19:16 +05:00
|
|
|
if (this.state.note && this.state.note.id && !this.state.note.locked) {
|
|
|
|
|
await db.vault.add(this.state.note.id);
|
2021-02-16 13:23:43 +05:00
|
|
|
this.setState({
|
|
|
|
|
loading: false,
|
|
|
|
|
});
|
2020-03-14 12:59:52 +05:00
|
|
|
ToastEvent.show('Note added to vault', 'success', 'local');
|
2021-02-16 13:23:43 +05:00
|
|
|
this.close();
|
2020-11-17 20:17:50 +05:00
|
|
|
} else {
|
|
|
|
|
eSendEvent('vaultUpdated');
|
|
|
|
|
this.close();
|
2020-03-10 23:19:16 +05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_permanantUnlock() {
|
|
|
|
|
db.vault
|
|
|
|
|
.remove(this.state.note.id, this.password)
|
2020-11-17 20:17:50 +05:00
|
|
|
.then((r) => {
|
2021-01-01 18:55:26 +05:00
|
|
|
sendNoteEditedEvent({
|
2021-02-15 11:08:05 +05:00
|
|
|
id: this.state.note.id,
|
2021-01-01 18:55:26 +05:00
|
|
|
forced: true,
|
|
|
|
|
});
|
2021-02-16 13:23:43 +05:00
|
|
|
Navigation.setRoutesToUpdate([
|
|
|
|
|
Navigation.routeNames.Notes,
|
|
|
|
|
Navigation.routeNames.Favorites,
|
|
|
|
|
Navigation.routeNames.NotesPage,
|
|
|
|
|
]);
|
2020-03-10 23:19:16 +05:00
|
|
|
this.close();
|
|
|
|
|
})
|
2020-09-09 11:10:35 +05:00
|
|
|
.catch((e) => {
|
2020-03-10 23:19:16 +05:00
|
|
|
this._takeErrorAction(e);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_openInEditor(note) {
|
|
|
|
|
this.close();
|
2020-12-31 21:33:14 +05:00
|
|
|
InteractionManager.runAfterInteractions(() => {
|
|
|
|
|
eSendEvent(eOnLoadNote, note);
|
|
|
|
|
if (!DDS.isTab) {
|
|
|
|
|
tabBarRef.current?.goToPage(1);
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-03-10 23:19:16 +05:00
|
|
|
}
|
|
|
|
|
|
2020-12-07 11:26:30 +05:00
|
|
|
_copyNote(note) {
|
|
|
|
|
let text = toTXT(note.content.data);
|
2021-02-16 16:11:10 +05:00
|
|
|
text = `${note.title}\n \n ${text}`;
|
2020-12-07 11:26:30 +05:00
|
|
|
Clipboard.setString(text);
|
|
|
|
|
ToastEvent.show('Note copied to clipboard', 'success', 'local');
|
|
|
|
|
this.close();
|
2020-12-01 16:36:19 +05:00
|
|
|
}
|
|
|
|
|
|
2020-12-31 21:33:14 +05:00
|
|
|
async _shareNote(note) {
|
|
|
|
|
this.close();
|
2020-12-07 11:26:30 +05:00
|
|
|
let text = toTXT(note.content.data);
|
2021-02-16 16:11:10 +05:00
|
|
|
text = `${note.title}\n \n ${text}`;
|
2020-12-31 21:33:14 +05:00
|
|
|
try {
|
|
|
|
|
await Share.open({
|
|
|
|
|
title: 'Share note to',
|
|
|
|
|
failOnCancel: false,
|
2021-02-16 16:11:10 +05:00
|
|
|
message: text,
|
2020-12-31 21:33:14 +05:00
|
|
|
});
|
2021-02-15 11:08:05 +05:00
|
|
|
} catch (e) {}
|
2020-03-10 23:19:16 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_takeErrorAction(e) {
|
|
|
|
|
if (e.message === db.vault.ERRORS.wrongPassword) {
|
2020-03-14 12:59:52 +05:00
|
|
|
ToastEvent.show('Password is incorrect', 'error', 'local');
|
2020-03-10 23:19:16 +05:00
|
|
|
this.setState({
|
|
|
|
|
wrongPassword: true,
|
|
|
|
|
});
|
|
|
|
|
return;
|
2020-01-17 21:05:38 +05:00
|
|
|
} else {
|
|
|
|
|
}
|
2020-03-10 23:19:16 +05:00
|
|
|
}
|
2020-01-17 21:05:38 +05:00
|
|
|
|
2020-12-22 00:24:08 +05:00
|
|
|
_revokeFingerprintAccess = async () => {
|
|
|
|
|
try {
|
2021-02-16 13:23:43 +05:00
|
|
|
await BiometricService.resetCredentials();
|
2020-12-22 00:24:08 +05:00
|
|
|
eSendEvent('vaultUpdated');
|
2021-02-16 13:23:43 +05:00
|
|
|
ToastEvent.show('Biometrics access revoked!', 'success');
|
2020-12-22 00:24:08 +05:00
|
|
|
} catch (e) {
|
|
|
|
|
ToastEvent.show(e.message, 'error', 'local');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-02-16 16:11:10 +05:00
|
|
|
_onPressFingerprintAuth = async (title, description) => {
|
2020-11-17 20:17:50 +05:00
|
|
|
try {
|
2021-02-16 16:11:10 +05:00
|
|
|
let credentials = await BiometricService.getCredentials(
|
|
|
|
|
title || this.state.title,
|
|
|
|
|
description || this.state.description,
|
|
|
|
|
);
|
2021-02-16 13:23:43 +05:00
|
|
|
|
2020-11-17 20:17:50 +05:00
|
|
|
if (credentials?.password) {
|
|
|
|
|
this.password = credentials.password;
|
|
|
|
|
this.onPress();
|
2021-02-16 13:23:43 +05:00
|
|
|
} else {
|
|
|
|
|
this.setState({
|
|
|
|
|
visible: true,
|
|
|
|
|
});
|
|
|
|
|
ToastEvent.show('Biometrics Authentication Failed', 'error', 'local');
|
2020-11-17 20:17:50 +05:00
|
|
|
}
|
2021-02-16 13:23:43 +05:00
|
|
|
} catch (e) {}
|
2020-11-17 20:17:50 +05:00
|
|
|
};
|
|
|
|
|
|
2020-01-17 21:05:38 +05:00
|
|
|
render() {
|
2020-09-09 11:10:35 +05:00
|
|
|
const {colors} = this.props;
|
2020-03-10 23:19:16 +05:00
|
|
|
const {
|
|
|
|
|
note,
|
|
|
|
|
visible,
|
|
|
|
|
wrongPassword,
|
|
|
|
|
passwordsDontMatch,
|
|
|
|
|
novault,
|
|
|
|
|
locked,
|
|
|
|
|
permanant,
|
2020-11-17 20:17:50 +05:00
|
|
|
biometricUnlock,
|
2020-11-25 11:46:44 +05:00
|
|
|
deleteNote,
|
|
|
|
|
share,
|
|
|
|
|
goToEditor,
|
|
|
|
|
fingerprintAccess,
|
|
|
|
|
changePassword,
|
|
|
|
|
copyNote,
|
|
|
|
|
loading,
|
2020-03-10 23:19:16 +05:00
|
|
|
} = this.state;
|
2020-01-17 21:05:38 +05:00
|
|
|
|
2020-11-23 12:32:33 +05:00
|
|
|
if (!visible) return null;
|
2020-01-17 21:05:38 +05:00
|
|
|
return (
|
2020-09-27 13:05:26 +05:00
|
|
|
<BaseDialog
|
2020-03-03 15:37:48 +05:00
|
|
|
onShow={() => {
|
|
|
|
|
passInputRef.current?.focus();
|
|
|
|
|
}}
|
2020-11-25 11:46:44 +05:00
|
|
|
statusBarTranslucent={false}
|
2020-09-27 13:05:26 +05:00
|
|
|
onRequestClose={this.close}
|
2020-11-23 12:32:33 +05:00
|
|
|
visible={true}>
|
2019-12-07 08:41:48 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
2020-09-27 13:05:26 +05:00
|
|
|
...getElevation(5),
|
2020-12-22 10:27:51 +05:00
|
|
|
width: DDS.isTab ? 350 : '85%',
|
2020-09-27 13:05:26 +05:00
|
|
|
borderRadius: 5,
|
|
|
|
|
backgroundColor: colors.bg,
|
|
|
|
|
paddingHorizontal: ph,
|
2020-12-22 00:24:08 +05:00
|
|
|
paddingVertical: 15,
|
2019-12-07 08:41:48 +05:00
|
|
|
}}>
|
2020-09-27 13:05:26 +05:00
|
|
|
<DialogHeader
|
2021-02-16 16:11:10 +05:00
|
|
|
title={this.state.title}
|
|
|
|
|
paragraph={this.state.description}
|
2020-09-27 13:05:26 +05:00
|
|
|
icon="shield"
|
|
|
|
|
/>
|
|
|
|
|
|
2020-12-22 00:24:08 +05:00
|
|
|
{(novault || changePassword) &&
|
|
|
|
|
!this.state.revokeFingerprintAccess ? (
|
2020-11-17 20:17:50 +05:00
|
|
|
<>
|
2020-12-20 13:04:05 +05:00
|
|
|
<Input
|
|
|
|
|
fwdRef={passInputRef}
|
2020-11-25 11:46:44 +05:00
|
|
|
editable={!loading}
|
|
|
|
|
autoCapitalize="none"
|
2020-12-01 22:52:01 +05:00
|
|
|
testID={notesnook.ids.dialogs.vault.pwd}
|
2020-11-17 20:17:50 +05:00
|
|
|
onChangeText={(value) => {
|
|
|
|
|
this.password = value;
|
|
|
|
|
}}
|
2020-12-22 10:27:51 +05:00
|
|
|
marginBottom={
|
|
|
|
|
!this.state.biometricUnlock ||
|
|
|
|
|
!this.state.isBiometryEnrolled ||
|
|
|
|
|
!novault ||
|
|
|
|
|
changePassword
|
|
|
|
|
? 0
|
|
|
|
|
: 10
|
|
|
|
|
}
|
2020-11-17 20:17:50 +05:00
|
|
|
secureTextEntry
|
2021-02-16 16:11:10 +05:00
|
|
|
placeholder={changePassword ? 'Current password' : 'Password'}
|
2020-11-17 20:17:50 +05:00
|
|
|
/>
|
2020-11-25 11:46:44 +05:00
|
|
|
|
|
|
|
|
{!this.state.biometricUnlock ||
|
2020-12-22 00:24:08 +05:00
|
|
|
!this.state.isBiometryEnrolled ||
|
2020-11-25 11:46:44 +05:00
|
|
|
!novault ||
|
|
|
|
|
changePassword ? null : (
|
2020-11-17 20:17:50 +05:00
|
|
|
<Button
|
|
|
|
|
onPress={this._onPressFingerprintAuth}
|
|
|
|
|
width="100%"
|
2021-02-16 16:11:10 +05:00
|
|
|
title={'Biometric unlock'}
|
2020-11-17 20:17:50 +05:00
|
|
|
type="shade"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
2020-09-27 13:05:26 +05:00
|
|
|
) : null}
|
2020-01-05 18:03:40 +05:00
|
|
|
|
2020-11-25 11:46:44 +05:00
|
|
|
{changePassword ? (
|
|
|
|
|
<>
|
2020-12-20 13:04:05 +05:00
|
|
|
<Input
|
2020-11-25 11:46:44 +05:00
|
|
|
ref={changePassInputRef}
|
|
|
|
|
editable={!loading}
|
2020-12-01 22:52:01 +05:00
|
|
|
testID={notesnook.ids.dialogs.vault.changePwd}
|
2020-11-25 11:46:44 +05:00
|
|
|
autoCapitalize="none"
|
|
|
|
|
onChangeText={(value) => {
|
|
|
|
|
this.newPassword = value;
|
|
|
|
|
}}
|
|
|
|
|
secureTextEntry
|
2021-02-16 16:11:10 +05:00
|
|
|
placeholder={'New password'}
|
2020-11-25 11:46:44 +05:00
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
) : null}
|
|
|
|
|
|
2020-09-27 13:05:26 +05:00
|
|
|
{!novault ? (
|
|
|
|
|
<View>
|
2020-12-20 13:04:05 +05:00
|
|
|
<Input
|
|
|
|
|
fwdRef={passInputRef}
|
2020-11-25 11:46:44 +05:00
|
|
|
autoCapitalize="none"
|
2020-12-01 22:52:01 +05:00
|
|
|
testID={notesnook.ids.dialogs.vault.pwd}
|
2020-09-09 11:10:35 +05:00
|
|
|
onChangeText={(value) => {
|
2020-03-03 15:33:33 +05:00
|
|
|
this.password = value;
|
2020-01-17 21:05:38 +05:00
|
|
|
}}
|
|
|
|
|
secureTextEntry
|
2019-12-07 08:41:48 +05:00
|
|
|
placeholder="Password"
|
|
|
|
|
/>
|
2020-09-09 11:10:35 +05:00
|
|
|
|
2020-12-20 13:04:05 +05:00
|
|
|
<Input
|
|
|
|
|
fwdRef={confirmPassRef}
|
2020-11-25 11:46:44 +05:00
|
|
|
autoCapitalize="none"
|
2020-12-01 22:52:01 +05:00
|
|
|
testID={notesnook.ids.dialogs.vault.pwdAlt}
|
2020-09-27 13:05:26 +05:00
|
|
|
secureTextEntry
|
2020-12-21 23:35:33 +05:00
|
|
|
validationType="confirmPassword"
|
|
|
|
|
customValidator={() => this.password}
|
|
|
|
|
errorMessage="Passwords do not match."
|
|
|
|
|
onErrorCheck={(e) => null}
|
|
|
|
|
marginBottom={0}
|
2020-09-27 13:05:26 +05:00
|
|
|
onChangeText={(value) => {
|
|
|
|
|
this.confirmPassword = value;
|
|
|
|
|
if (value !== this.password) {
|
|
|
|
|
this.setState({
|
|
|
|
|
passwordsDontMatch: true,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
this.setState({
|
|
|
|
|
passwordsDontMatch: false,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
placeholder="Confirm password"
|
2020-09-09 11:10:35 +05:00
|
|
|
/>
|
2020-01-17 21:05:38 +05:00
|
|
|
</View>
|
2020-09-27 13:05:26 +05:00
|
|
|
) : null}
|
|
|
|
|
|
2021-02-16 13:23:43 +05:00
|
|
|
{this.state.biometricUnlock &&
|
|
|
|
|
!this.state.isBiometryEnrolled &&
|
|
|
|
|
novault && (
|
|
|
|
|
<Paragraph>
|
|
|
|
|
Unlock with password once to enable fingerprint access.
|
|
|
|
|
</Paragraph>
|
|
|
|
|
)}
|
2020-12-22 00:24:08 +05:00
|
|
|
|
2020-11-23 12:32:33 +05:00
|
|
|
{this.state.isBiometryAvailable &&
|
|
|
|
|
!this.state.fingerprintAccess &&
|
2020-11-25 11:46:44 +05:00
|
|
|
((!this.state.biometricUnlock && !changePassword) || !novault) ? (
|
2020-11-17 20:17:50 +05:00
|
|
|
<TouchableOpacity
|
|
|
|
|
onPress={() => {
|
|
|
|
|
this.setState({
|
|
|
|
|
biometricUnlock: !biometricUnlock,
|
|
|
|
|
});
|
|
|
|
|
}}
|
2020-12-01 22:52:01 +05:00
|
|
|
testID={notesnook.ids.dialogs.vault.fingerprint}
|
2020-11-17 20:17:50 +05:00
|
|
|
activeOpacity={0.7}
|
|
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
width: '100%',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
height: 40,
|
|
|
|
|
}}>
|
|
|
|
|
<Icon
|
|
|
|
|
size={SIZE.lg}
|
|
|
|
|
color={biometricUnlock ? colors.accent : colors.icon}
|
|
|
|
|
name={
|
|
|
|
|
biometricUnlock
|
|
|
|
|
? 'check-circle-outline'
|
|
|
|
|
: 'checkbox-blank-circle-outline'
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<Paragraph
|
|
|
|
|
style={{
|
|
|
|
|
fontSize: SIZE.sm,
|
2021-01-03 10:38:07 +05:00
|
|
|
//fontFamily: "sans-serif",
|
2020-11-17 20:17:50 +05:00
|
|
|
color: colors.pri,
|
|
|
|
|
maxWidth: '90%',
|
|
|
|
|
marginLeft: 10,
|
|
|
|
|
}}>
|
2020-12-01 22:52:01 +05:00
|
|
|
Fingerprint Unlock
|
2020-11-17 20:17:50 +05:00
|
|
|
</Paragraph>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
) : null}
|
|
|
|
|
|
2020-09-27 13:05:26 +05:00
|
|
|
<DialogButtons
|
|
|
|
|
onPressNegative={this.close}
|
|
|
|
|
onPressPositive={this.onPress}
|
2020-11-25 11:46:44 +05:00
|
|
|
loading={loading}
|
2020-09-27 13:05:26 +05:00
|
|
|
positiveTitle={
|
2020-11-25 11:46:44 +05:00
|
|
|
fingerprintAccess
|
2020-11-17 20:17:50 +05:00
|
|
|
? 'Enable'
|
2020-12-22 00:24:08 +05:00
|
|
|
: this.state.revokeFingerprintAccess
|
|
|
|
|
? 'Revoke'
|
2020-11-25 11:46:44 +05:00
|
|
|
: changePassword
|
|
|
|
|
? 'Change'
|
2020-11-17 20:17:50 +05:00
|
|
|
: note.locked
|
2020-11-25 11:46:44 +05:00
|
|
|
? deleteNote
|
2020-09-27 13:05:26 +05:00
|
|
|
? 'Delete'
|
2020-11-25 11:46:44 +05:00
|
|
|
: share
|
2020-09-27 13:05:26 +05:00
|
|
|
? 'Share '
|
2020-11-25 11:46:44 +05:00
|
|
|
: goToEditor
|
2020-09-27 13:05:26 +05:00
|
|
|
? 'Open'
|
|
|
|
|
: 'Unlock'
|
2020-11-17 20:17:50 +05:00
|
|
|
: !note.id
|
|
|
|
|
? 'Create'
|
2020-09-27 13:05:26 +05:00
|
|
|
: 'Lock'
|
|
|
|
|
}
|
|
|
|
|
/>
|
2019-12-07 08:41:48 +05:00
|
|
|
</View>
|
2021-01-01 15:43:41 +05:00
|
|
|
<Toast context="local" />
|
2020-09-27 13:05:26 +05:00
|
|
|
</BaseDialog>
|
2020-01-17 21:05:38 +05:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|