@ -12,6 +12,8 @@ from typing import TYPE_CHECKING, Optional, Union, Callable, Sequence
from electrum . storage import WalletStorage , StorageReadWriteError
from electrum . wallet_db import WalletDB
from electrum . wallet import Wallet , InternalAddressCorruption , Abstract_Wallet
from electrum . wallet import check_password_for_directory , update_password_for_directory
from electrum . plugin import run_hook
from electrum import util
from electrum . util import ( profiler , InvalidPassword , send_exception_to_crash_reporter ,
@ -367,6 +369,7 @@ class ElectrumWindow(App, Logger):
self . pause_time = 0
self . asyncio_loop = asyncio . get_event_loop ( )
self . password = None
self . _use_single_password = False
App . __init__ ( self ) #, **kwargs)
Logger . __init__ ( self )
@ -634,6 +637,9 @@ class ElectrumWindow(App, Logger):
def on_wizard_success ( self , storage , db , password ) :
self . password = password
if self . electrum_config . get ( ' single_password ' ) :
self . _use_single_password = check_password_for_directory ( self . electrum_config , password )
self . logger . info ( f ' use single password: { self . _use_single_password } ' )
wallet = Wallet ( db , storage , config = self . electrum_config )
wallet . start_network ( self . daemon . network )
self . daemon . add_wallet ( wallet )
@ -649,6 +655,12 @@ class ElectrumWindow(App, Logger):
return
if self . wallet and self . wallet . storage . path == path :
return
if self . password and self . _use_single_password :
storage = WalletStorage ( path )
# call check_password to decrypt
storage . check_password ( self . password )
self . on_open_wallet ( self . password , storage )
return
d = OpenWalletDialog ( self , path , self . on_open_wallet )
d . open ( )
@ -724,10 +736,13 @@ class ElectrumWindow(App, Logger):
if self . _channels_dialog :
Clock . schedule_once ( lambda dt : self . _channels_dialog . update ( ) )
def is_wallet_creation_disabled ( self ) :
return bool ( self . electrum_config . get ( ' single_password ' ) ) and self . password is None
def wallets_dialog ( self ) :
from . uix . dialogs . wallets import WalletDialog
dirname = os . path . dirname ( self . electrum_config . get_wallet_path ( ) )
d = WalletDialog ( dirname , self . load_wallet_by_name )
d = WalletDialog ( dirname , self . load_wallet_by_name , self . is_wallet_creation_disabled ( ) )
d . open ( )
def popup_dialog ( self , name ) :
@ -1219,9 +1234,18 @@ class ElectrumWindow(App, Logger):
def change_password ( self , cb ) :
def on_success ( old_password , new_password ) :
self . wallet . update_password ( old_password , new_password )
# called if old_password works on self.wallet
self . password = new_password
self . show_info ( _ ( " Your password was updated " ) )
if self . _use_single_password :
path = self . wallet . storage . path
self . stop_wallet ( )
update_password_for_directory ( self . electrum_config , old_password , new_password )
self . load_wallet_by_name ( path )
msg = _ ( " Password updated successfully " )
else :
self . wallet . update_password ( old_password , new_password )
msg = _ ( " Password updated for {} " ) . format ( os . path . basename ( self . wallet . storage . path ) )
self . show_info ( msg )
on_failure = lambda : self . show_error ( _ ( " Password not updated " ) )
d = ChangePasswordDialog ( self , self . wallet , on_success , on_failure )
d . open ( )