Browse Source

add unified wallet password support

patch-4
Sander van Grieken 3 years ago
parent
commit
cd6d5e577b
  1. 15
      electrum/gui/qml/components/Wallets.qml
  2. 25
      electrum/gui/qml/qedaemon.py
  3. 7
      electrum/gui/qml/qewallet.py

15
electrum/gui/qml/components/Wallets.qml

@ -42,7 +42,7 @@ Pane {
function changePassword() {
// trigger dialog via wallet (auth then signal)
Daemon.currentWallet.start_change_password()
Daemon.start_change_password()
}
property QtObject menu: Menu {
@ -307,6 +307,19 @@ Pane {
Daemon.availableWallets.reload()
app.stack.pop()
}
function onRequestNewPassword() { // new unified password (all wallets)
var dialog = app.passwordDialog.createObject(app,
{
'confirmPassword': true,
'title': qsTr('Enter new password'),
'infotext': qsTr('If you forget your password, you\'ll need to\
restore from seed. Please make sure you have your seed stored safely')
} )
dialog.accepted.connect(function() {
Daemon.set_password(dialog.password)
})
dialog.open()
}
}
Connections {

25
electrum/gui/qml/qedaemon.py

@ -6,7 +6,7 @@ from PyQt5.QtCore import Qt, QAbstractListModel, QModelIndex
from electrum.util import register_callback, get_new_wallet_name, WalletFileException
from electrum.logging import get_logger
from electrum.wallet import Wallet, Abstract_Wallet
from electrum.wallet import Wallet, Abstract_Wallet, update_password_for_directory
from electrum.storage import WalletStorage, StorageReadWriteError
from electrum.wallet_db import WalletDB
@ -104,7 +104,8 @@ class QEDaemon(AuthMixin, QObject):
_available_wallets = None
_current_wallet = None
_path = None
_use_single_password = False
_password = None
walletLoaded = pyqtSignal()
walletRequiresPassword = pyqtSignal()
@ -144,6 +145,12 @@ class QEDaemon(AuthMixin, QObject):
self._loaded_wallets.add_wallet(wallet=wallet)
self._current_wallet = QEWallet.getInstanceFor(wallet)
self.walletLoaded.emit()
if self.daemon.config.get('single_password'):
self._use_single_password = update_password_for_directory(self.daemon.config, password, password)
self._password = password
self._logger.info(f'use single password: {self._use_single_password}')
self.daemon.config.save_last_wallet(wallet)
else:
self._logger.info('could not open wallet')
@ -195,3 +202,17 @@ class QEDaemon(AuthMixin, QObject):
i = i + 1
return f'wallet_{i}'
requestNewPassword = pyqtSignal()
@pyqtSlot()
@auth_protect
def start_change_password(self):
if self._use_single_password:
self.requestNewPassword.emit()
else:
self.currentWallet.requestNewPassword.emit()
@pyqtSlot(str)
def set_password(self, password):
assert self._use_single_password
self._logger.debug('about to set password to %s for ALL wallets' % password)
update_password_for_directory(self.daemon.config, self._password, password)

7
electrum/gui/qml/qewallet.py

@ -57,6 +57,7 @@ class QEWallet(AuthMixin, QObject):
invoiceCreateError = pyqtSignal([str,str], arguments=['code','error'])
paymentSucceeded = pyqtSignal([str], arguments=['key'])
paymentFailed = pyqtSignal([str,str], arguments=['key','reason'])
requestNewPassword = pyqtSignal()
_network_signal = pyqtSignal(str, object)
@ -499,12 +500,6 @@ class QEWallet(AuthMixin, QObject):
except InvalidPassword as e:
return False
requestNewPassword = pyqtSignal()
@pyqtSlot()
@auth_protect
def start_change_password(self):
self.requestNewPassword.emit()
@pyqtSlot(str)
def set_password(self, password):
storage = self.wallet.storage

Loading…
Cancel
Save