From 5c06fa2dd819675eb8417c3b8294c46e73c1a7ab Mon Sep 17 00:00:00 2001 From: jessop Date: Tue, 27 Aug 2019 22:35:07 -0400 Subject: [PATCH] password saving --- src/platforms/electron/index.js | 25 ++++++++++ src/ui/component/app/view.jsx | 6 --- .../component/walletSecurityAndSync/index.js | 4 -- .../component/walletSecurityAndSync/view.jsx | 18 +++---- src/ui/constants/keychain.js | 3 -- src/ui/modal/modalPasswordUnsave/index.js | 3 +- src/ui/modal/modalPasswordUnsave/view.jsx | 13 ++--- src/ui/modal/modalWalletDecrypt/index.js | 5 +- src/ui/modal/modalWalletDecrypt/view.jsx | 7 +-- src/ui/modal/modalWalletEncrypt/index.js | 3 +- src/ui/modal/modalWalletEncrypt/view.jsx | 5 +- src/ui/modal/modalWalletUnlock/index.js | 3 +- src/ui/modal/modalWalletUnlock/view.jsx | 15 ++++-- src/ui/page/settings/index.js | 1 - src/ui/page/settings/view.jsx | 21 +++----- src/ui/page/show/index.js | 6 --- src/ui/redux/actions/app.js | 15 ------ src/ui/util/saved-passwords.js | 50 +++++++++++++++---- static/app-strings.json | 1 - 19 files changed, 103 insertions(+), 101 deletions(-) delete mode 100644 src/ui/constants/keychain.js diff --git a/src/platforms/electron/index.js b/src/platforms/electron/index.js index 01cbe43f6..5eff94534 100644 --- a/src/platforms/electron/index.js +++ b/src/platforms/electron/index.js @@ -1,3 +1,5 @@ +/* eslint no-console:0 */ +/* eslint space-before-function-paren:0 */ // Module imports import '@babel/polyfill'; import keytar from 'keytar'; @@ -29,6 +31,7 @@ let showingAutoUpdateCloseAlert = false; // object is garbage collected. let rendererWindow; +// eslint-disable-next-line no-unused-vars let tray; let daemon; @@ -44,6 +47,7 @@ if (isDev) { process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = true; } +// eslint-disable-next-line space-before-function-paren const startDaemon = async () => { let isDaemonRunning = false; @@ -110,6 +114,7 @@ if (!gotSingleInstanceLock) { } }); + // eslint-disable-next-line space-before-function-paren app.on('ready', async () => { await startDaemon(); startSandbox(); @@ -312,6 +317,26 @@ ipcMain.on('set-auth-token', (event, token) => { keytar.setPassword('LBRY', 'auth_token', token ? token.toString().trim() : null); }); +ipcMain.on('get-password', event => { + keytar.getPassword('LBRY', 'wallet_password').then(password => { + event.sender.send('get-password-response', password ? password.toString() : null); + }); +}); + +ipcMain.on('set-password', (event, password) => { + if (password || password === '') { + keytar.setPassword('LBRY', 'wallet_password', password).then(res => { + event.sender.send('get-password-response', res); + }); + } +}); + +ipcMain.on('delete-password', (event, password) => { + keytar.deletePassword('LBRY', 'wallet_password', password).then(res => { + event.sender.send('get-password-response', res); + }); +}); + process.on('uncaughtException', error => { console.log(error); dialog.showErrorBox('Error Encountered', `Caught error: ${error}`); diff --git a/src/ui/component/app/view.jsx b/src/ui/component/app/view.jsx index ec69bf08c..df050ba9a 100644 --- a/src/ui/component/app/view.jsx +++ b/src/ui/component/app/view.jsx @@ -6,12 +6,6 @@ import { Lbry, buildURI, parseURI } from 'lbry-redux'; import Router from 'component/router/index'; import ModalRouter from 'modal/modalRouter'; import ReactModal from 'react-modal'; -<<<<<<< HEAD -import SideBar from 'component/sideBar'; -import Header from 'component/header'; -import Button from 'component/button'; -======= ->>>>>>> add createChannel to first run flow import { openContextMenu } from 'util/context-menu'; import useKonamiListener from 'util/enhanced-layout'; import Yrbl from 'component/yrbl'; diff --git a/src/ui/component/walletSecurityAndSync/index.js b/src/ui/component/walletSecurityAndSync/index.js index 1493fa5f3..2a0f7130d 100644 --- a/src/ui/component/walletSecurityAndSync/index.js +++ b/src/ui/component/walletSecurityAndSync/index.js @@ -10,7 +10,6 @@ import { selectWalletIsEncrypted, selectHasTransactions, } from 'lbry-redux'; -import { doPasswordSaved } from 'redux/actions/app'; import WalletSecurityAndSync from './view'; import { doCheckSync, @@ -27,7 +26,6 @@ import { selectHashChanged, selectUser, } from 'lbryinc'; -import { selectIsPasswordSaved } from 'redux/selectors/app'; import { doSetClientSetting } from 'redux/actions/settings'; import { makeSelectClientSetting } from 'redux/selectors/settings'; @@ -46,7 +44,6 @@ const select = state => ({ syncApplyErrorMessage: selectSyncApplyErrorMessage(state), syncData: selectSyncData(state), syncHash: selectSyncHash(state), - isPasswordSaved: selectIsPasswordSaved(state), hashChanged: selectHashChanged(state), }); @@ -54,7 +51,6 @@ const perform = dispatch => ({ encryptWallet: password => dispatch(doWalletEncrypt(password)), decryptWallet: () => dispatch(doWalletDecrypt()), updateWalletStatus: () => dispatch(doWalletStatus()), - setPasswordSaved: saved => dispatch(doPasswordSaved(saved)), syncApply: (hash, data, password) => dispatch(doSyncApply(hash, data, password)), getSync: password => dispatch(doGetSync(password)), checkSync: () => dispatch(doCheckSync()), diff --git a/src/ui/component/walletSecurityAndSync/view.jsx b/src/ui/component/walletSecurityAndSync/view.jsx index 3cd8c298f..4c3c5b3bc 100644 --- a/src/ui/component/walletSecurityAndSync/view.jsx +++ b/src/ui/component/walletSecurityAndSync/view.jsx @@ -6,7 +6,6 @@ import UserEmail from 'component/userEmail'; import * as ICONS from 'constants/icons'; import { getSavedPassword, setSavedPassword, deleteSavedPassword } from 'util/saved-passwords'; -import { KEY_WALLET_PASSWORD } from 'constants/keychain'; type Props = { // wallet statuses @@ -70,10 +69,7 @@ function WalletSecurityAndSync(props: Props) { walletEncrypted, encryptWallet, decryptWallet, - setPasswordSaved, syncEnabled, - setClientSetting, - isPasswordSaved, user, hasSyncedWallet, getSyncIsPending, @@ -84,7 +80,7 @@ function WalletSecurityAndSync(props: Props) { syncApply, checkSync, hasTransactions, - // setDefaultAccount, + setDefaultAccount, } = props; const defaultComponentState: State = { @@ -111,7 +107,7 @@ function WalletSecurityAndSync(props: Props) { // on mount useEffect(() => { checkSync(); - getSavedPassword(KEY_WALLET_PASSWORD).then(p => { + getSavedPassword().then(p => { if (p) { setComponentState({ ...componentState, @@ -140,7 +136,7 @@ function WalletSecurityAndSync(props: Props) { function onChangeRememberPassword(event: SyntheticInputEvent<>) { if (componentState.rememberPassword) { - deleteSavedPassword(KEY_WALLET_PASSWORD); + deleteSavedPassword(); } setComponentState({ ...componentState, rememberPassword: event.target.checked }); } @@ -204,7 +200,7 @@ function WalletSecurityAndSync(props: Props) { } if (componentState.rememberPassword && !componentState.failed) { - setSavedPassword(KEY_WALLET_PASSWORD, componentState.newPassword); + setSavedPassword(componentState.newPassword); } } @@ -374,13 +370,13 @@ function WalletSecurityAndSync(props: Props) { onClick={() => syncApply(syncHash, syncData, componentState.newPassword)} />{' '}