diff --git a/src/main/java/com/sparrowwallet/sparrow/event/WalletBlockHeightChangedEvent.java b/src/main/java/com/sparrowwallet/sparrow/event/WalletBlockHeightChangedEvent.java new file mode 100644 index 00000000..16d75938 --- /dev/null +++ b/src/main/java/com/sparrowwallet/sparrow/event/WalletBlockHeightChangedEvent.java @@ -0,0 +1,16 @@ +package com.sparrowwallet.sparrow.event; + +import com.sparrowwallet.drongo.wallet.Wallet; + +public class WalletBlockHeightChangedEvent extends WalletChangedEvent { + private Integer blockHeight; + + public WalletBlockHeightChangedEvent(Wallet wallet, Integer blockHeight) { + super(wallet); + this.blockHeight = blockHeight; + } + + public Integer getBlockHeight() { + return blockHeight; + } +} diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java index b10d5c1f..a492387a 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java @@ -6,10 +6,7 @@ import com.sparrowwallet.drongo.wallet.Wallet; import com.sparrowwallet.drongo.wallet.WalletNode; import com.sparrowwallet.sparrow.AppController; import com.sparrowwallet.sparrow.EventManager; -import com.sparrowwallet.sparrow.event.ConnectionEvent; -import com.sparrowwallet.sparrow.event.NewBlockEvent; -import com.sparrowwallet.sparrow.event.WalletChangedEvent; -import com.sparrowwallet.sparrow.event.WalletHistoryChangedEvent; +import com.sparrowwallet.sparrow.event.*; import com.sparrowwallet.sparrow.io.ElectrumServer; import com.sparrowwallet.sparrow.io.Storage; import javafx.application.Platform; @@ -62,7 +59,7 @@ public class WalletForm { ElectrumServer.TransactionHistoryService historyService = new ElectrumServer.TransactionHistoryService(wallet); historyService.setOnSucceeded(workerStateEvent -> { wallet.setStoredBlockHeight(blockHeight); - notifyIfHistoryChanged(previousWallet); + notifyIfChanged(previousWallet, blockHeight); }); historyService.setOnFailed(workerStateEvent -> { workerStateEvent.getSource().getException().printStackTrace(); @@ -71,13 +68,15 @@ public class WalletForm { } } - private void notifyIfHistoryChanged(Wallet previousWallet) { + private void notifyIfChanged(Wallet previousWallet, Integer blockHeight) { List historyChangedNodes = new ArrayList<>(); historyChangedNodes.addAll(getHistoryChangedNodes(previousWallet.getNode(KeyPurpose.RECEIVE).getChildren(), wallet.getNode(KeyPurpose.RECEIVE).getChildren())); historyChangedNodes.addAll(getHistoryChangedNodes(previousWallet.getNode(KeyPurpose.CHANGE).getChildren(), wallet.getNode(KeyPurpose.CHANGE).getChildren())); if(!historyChangedNodes.isEmpty()) { Platform.runLater(() -> EventManager.get().post(new WalletHistoryChangedEvent(wallet, historyChangedNodes))); + } else if(blockHeight != null && !blockHeight.equals(previousWallet.getStoredBlockHeight())) { + Platform.runLater(() -> EventManager.get().post(new WalletBlockHeightChangedEvent(wallet, blockHeight))); } }