1
0

avoid duplicate QEWallet instances

This commit is contained in:
Sander van Grieken
2022-04-04 12:02:27 +02:00
parent 201669d178
commit a65ea46b5d
2 changed files with 19 additions and 1 deletions

View File

@@ -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:

View File

@@ -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