|
|
|
@ -106,6 +106,11 @@ class QEWallet(AuthMixin, QObject, QtEventListener): |
|
|
|
self.notification_timer.setInterval(500) # msec |
|
|
|
self.notification_timer.setInterval(500) # msec |
|
|
|
self.notification_timer.timeout.connect(self.notify_transactions) |
|
|
|
self.notification_timer.timeout.connect(self.notify_transactions) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.sync_progress_timer = QTimer(self) |
|
|
|
|
|
|
|
self.sync_progress_timer.setSingleShot(False) |
|
|
|
|
|
|
|
self.sync_progress_timer.setInterval(2000) |
|
|
|
|
|
|
|
self.sync_progress_timer.timeout.connect(self.update_sync_progress) |
|
|
|
|
|
|
|
|
|
|
|
# To avoid leaking references to "self" that prevent the |
|
|
|
# To avoid leaking references to "self" that prevent the |
|
|
|
# window from being GC-ed when closed, callbacks should be |
|
|
|
# window from being GC-ed when closed, callbacks should be |
|
|
|
# methods of this class only, and specifically not be |
|
|
|
# methods of this class only, and specifically not be |
|
|
|
@ -114,6 +119,8 @@ class QEWallet(AuthMixin, QObject, QtEventListener): |
|
|
|
self.register_callbacks() |
|
|
|
self.register_callbacks() |
|
|
|
self.destroyed.connect(lambda: self.on_destroy()) |
|
|
|
self.destroyed.connect(lambda: self.on_destroy()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.synchronizing = True # start in sync state |
|
|
|
|
|
|
|
|
|
|
|
@pyqtProperty(bool, notify=isUptodateChanged) |
|
|
|
@pyqtProperty(bool, notify=isUptodateChanged) |
|
|
|
def isUptodate(self): |
|
|
|
def isUptodate(self): |
|
|
|
return self._isUpToDate |
|
|
|
return self._isUpToDate |
|
|
|
@ -126,21 +133,29 @@ class QEWallet(AuthMixin, QObject, QtEventListener): |
|
|
|
@synchronizing.setter |
|
|
|
@synchronizing.setter |
|
|
|
def synchronizing(self, synchronizing): |
|
|
|
def synchronizing(self, synchronizing): |
|
|
|
if self._synchronizing != synchronizing: |
|
|
|
if self._synchronizing != synchronizing: |
|
|
|
|
|
|
|
self._logger.info(f'SYNC {self._synchronizing} -> {synchronizing}') |
|
|
|
self._synchronizing = synchronizing |
|
|
|
self._synchronizing = synchronizing |
|
|
|
self.synchronizingChanged.emit() |
|
|
|
self.synchronizingChanged.emit() |
|
|
|
|
|
|
|
if synchronizing: |
|
|
|
|
|
|
|
if not self.sync_progress_timer.isActive(): |
|
|
|
|
|
|
|
self.update_sync_progress() |
|
|
|
|
|
|
|
self.sync_progress_timer.start() |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
self.sync_progress_timer.stop() |
|
|
|
|
|
|
|
|
|
|
|
synchronizingProgressChanged = pyqtSignal() |
|
|
|
synchronizingProgressChanged = pyqtSignal() |
|
|
|
@pyqtProperty(str, notify=synchronizingProgressChanged) |
|
|
|
@pyqtProperty(str, notify=synchronizingProgressChanged) |
|
|
|
def synchronizing_progress(self): |
|
|
|
def synchronizingProgress(self): |
|
|
|
return self._synchronizing_progress |
|
|
|
return self._synchronizing_progress |
|
|
|
|
|
|
|
|
|
|
|
@synchronizing_progress.setter |
|
|
|
@synchronizingProgress.setter |
|
|
|
def synchronizing_progress(self, progress): |
|
|
|
def synchronizingProgress(self, progress): |
|
|
|
if self._synchronizing_progress != progress: |
|
|
|
if self._synchronizing_progress != progress: |
|
|
|
self._synchronizing_progress = progress |
|
|
|
self._synchronizing_progress = progress |
|
|
|
|
|
|
|
self._logger.info(progress) |
|
|
|
self.synchronizingProgressChanged.emit() |
|
|
|
self.synchronizingProgressChanged.emit() |
|
|
|
|
|
|
|
|
|
|
|
@event_listener |
|
|
|
@qt_event_listener |
|
|
|
def on_event_status(self): |
|
|
|
def on_event_status(self): |
|
|
|
self._logger.debug('status') |
|
|
|
self._logger.debug('status') |
|
|
|
uptodate = self.wallet.is_up_to_date() |
|
|
|
uptodate = self.wallet.is_up_to_date() |
|
|
|
@ -151,21 +166,6 @@ class QEWallet(AuthMixin, QObject, QtEventListener): |
|
|
|
if uptodate: |
|
|
|
if uptodate: |
|
|
|
self.historyModel.init_model() |
|
|
|
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 |
|
|
|
|
|
|
|
# Server height can be 0 after switching to a new server |
|
|
|
|
|
|
|
# until we get a headers subscription request response. |
|
|
|
|
|
|
|
# Display the synchronizing message in that case. |
|
|
|
|
|
|
|
if not self._isUpToDate or server_height == 0: |
|
|
|
|
|
|
|
num_sent, num_answered = self.wallet.adb.get_history_sync_state_details() |
|
|
|
|
|
|
|
self.synchronizing_progress = ("{} ({}/{})" |
|
|
|
|
|
|
|
.format(_("Synchronizing..."), num_answered, num_sent)) |
|
|
|
|
|
|
|
self.synchronizing = True |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
self.synchronizing_progress = '' |
|
|
|
|
|
|
|
self.synchronizing = False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@qt_event_listener |
|
|
|
@qt_event_listener |
|
|
|
def on_event_request_status(self, wallet, key, status): |
|
|
|
def on_event_request_status(self, wallet, key, status): |
|
|
|
if wallet == self.wallet: |
|
|
|
if wallet == self.wallet: |
|
|
|
@ -176,7 +176,7 @@ class QEWallet(AuthMixin, QObject, QtEventListener): |
|
|
|
# TODO: only update if it was paid over lightning, |
|
|
|
# TODO: only update if it was paid over lightning, |
|
|
|
# and even then, we can probably just add the payment instead |
|
|
|
# and even then, we can probably just add the payment instead |
|
|
|
# of recreating the whole history (expensive) |
|
|
|
# of recreating the whole history (expensive) |
|
|
|
self.historyModel.init_model() |
|
|
|
self.historyModel.init_model(True) |
|
|
|
|
|
|
|
|
|
|
|
@event_listener |
|
|
|
@event_listener |
|
|
|
def on_event_invoice_status(self, wallet, key, status): |
|
|
|
def on_event_invoice_status(self, wallet, key, status): |
|
|
|
@ -192,11 +192,12 @@ class QEWallet(AuthMixin, QObject, QtEventListener): |
|
|
|
self.addressModel.setDirty() |
|
|
|
self.addressModel.setDirty() |
|
|
|
self.historyModel.setDirty() # assuming wallet.is_up_to_date triggers after |
|
|
|
self.historyModel.setDirty() # assuming wallet.is_up_to_date triggers after |
|
|
|
|
|
|
|
|
|
|
|
@event_listener |
|
|
|
@qt_event_listener |
|
|
|
def on_event_wallet_updated(self, wallet): |
|
|
|
def on_event_wallet_updated(self, wallet): |
|
|
|
if wallet == self.wallet: |
|
|
|
if wallet == self.wallet: |
|
|
|
self._logger.debug('wallet %s updated' % str(wallet)) |
|
|
|
self._logger.debug('wallet %s updated' % str(wallet)) |
|
|
|
self.balanceChanged.emit() |
|
|
|
self.balanceChanged.emit() |
|
|
|
|
|
|
|
self.synchronizing = not wallet.is_up_to_date() |
|
|
|
|
|
|
|
|
|
|
|
@event_listener |
|
|
|
@event_listener |
|
|
|
def on_event_channel(self, wallet, channel): |
|
|
|
def on_event_channel(self, wallet, channel): |
|
|
|
@ -214,7 +215,7 @@ class QEWallet(AuthMixin, QObject, QtEventListener): |
|
|
|
def on_event_payment_succeeded(self, wallet, key): |
|
|
|
def on_event_payment_succeeded(self, wallet, key): |
|
|
|
if wallet == self.wallet: |
|
|
|
if wallet == self.wallet: |
|
|
|
self.paymentSucceeded.emit(key) |
|
|
|
self.paymentSucceeded.emit(key) |
|
|
|
self.historyModel.init_model() # TODO: be less dramatic |
|
|
|
self.historyModel.init_model(True) # TODO: be less dramatic |
|
|
|
|
|
|
|
|
|
|
|
@event_listener |
|
|
|
@event_listener |
|
|
|
def on_event_payment_failed(self, wallet, key, reason): |
|
|
|
def on_event_payment_failed(self, wallet, key, reason): |
|
|
|
@ -269,6 +270,12 @@ class QEWallet(AuthMixin, QObject, QtEventListener): |
|
|
|
self.userNotify.emit(self.wallet, |
|
|
|
self.userNotify.emit(self.wallet, |
|
|
|
_("New transaction: {}").format(config.format_amount_and_units(tx_wallet_delta.delta))) |
|
|
|
_("New transaction: {}").format(config.format_amount_and_units(tx_wallet_delta.delta))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_sync_progress(self): |
|
|
|
|
|
|
|
if self.wallet.network.is_connected(): |
|
|
|
|
|
|
|
num_sent, num_answered = self.wallet.adb.get_history_sync_state_details() |
|
|
|
|
|
|
|
self.synchronizingProgress = \ |
|
|
|
|
|
|
|
("{} ({}/{})".format(_("Synchronizing..."), num_answered, num_sent)) |
|
|
|
|
|
|
|
|
|
|
|
historyModelChanged = pyqtSignal() |
|
|
|
historyModelChanged = pyqtSignal() |
|
|
|
@pyqtProperty(QETransactionListModel, notify=historyModelChanged) |
|
|
|
@pyqtProperty(QETransactionListModel, notify=historyModelChanged) |
|
|
|
def historyModel(self): |
|
|
|
def historyModel(self): |
|
|
|
|