avoid duplicate QEWallet instances
This commit is contained in:
@@ -43,6 +43,11 @@ class QEWalletListModel(QAbstractListModel):
|
|||||||
def add_wallet(self, wallet_path = None, wallet: Abstract_Wallet = None):
|
def add_wallet(self, wallet_path = None, wallet: Abstract_Wallet = None):
|
||||||
if wallet_path == None and wallet == None:
|
if wallet_path == None and wallet == None:
|
||||||
return
|
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));
|
self.beginInsertRows(QModelIndex(), len(self.wallets), len(self.wallets));
|
||||||
if wallet == None:
|
if wallet == None:
|
||||||
wallet_name = os.path.basename(wallet_path)
|
wallet_name = os.path.basename(wallet_path)
|
||||||
@@ -117,7 +122,7 @@ class QEDaemon(QObject):
|
|||||||
wallet = self.daemon.load_wallet(self._path, password)
|
wallet = self.daemon.load_wallet(self._path, password)
|
||||||
if wallet != None:
|
if wallet != None:
|
||||||
self._loaded_wallets.add_wallet(wallet=wallet)
|
self._loaded_wallets.add_wallet(wallet=wallet)
|
||||||
self._current_wallet = QEWallet(wallet)
|
self._current_wallet = QEWallet.getInstanceFor(wallet)
|
||||||
self.walletLoaded.emit()
|
self.walletLoaded.emit()
|
||||||
self.daemon.config.save_last_wallet(wallet)
|
self.daemon.config.save_last_wallet(wallet)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -18,6 +18,19 @@ from .qetransactionlistmodel import QETransactionListModel
|
|||||||
from .qeaddresslistmodel import QEAddressListModel
|
from .qeaddresslistmodel import QEAddressListModel
|
||||||
|
|
||||||
class QEWallet(QObject):
|
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__)
|
_logger = get_logger(__name__)
|
||||||
|
|
||||||
# emitted when wallet wants to display a user notification
|
# emitted when wallet wants to display a user notification
|
||||||
|
|||||||
Reference in New Issue
Block a user