Browse Source

qml: refresh address list on new transaction by setting dirty flag

patch-4
Sander van Grieken 2 years ago
parent
commit
e3b3f04afe
  1. 3
      electrum/gui/qml/components/Addresses.qml
  2. 10
      electrum/gui/qml/qeaddresslistmodel.py
  3. 2
      electrum/gui/qml/qewallet.py

3
electrum/gui/qml/components/Addresses.qml

@ -169,4 +169,7 @@ Pane {
}
}
Component.onCompleted: {
Daemon.currentWallet.addressModel.init_model()
}
}

10
electrum/gui/qml/qeaddresslistmodel.py

@ -16,6 +16,7 @@ class QEAddressListModel(QAbstractListModel):
def __init__(self, wallet: 'Abstract_Wallet', parent=None):
super().__init__(parent)
self.wallet = wallet
self.setDirty()
self.init_model()
_logger = get_logger(__name__)
@ -60,9 +61,16 @@ class QEAddressListModel(QAbstractListModel):
item['held'] = self.wallet.is_frozen_address(address)
return item
@pyqtSlot()
def setDirty(self):
self._dirty = True
# initial model data
@pyqtSlot()
def init_model(self):
if not self._dirty:
return
r_addresses = self.wallet.get_receiving_addresses()
c_addresses = self.wallet.get_change_addresses()
n_addresses = len(r_addresses) + len(c_addresses) if self.wallet.use_change else 0
@ -85,6 +93,8 @@ class QEAddressListModel(QAbstractListModel):
i = i + 1
self.endInsertRows()
self._dirty = False
@pyqtSlot(str)
def update_address(self, address):
i = 0

2
electrum/gui/qml/qewallet.py

@ -171,7 +171,9 @@ class QEWallet(AuthMixin, QObject, QtEventListener):
@qt_event_listener
def on_event_new_transaction(self, wallet, tx):
if wallet == self.wallet:
self._logger.info(f'new transaction {tx.txid()}')
self.add_tx_notification(tx)
self.addressModel.setDirty()
self.historyModel.init_model() # TODO: be less dramatic
@qt_event_listener

Loading…
Cancel
Save