2020-09-09 11:10:35 +05:00
|
|
|
import React, {Component, createRef} from 'react';
|
2020-11-17 20:17:50 +05:00
|
|
|
import {TouchableOpacity, View} from 'react-native';
|
2020-09-09 11:10:35 +05:00
|
|
|
import {TextInput} from 'react-native-gesture-handler';
|
2020-11-17 20:17:50 +05:00
|
|
|
import * as Keychain from 'react-native-keychain';
|
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';
|
2020-10-13 17:02:14 +05:00
|
|
|
import {Actions} from '../../provider/Actions';
|
2020-11-02 20:45:56 +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,
|
|
|
|
|
ToastEvent,
|
2020-10-13 17:02:14 +05:00
|
|
|
} from '../../services/EventManager';
|
2020-11-02 20:45:56 +05:00
|
|
|
import {getElevation} 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-03-14 12:13:00 +05:00
|
|
|
refreshNotesPage,
|
2020-10-13 17:02:14 +05:00
|
|
|
} from '../../utils/Events';
|
2020-11-17 20:17:50 +05:00
|
|
|
import {tabBarRef} from '../../utils/Refs';
|
2020-11-02 20:45:56 +05:00
|
|
|
import {ph, pv, SIZE, WEIGHT} from '../../utils/SizeUtils';
|
2020-11-17 20:17:50 +05:00
|
|
|
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-09-09 11:10:35 +05:00
|
|
|
import {updateEvent} from '../DialogManager/recievers';
|
2020-11-02 20:45:56 +05:00
|
|
|
import Seperator from '../Seperator';
|
2020-09-09 11:10:35 +05:00
|
|
|
import {Toast} from '../Toast';
|
2020-11-17 20:17:50 +05:00
|
|
|
import Paragraph from '../Typography/Paragraph';
|
|
|
|
|
|
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,
|
|
|
|
|
isBiometryAvailable: false,
|
|
|
|
|
fingerprintAccess: false,
|
2020-11-25 11:46:44 +05:00
|
|
|
changePassword: false,
|
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;
|
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) => {
|
|
|
|
|
let biometry = await Keychain.getSupportedBiometryType();
|
|
|
|
|
let available = false;
|
|
|
|
|
let fingerprint = await Keychain.hasInternetCredentials('nn_vault');
|
|
|
|
|
if (
|
|
|
|
|
biometry === Keychain.BIOMETRY_TYPE.FINGERPRINT ||
|
|
|
|
|
biometry === Keychain.BIOMETRY_TYPE.TOUCH_ID
|
|
|
|
|
) {
|
|
|
|
|
available = true;
|
|
|
|
|
}
|
2020-01-17 21:05:38 +05:00
|
|
|
this.setState({
|
|
|
|
|
visible: true,
|
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,
|
|
|
|
|
fingerprintAccess: data.fingerprintAccess,
|
2020-11-25 11:46:44 +05:00
|
|
|
changePassword: data.changePassword,
|
2020-01-17 21:05:38 +05:00
|
|
|
});
|
2020-11-17 20:17:50 +05:00
|
|
|
if (fingerprint && this.state.novault && !this.state.fingerprintAccess) {
|
|
|
|
|
await this._onPressFingerprintAuth();
|
|
|
|
|
}
|
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) {
|
|
|
|
|
ToastEvent.show('Please wait and do not close the app.', 'success');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-10-13 17:02:14 +05:00
|
|
|
updateEvent({type: Actions.NOTES});
|
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-11-25 11:46:44 +05:00
|
|
|
if (this.state.loading) return;
|
2020-03-10 23:19:16 +05:00
|
|
|
if (!this.state.novault) {
|
2020-11-25 11:46:44 +05:00
|
|
|
if (this.password && this.password.length < 3) {
|
2020-03-14 12:59:52 +05:00
|
|
|
ToastEvent.show('Password too short', 'error', 'local');
|
|
|
|
|
|
2020-03-10 23:19:16 +05:00
|
|
|
return;
|
|
|
|
|
}
|
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) {
|
|
|
|
|
if (this.newPassword && this.newPassword.length < 3) {
|
|
|
|
|
ToastEvent.show('New password too short', 'error', 'local');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
|
});
|
|
|
|
|
if (e === db.vault.ERRORS.wrongPassword) {
|
|
|
|
|
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-03-10 23:19:16 +05:00
|
|
|
} else {
|
|
|
|
|
db.vault
|
|
|
|
|
.unlock(this.password)
|
|
|
|
|
.then(async () => {
|
2020-03-14 12:13:00 +05:00
|
|
|
this.setState({
|
|
|
|
|
wrongPassword: false,
|
|
|
|
|
});
|
2020-03-10 23:19:16 +05:00
|
|
|
if (this.state.note.locked) {
|
|
|
|
|
await this._unlockNote();
|
|
|
|
|
} else {
|
|
|
|
|
await this._lockNote();
|
|
|
|
|
}
|
|
|
|
|
})
|
2020-09-09 11:10:35 +05:00
|
|
|
.catch((e) => {
|
2020-03-10 23:19:16 +05:00
|
|
|
this._takeErrorAction(e);
|
|
|
|
|
});
|
2020-01-17 21:05:38 +05:00
|
|
|
}
|
2020-11-17 20:17:50 +05:00
|
|
|
} else if (this.state.fingerprintEnroll) {
|
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;
|
|
|
|
|
} else {
|
|
|
|
|
if (this.state.permanant) {
|
|
|
|
|
this._permanantUnlock();
|
|
|
|
|
} else {
|
|
|
|
|
await this._openNote();
|
2020-01-17 21:05:38 +05:00
|
|
|
}
|
2020-03-10 23:19:16 +05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async _openNote() {
|
2020-03-14 12:13:00 +05:00
|
|
|
db.vault
|
|
|
|
|
.open(this.state.note.id, this.password)
|
2020-04-15 17:41:28 +05:00
|
|
|
.then(async (note) => {
|
2020-03-14 12:13:00 +05:00
|
|
|
if (this.state.goToEditor) {
|
2020-11-17 20:17:50 +05:00
|
|
|
console.log(note, 'NOTE');
|
2020-03-14 12:13:00 +05:00
|
|
|
this._openInEditor(note);
|
|
|
|
|
} else if (this.state.share) {
|
|
|
|
|
this._shareNote(note);
|
|
|
|
|
} else if (this.state.deleteNote) {
|
|
|
|
|
await this._deleteNote();
|
|
|
|
|
}
|
|
|
|
|
})
|
2020-09-09 11:10:35 +05:00
|
|
|
.catch((e) => {
|
2020-03-14 12:13:00 +05:00
|
|
|
this._takeErrorAction(e);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
async _deleteNote() {
|
|
|
|
|
await db.notes.delete(this.state.note.id);
|
2020-10-13 17:02:14 +05:00
|
|
|
updateEvent({type: Actions.NOTES});
|
|
|
|
|
updateEvent({type: Actions.FAVORITES});
|
2020-03-14 12:13:00 +05:00
|
|
|
eSendEvent(refreshNotesPage);
|
|
|
|
|
this.close();
|
2020-03-14 12:59:52 +05:00
|
|
|
ToastEvent.show('Note deleted', 'success', 'local');
|
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 {
|
2020-11-25 11:46:44 +05:00
|
|
|
await Keychain.setInternetCredentials('nn_vault', 'nn_vault', password, {
|
|
|
|
|
accessControl: Keychain.ACCESS_CONTROL.BIOMETRY_ANY_OR_DEVICE_PASSCODE,
|
|
|
|
|
authenticationPrompt: {cancel: null},
|
|
|
|
|
accessible: Keychain.AUTHENTICATION_TYPE.DEVICE_PASSCODE_OR_BIOMETRICS,
|
|
|
|
|
});
|
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);
|
2020-11-17 20:17:50 +05:00
|
|
|
if (this.state.biometricUnlock) {
|
|
|
|
|
await this._enrollFingerprint();
|
|
|
|
|
}
|
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);
|
|
|
|
|
this.close();
|
2020-03-14 12:59:52 +05:00
|
|
|
ToastEvent.show('Note added to vault', 'success', 'local');
|
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) => {
|
|
|
|
|
console.log(r, 'unocking result');
|
2020-03-10 23:19:16 +05:00
|
|
|
this.close();
|
|
|
|
|
})
|
2020-09-09 11:10:35 +05:00
|
|
|
.catch((e) => {
|
2020-11-17 20:17:50 +05:00
|
|
|
console.log(e, 'unlocking error');
|
2020-03-10 23:19:16 +05:00
|
|
|
this._takeErrorAction(e);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_openInEditor(note) {
|
|
|
|
|
eSendEvent(eOnLoadNote, note);
|
|
|
|
|
if (!DDS.isTab) {
|
2020-11-14 10:07:23 +05:00
|
|
|
tabBarRef.current?.goToPage(1);
|
2020-03-10 23:19:16 +05:00
|
|
|
}
|
|
|
|
|
this.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_shareNote(note) {
|
|
|
|
|
let m = `${note.title}\n \n ${note.content.text}`;
|
|
|
|
|
Share.open({
|
|
|
|
|
title: 'Share note to',
|
|
|
|
|
failOnCancel: false,
|
|
|
|
|
message: m,
|
|
|
|
|
});
|
|
|
|
|
this.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_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-11-17 20:17:50 +05:00
|
|
|
_onPressFingerprintAuth = async () => {
|
|
|
|
|
try {
|
|
|
|
|
let credentials = await Keychain.getInternetCredentials('nn_vault', {
|
|
|
|
|
accessControl: Keychain.ACCESS_CONTROL.BIOMETRY_ANY_OR_DEVICE_PASSCODE,
|
|
|
|
|
authenticationType:
|
|
|
|
|
Keychain.AUTHENTICATION_TYPE.DEVICE_PASSCODE_OR_BIOMETRICS,
|
|
|
|
|
authenticationPrompt: {
|
|
|
|
|
cancel: null,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
if (credentials?.password) {
|
|
|
|
|
this.password = credentials.password;
|
|
|
|
|
this.onPress();
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
ToastEvent.show('Fingerprint Authentication Canceled', 'error', 'local');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
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-10-04 09:46:50 +05:00
|
|
|
width: DDS.isTab ? 350 : '80%',
|
2020-09-27 13:05:26 +05:00
|
|
|
borderRadius: 5,
|
|
|
|
|
backgroundColor: colors.bg,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
paddingVertical: pv,
|
2019-12-07 08:41:48 +05:00
|
|
|
}}>
|
2020-09-27 13:05:26 +05:00
|
|
|
<DialogHeader
|
|
|
|
|
title={
|
|
|
|
|
!novault
|
2020-11-02 20:45:56 +05:00
|
|
|
? 'Create Vault'
|
2020-11-25 11:46:44 +05:00
|
|
|
: fingerprintAccess
|
2020-11-17 20:17:50 +05:00
|
|
|
? 'Fingerprint Access'
|
2020-11-25 11:46:44 +05:00
|
|
|
: changePassword
|
|
|
|
|
? 'Change Vault Password'
|
2020-09-27 13:05:26 +05:00
|
|
|
: note.locked
|
2020-11-25 11:46:44 +05:00
|
|
|
? deleteNote
|
2020-09-27 13:05:26 +05:00
|
|
|
? 'Delete note'
|
2020-11-25 11:46:44 +05:00
|
|
|
: share
|
2020-09-27 13:05:26 +05:00
|
|
|
? 'Share note'
|
2020-11-25 11:46:44 +05:00
|
|
|
: goToEditor
|
2020-09-27 13:05:26 +05:00
|
|
|
? 'Unlock note'
|
|
|
|
|
: 'Unlock note'
|
|
|
|
|
: 'Lock note'
|
|
|
|
|
}
|
2020-09-27 13:14:24 +05:00
|
|
|
paragraph={
|
|
|
|
|
!novault
|
|
|
|
|
? 'Set a password to create vault'
|
2020-11-25 11:46:44 +05:00
|
|
|
: fingerprintAccess
|
2020-11-17 20:17:50 +05:00
|
|
|
? 'Enter vault password to enable access to the vault with fingerprint'
|
2020-11-25 11:46:44 +05:00
|
|
|
: changePassword
|
|
|
|
|
? 'Setup a new password for the vault.'
|
2020-09-27 13:14:24 +05:00
|
|
|
: permanant
|
|
|
|
|
? 'Enter password to remove note from vault.'
|
|
|
|
|
: note.locked
|
2020-11-25 11:46:44 +05:00
|
|
|
? deleteNote
|
2020-09-27 13:14:24 +05:00
|
|
|
? 'Unlock note to delete it.'
|
2020-11-25 11:46:44 +05:00
|
|
|
: share
|
2020-09-27 13:14:24 +05:00
|
|
|
? 'Unlock note to share it.'
|
2020-11-25 11:46:44 +05:00
|
|
|
: goToEditor
|
2020-09-27 13:14:24 +05:00
|
|
|
? 'Unlock note to open it in editor'
|
|
|
|
|
: 'Enter vault password to unlock note.'
|
|
|
|
|
: 'Enter vault password to lock note.'
|
|
|
|
|
}
|
2020-09-27 13:05:26 +05:00
|
|
|
icon="shield"
|
|
|
|
|
/>
|
|
|
|
|
|
2020-11-02 20:45:56 +05:00
|
|
|
<Seperator />
|
|
|
|
|
|
2020-11-17 20:17:50 +05:00
|
|
|
{note.locked ||
|
|
|
|
|
locked ||
|
|
|
|
|
permanant ||
|
2020-11-25 11:46:44 +05:00
|
|
|
fingerprintAccess ||
|
|
|
|
|
changePassword ? (
|
2020-11-17 20:17:50 +05:00
|
|
|
<>
|
|
|
|
|
<TextInput
|
|
|
|
|
ref={passInputRef}
|
2020-11-25 11:46:44 +05:00
|
|
|
editable={!loading}
|
|
|
|
|
autoCapitalize="none"
|
2020-11-17 20:17:50 +05:00
|
|
|
style={{
|
|
|
|
|
padding: pv - 5,
|
|
|
|
|
borderBottomWidth: 1.5,
|
|
|
|
|
borderColor: wrongPassword
|
|
|
|
|
? colors.errorText
|
|
|
|
|
: this.state.focusIndex === 0
|
|
|
|
|
? colors.accent
|
|
|
|
|
: colors.nav,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
marginTop: 10,
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
}}
|
|
|
|
|
onChangeText={(value) => {
|
|
|
|
|
this.password = value;
|
|
|
|
|
}}
|
|
|
|
|
onFocus={() => {
|
|
|
|
|
this.setState({
|
|
|
|
|
focusIndex: 0,
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
secureTextEntry
|
2020-11-25 11:46:44 +05:00
|
|
|
placeholder={changePassword ? 'Current Password' : 'Password'}
|
2020-11-17 20:17:50 +05:00
|
|
|
placeholderTextColor={colors.icon}
|
|
|
|
|
/>
|
2020-11-25 11:46:44 +05:00
|
|
|
|
2020-11-17 20:17:50 +05:00
|
|
|
<Seperator />
|
2020-11-25 11:46:44 +05:00
|
|
|
{!this.state.biometricUnlock ||
|
|
|
|
|
!novault ||
|
|
|
|
|
changePassword ? null : (
|
2020-11-17 20:17:50 +05:00
|
|
|
<Button
|
|
|
|
|
onPress={this._onPressFingerprintAuth}
|
|
|
|
|
width="100%"
|
|
|
|
|
title={
|
|
|
|
|
!note.locked
|
|
|
|
|
? 'Lock with Fingerprint'
|
|
|
|
|
: 'Unlock with Fingerprint'
|
|
|
|
|
}
|
|
|
|
|
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 ? (
|
|
|
|
|
<>
|
|
|
|
|
<TextInput
|
|
|
|
|
ref={changePassInputRef}
|
|
|
|
|
editable={!loading}
|
|
|
|
|
autoCapitalize="none"
|
|
|
|
|
style={{
|
|
|
|
|
padding: pv - 5,
|
|
|
|
|
borderBottomWidth: 1.5,
|
|
|
|
|
borderColor: wrongPassword
|
|
|
|
|
? colors.errorText
|
|
|
|
|
: this.state.focusIndex === 0
|
|
|
|
|
? colors.accent
|
|
|
|
|
: colors.nav,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
marginTop: 10,
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
}}
|
|
|
|
|
onChangeText={(value) => {
|
|
|
|
|
this.newPassword = value;
|
|
|
|
|
}}
|
|
|
|
|
onFocus={() => {
|
|
|
|
|
this.setState({
|
|
|
|
|
focusIndex: 0,
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
secureTextEntry
|
|
|
|
|
placeholder={'New Password'}
|
|
|
|
|
placeholderTextColor={colors.icon}
|
|
|
|
|
/>
|
|
|
|
|
<Seperator />
|
|
|
|
|
</>
|
|
|
|
|
) : null}
|
|
|
|
|
|
2020-09-27 13:05:26 +05:00
|
|
|
{!novault ? (
|
|
|
|
|
<View>
|
2019-12-07 08:41:48 +05:00
|
|
|
<TextInput
|
2020-03-03 15:37:48 +05:00
|
|
|
ref={passInputRef}
|
2020-11-25 11:46:44 +05:00
|
|
|
autoCapitalize="none"
|
2019-12-07 08:41:48 +05:00
|
|
|
style={{
|
|
|
|
|
padding: pv - 5,
|
2020-11-02 20:45:56 +05:00
|
|
|
borderBottomWidth: 1.5,
|
2020-09-27 13:05:26 +05:00
|
|
|
borderColor: passwordsDontMatch
|
|
|
|
|
? colors.errorText
|
2020-11-02 20:45:56 +05:00
|
|
|
: this.state.focusIndex === 1
|
|
|
|
|
? colors.accent
|
2020-09-27 13:05:26 +05:00
|
|
|
: colors.nav,
|
2019-12-07 08:41:48 +05:00
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
}}
|
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
|
|
|
}}
|
2020-11-02 20:45:56 +05:00
|
|
|
onFocus={() => {
|
|
|
|
|
this.setState({
|
|
|
|
|
focusIndex: 1,
|
|
|
|
|
});
|
|
|
|
|
}}
|
2020-01-17 21:05:38 +05:00
|
|
|
secureTextEntry
|
2019-12-07 08:41:48 +05:00
|
|
|
placeholder="Password"
|
|
|
|
|
placeholderTextColor={colors.icon}
|
|
|
|
|
/>
|
2020-09-09 11:10:35 +05:00
|
|
|
|
2020-09-27 13:05:26 +05:00
|
|
|
<TextInput
|
|
|
|
|
ref={confirmPassRef}
|
2020-11-25 11:46:44 +05:00
|
|
|
autoCapitalize="none"
|
2020-09-27 13:05:26 +05:00
|
|
|
style={{
|
|
|
|
|
padding: pv - 5,
|
2020-11-02 20:45:56 +05:00
|
|
|
borderBottomWidth: 1.5,
|
2020-09-27 13:05:26 +05:00
|
|
|
borderColor: passwordsDontMatch
|
|
|
|
|
? colors.errorText
|
2020-11-02 20:45:56 +05:00
|
|
|
: this.state.focusIndex === 2
|
|
|
|
|
? colors.accent
|
2020-09-27 13:05:26 +05:00
|
|
|
: colors.nav,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
marginTop: 10,
|
|
|
|
|
}}
|
|
|
|
|
secureTextEntry
|
2020-11-02 20:45:56 +05:00
|
|
|
onFocus={() => {
|
|
|
|
|
this.setState({
|
|
|
|
|
focusIndex: 2,
|
|
|
|
|
});
|
|
|
|
|
}}
|
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"
|
|
|
|
|
placeholderTextColor={colors.icon}
|
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}
|
|
|
|
|
|
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,
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
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,
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
color: colors.pri,
|
|
|
|
|
maxWidth: '90%',
|
|
|
|
|
marginLeft: 10,
|
|
|
|
|
}}>
|
|
|
|
|
{!biometricUnlock
|
|
|
|
|
? 'Fingerprint Unlock Disabled'
|
|
|
|
|
: 'Fingerprint Unlock Enabled'}
|
|
|
|
|
</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-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>
|
2020-03-14 12:59:52 +05:00
|
|
|
<Toast context="local" />
|
2020-09-27 13:05:26 +05:00
|
|
|
</BaseDialog>
|
2020-01-17 21:05:38 +05:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|