From 13d701b0a7985fff3b5be1241527273445cac826 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 8 Mar 2021 10:45:29 +0200 Subject: [PATCH] indicate when initially loading a wallets transactions in status bar --- .../sparrowwallet/sparrow/AppController.java | 22 +++++++++++++++++++ .../event/WalletHistoryFinishedEvent.java | 13 +++++++++++ .../event/WalletHistoryStartedEvent.java | 9 ++++++++ .../event/WalletHistoryStatusEvent.java | 2 +- .../sparrow/wallet/WalletForm.java | 11 +++++++--- 5 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/sparrowwallet/sparrow/event/WalletHistoryFinishedEvent.java create mode 100644 src/main/java/com/sparrowwallet/sparrow/event/WalletHistoryStartedEvent.java diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index 41fa6ce2..b7bd661d 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -1347,6 +1347,28 @@ public class AppController implements Initializable { } } + @Subscribe + public void walletHistoryStarted(WalletHistoryStartedEvent event) { + if(AppServices.isConnected() && getOpenWallets().containsKey(event.getWallet())) { + statusUpdated(new StatusEvent("Loading transactions...", 120)); + if(statusTimeline == null || statusTimeline.getStatus() != Animation.Status.RUNNING) { + statusBar.setProgress(-1); + } + } + } + + @Subscribe + public void walletHistoryFinished(WalletHistoryFinishedEvent event) { + if(getOpenWallets().containsKey(event.getWallet())) { + if(statusBar.getText().equals("Loading transactions...")) { + statusBar.setText(""); + } + if(statusTimeline == null || statusTimeline.getStatus() != Animation.Status.RUNNING) { + statusBar.setProgress(0); + } + } + } + @Subscribe public void bwtBootStatus(BwtBootStatusEvent event) { serverToggle.setDisable(true); diff --git a/src/main/java/com/sparrowwallet/sparrow/event/WalletHistoryFinishedEvent.java b/src/main/java/com/sparrowwallet/sparrow/event/WalletHistoryFinishedEvent.java new file mode 100644 index 00000000..41f463dd --- /dev/null +++ b/src/main/java/com/sparrowwallet/sparrow/event/WalletHistoryFinishedEvent.java @@ -0,0 +1,13 @@ +package com.sparrowwallet.sparrow.event; + +import com.sparrowwallet.drongo.wallet.Wallet; + +public class WalletHistoryFinishedEvent extends WalletHistoryStatusEvent { + public WalletHistoryFinishedEvent(Wallet wallet) { + super(wallet, false); + } + + public WalletHistoryFinishedEvent(Wallet wallet, String errorMessage) { + super(wallet, errorMessage); + } +} diff --git a/src/main/java/com/sparrowwallet/sparrow/event/WalletHistoryStartedEvent.java b/src/main/java/com/sparrowwallet/sparrow/event/WalletHistoryStartedEvent.java new file mode 100644 index 00000000..81e98946 --- /dev/null +++ b/src/main/java/com/sparrowwallet/sparrow/event/WalletHistoryStartedEvent.java @@ -0,0 +1,9 @@ +package com.sparrowwallet.sparrow.event; + +import com.sparrowwallet.drongo.wallet.Wallet; + +public class WalletHistoryStartedEvent extends WalletHistoryStatusEvent { + public WalletHistoryStartedEvent(Wallet wallet) { + super(wallet, true); + } +} diff --git a/src/main/java/com/sparrowwallet/sparrow/event/WalletHistoryStatusEvent.java b/src/main/java/com/sparrowwallet/sparrow/event/WalletHistoryStatusEvent.java index b433e133..4685f03a 100644 --- a/src/main/java/com/sparrowwallet/sparrow/event/WalletHistoryStatusEvent.java +++ b/src/main/java/com/sparrowwallet/sparrow/event/WalletHistoryStatusEvent.java @@ -24,7 +24,7 @@ public class WalletHistoryStatusEvent { public WalletHistoryStatusEvent(Wallet wallet, String errorMessage) { this.wallet = wallet; - this.loading = true; + this.loading = false; this.statusMessage = null; this.errorMessage = errorMessage; } diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java index 2575b887..1d023797 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java @@ -100,14 +100,19 @@ public class WalletForm { log.debug(node == null ? wallet.getName() + " refreshing full wallet history" : wallet.getName() + " requesting node wallet history for " + node.getDerivationPath()); ElectrumServer.TransactionHistoryService historyService = new ElectrumServer.TransactionHistoryService(wallet, getWalletTransactionNodes(node)); historyService.setOnSucceeded(workerStateEvent -> { - EventManager.get().post(new WalletHistoryStatusEvent(wallet, false)); + EventManager.get().post(new WalletHistoryFinishedEvent(wallet)); updateWallet(blockHeight, pastWallet, previousWallet); }); historyService.setOnFailed(workerStateEvent -> { log.error("Error retrieving wallet history", workerStateEvent.getSource().getException()); - EventManager.get().post(new WalletHistoryStatusEvent(wallet, workerStateEvent.getSource().getException().getMessage())); + EventManager.get().post(new WalletHistoryFinishedEvent(wallet, workerStateEvent.getSource().getException().getMessage())); }); - EventManager.get().post(new WalletHistoryStatusEvent(wallet, true)); + if(node == null && wallet.getTransactions().isEmpty()) { + EventManager.get().post(new WalletHistoryStartedEvent(wallet)); + } else { + EventManager.get().post(new WalletHistoryStatusEvent(wallet, true)); + } + historyService.start(); } }