Browse Source

avoid duplicate QEWallet instances

patch-4
Sander van Grieken 3 years ago
parent
commit
a65ea46b5d
  1. 7
      electrum/gui/qml/qedaemon.py
  2. 13
      electrum/gui/qml/qewallet.py

7
electrum/gui/qml/qedaemon.py

@ -43,6 +43,11 @@ class QEWalletListModel(QAbstractListModel):
def add_wallet(self, wallet_path = None, wallet: Abstract_Wallet = None):
if wallet_path == None and wallet == None:
return
# only add wallet instance if instance not yet in model
if wallet:
for name,path,w in self.wallets:
if w == wallet:
return
self.beginInsertRows(QModelIndex(), len(self.wallets), len(self.wallets));
if wallet == None:
wallet_name = os.path.basename(wallet_path)
@ -117,7 +122,7 @@ class QEDaemon(QObject):
wallet = self.daemon.load_wallet(self._path, password)
if wallet != None:
self._loaded_wallets.add_wallet(wallet=wallet)
self._current_wallet = QEWallet(wallet)
self._current_wallet = QEWallet.getInstanceFor(wallet)
self.walletLoaded.emit()
self.daemon.config.save_last_wallet(wallet)
else:

13
electrum/gui/qml/qewallet.py

@ -18,6 +18,19 @@ from .qetransactionlistmodel import QETransactionListModel
from .qeaddresslistmodel import QEAddressListModel
class QEWallet(QObject):
__instances = []
# this factory method should be used to instantiate QEWallet
# so we have only one QEWallet for each electrum.wallet
@classmethod
def getInstanceFor(cls, wallet):
for i in cls.__instances:
if i.wallet == wallet:
return i
i = QEWallet(wallet)
cls.__instances.append(i)
return i
_logger = get_logger(__name__)
# emitted when wallet wants to display a user notification

Loading…
Cancel
Save