diff --git a/bitcoin_safe/client_helpers.py b/bitcoin_safe/client_helpers.py index 9546a994..21cb763a 100644 --- a/bitcoin_safe/client_helpers.py +++ b/bitcoin_safe/client_helpers.py @@ -64,3 +64,4 @@ class UpdateType(enum.Enum): update: bdk.Update update_type: UpdateType + wallet_events: list[bdk.WalletEvent] = field(default_factory=list) diff --git a/bitcoin_safe/gui/qt/qt_wallet.py b/bitcoin_safe/gui/qt/qt_wallet.py index e99434ce..e4b58d22 100644 --- a/bitcoin_safe/gui/qt/qt_wallet.py +++ b/bitcoin_safe/gui/qt/qt_wallet.py @@ -326,7 +326,6 @@ def __init__( self._last_syncing_start = datetime.datetime.now() self._syncing_delay = timedelta(seconds=0) - self._last_sync_chain_height = 0 self._rows_after_hist_list_update: list[str] = [] ########### create tabs @@ -1867,15 +1866,13 @@ def is_in_cbf_ibd(self) -> bool: def on_update(self, update_info: UpdateInfo): """On update.""" logger.info(self.tr("start updating lists")) - new_chain_height = self.wallet.get_height_no_cache() - # self.wallet.clear_cache() + self.refresh_caches_and_ui_lists( force_ui_refresh=False, - chain_height_advanced=new_chain_height != self._last_sync_chain_height, + chain_height_advanced=bool([e for e in update_info.wallet_events if e.is_chain_tip_changed()]), ) - # self.update_tabs() + logger.info(self.tr("finished updating lists")) - self._last_sync_chain_height = new_chain_height self.fx.update_if_needed() self.save() diff --git a/bitcoin_safe/wallet.py b/bitcoin_safe/wallet.py index 7fd55c58..3b70a83f 100644 --- a/bitcoin_safe/wallet.py +++ b/bitcoin_safe/wallet.py @@ -1308,17 +1308,18 @@ async def update(self) -> UpdateInfo | None: update_info = await self.client.update() if not update_info: return None - self._apply_update(update=update_info.update) + wallet_events = self._apply_update(update=update_info.update) + update_info.wallet_events = wallet_events return update_info - def _apply_update(self, update: bdk.Update): + def _apply_update(self, update: bdk.Update) -> list[bdk.WalletEvent]: """Apply a client update to the local wallet caches.""" - if update: - self.bdkwallet.apply_update(update) + wallet_events = self.bdkwallet.apply_update_events(update) self.persist() - logger.info("Applied update") + logger.info(f"Applied update with events {[type(event) for event in wallet_events]}") + return wallet_events def forward_search_unused_address( self, category: str | None = None, is_change=False diff --git a/tests/gui/qt/test_qt_wallet.py b/tests/gui/qt/test_qt_wallet.py index 0a72de95..fd5878fe 100644 --- a/tests/gui/qt/test_qt_wallet.py +++ b/tests/gui/qt/test_qt_wallet.py @@ -67,7 +67,6 @@ def _make_qt_wallet_stub(has_gap_overhang: bool) -> tuple[SimpleNamespace, LoopR ) qt_wallet = SimpleNamespace( wallet=wallet, - _last_sync_chain_height=0, refresh_caches_and_ui_lists=lambda force_ui_refresh, chain_height_advanced: None, fx=SimpleNamespace(update_if_needed=lambda: None), save=lambda: None,