1
0

qml: use dirty flag on qetransactionlistmodel

This commit is contained in:
Sander van Grieken
2023-02-01 15:44:30 +01:00
parent 96ac199f5c
commit 7ea2a2a8ea
5 changed files with 20 additions and 5 deletions

View File

@@ -248,7 +248,7 @@ Pane {
dialog.yesClicked.connect(function() {
channeldetails.deleteChannel()
app.stack.pop()
Daemon.currentWallet.historyModel.init_model() // needed here?
Daemon.currentWallet.historyModel.init_model(true) // needed here?
Daemon.currentWallet.channelModel.remove_channel(channelid)
})
dialog.open()

View File

@@ -227,7 +227,7 @@ ElDialog {
+ qsTr('This channel will be usable after %1 confirmations').arg(min_depth)
if (!tx_complete) {
message = message + '\n\n' + qsTr('Please sign and broadcast the funding transaction.')
channelopener.wallet.historyModel.init_model() // local tx doesn't trigger model update
channelopener.wallet.historyModel.init_model(true) // local tx doesn't trigger model update
}
app.channelOpenProgressDialog.state = 'success'
app.channelOpenProgressDialog.info = message

View File

@@ -384,7 +384,7 @@ Pane {
dialog.yesClicked.connect(function() {
dialog.close()
txdetails.removeLocalTx(true)
txdetails.wallet.historyModel.init_model()
txdetails.wallet.historyModel.init_model(true)
root.close()
})
dialog.open()

View File

@@ -32,6 +32,7 @@ class QETransactionListModel(QAbstractListModel, QtEventListener):
self.destroyed.connect(lambda: self.on_destroy())
self.requestRefresh.connect(lambda: self.init_model())
self.setDirty()
self.init_model()
def on_destroy(self):
@@ -71,6 +72,10 @@ class QETransactionListModel(QAbstractListModel, QtEventListener):
return value.value
return str(value)
@pyqtSlot()
def setDirty(self):
self._dirty = True
def clear(self):
self.beginResetModel()
self.tx_history = []
@@ -139,7 +144,12 @@ class QETransactionListModel(QAbstractListModel, QtEventListener):
# initial model data
@pyqtSlot()
def init_model(self):
@pyqtSlot(bool)
def init_model(self, force: bool = False):
# only (re)construct if dirty or forced
if not self._dirty and not force:
return
self._logger.debug('retrieving history')
history = self.wallet.get_full_history(onchain_domain=self.onchain_domain,
include_lightning=self.include_lightning)
@@ -155,6 +165,8 @@ class QETransactionListModel(QAbstractListModel, QtEventListener):
self.countChanged.emit()
self._dirty = False
def on_tx_verified(self, txid, info):
i = 0
for tx in self.tx_history:

View File

@@ -148,6 +148,9 @@ class QEWallet(AuthMixin, QObject, QtEventListener):
self._isUpToDate = uptodate
self.isUptodateChanged.emit()
if uptodate:
self.historyModel.init_model()
if self.wallet.network.is_connected():
server_height = self.wallet.network.get_server_height()
server_lag = self.wallet.network.get_local_height() - server_height
@@ -187,7 +190,7 @@ class QEWallet(AuthMixin, QObject, QtEventListener):
self._logger.info(f'new transaction {tx.txid()}')
self.add_tx_notification(tx)
self.addressModel.setDirty()
self.historyModel.init_model() # TODO: be less dramatic
self.historyModel.setDirty() # assuming wallet.is_up_to_date triggers after
@event_listener
def on_event_wallet_updated(self, wallet):