From 94da3b37b6558fbd595aba5114a450cf84f4d074 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Tue, 12 Jan 2021 14:43:30 +0200 Subject: [PATCH] show tx count, set default server type --- .../com/sparrowwallet/sparrow/MainApp.java | 10 ++--- .../wallet/TransactionsController.java | 37 ++++++++++++++----- .../sparrow/wallet/transactions.fxml | 11 +++--- 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/MainApp.java b/src/main/java/com/sparrowwallet/sparrow/MainApp.java index 113f5c91..db230679 100644 --- a/src/main/java/com/sparrowwallet/sparrow/MainApp.java +++ b/src/main/java/com/sparrowwallet/sparrow/MainApp.java @@ -9,14 +9,10 @@ import com.sparrowwallet.sparrow.io.Config; import com.sparrowwallet.sparrow.io.FileType; import com.sparrowwallet.sparrow.io.IOUtils; import com.sparrowwallet.sparrow.io.Storage; +import com.sparrowwallet.sparrow.net.ServerType; import com.sparrowwallet.sparrow.preferences.PreferenceGroup; import com.sparrowwallet.sparrow.preferences.PreferencesDialog; import javafx.application.Application; -import javafx.application.Platform; -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.scene.image.Image; import javafx.scene.text.Font; import javafx.stage.Stage; import org.controlsfx.glyphfont.GlyphFontRegistry; @@ -66,6 +62,10 @@ public class MainApp extends Application { } } + if(Config.get().getServerType() == null) { + Config.get().setServerType(ServerType.ELECTRUM_SERVER); + } + AppServices.initialize(this); AppController appController = AppServices.newAppWindow(stage); diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/TransactionsController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/TransactionsController.java index d46abff1..ccdadb24 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/TransactionsController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/TransactionsController.java @@ -4,10 +4,7 @@ import com.google.common.eventbus.Subscribe; import com.sparrowwallet.sparrow.AppServices; import com.sparrowwallet.sparrow.CurrencyRate; import com.sparrowwallet.sparrow.EventManager; -import com.sparrowwallet.sparrow.control.BalanceChart; -import com.sparrowwallet.sparrow.control.CoinLabel; -import com.sparrowwallet.sparrow.control.FiatLabel; -import com.sparrowwallet.sparrow.control.TransactionsTreeTable; +import com.sparrowwallet.sparrow.control.*; import com.sparrowwallet.sparrow.event.*; import com.sparrowwallet.sparrow.net.ExchangeSource; import javafx.collections.ListChangeListener; @@ -29,6 +26,12 @@ public class TransactionsController extends WalletFormController implements Init @FXML private CoinLabel mempoolBalance; + @FXML + private FiatLabel fiatMempoolBalance; + + @FXML + private CopyableLabel transactionCount; + @FXML private TransactionsTreeTable transactionsTable; @@ -47,10 +50,14 @@ public class TransactionsController extends WalletFormController implements Init transactionsTable.initialize(walletTransactionsEntry); balance.valueProperty().addListener((observable, oldValue, newValue) -> { - setFiatBalance(AppServices.getFiatCurrencyExchangeRate(), newValue.longValue()); + setFiatBalance(fiatBalance, AppServices.getFiatCurrencyExchangeRate(), newValue.longValue()); }); balance.setValue(walletTransactionsEntry.getBalance()); + mempoolBalance.valueProperty().addListener((observable, oldValue, newValue) -> { + setFiatBalance(fiatMempoolBalance, AppServices.getFiatCurrencyExchangeRate(), newValue.longValue()); + }); mempoolBalance.setValue(walletTransactionsEntry.getMempoolBalance()); + setTransactionCount(walletTransactionsEntry); balanceChart.initialize(walletTransactionsEntry); transactionsTable.getSelectionModel().getSelectedIndices().addListener((ListChangeListener) c -> { @@ -61,12 +68,19 @@ public class TransactionsController extends WalletFormController implements Init }); } - private void setFiatBalance(CurrencyRate currencyRate, long balance) { - if(currencyRate != null && currencyRate.isAvailable()) { - fiatBalance.set(currencyRate, balance); + private void setFiatBalance(FiatLabel fiatLabel, CurrencyRate currencyRate, long balance) { + if(currencyRate != null && currencyRate.isAvailable() && balance > 0) { + fiatLabel.set(currencyRate, balance); + } else { + fiatLabel.setCurrency(null); + fiatLabel.setBtcRate(0.0); } } + private void setTransactionCount(WalletTransactionsEntry walletTransactionsEntry) { + transactionCount.setText(walletTransactionsEntry.getChildren() != null ? Integer.toString(walletTransactionsEntry.getChildren().size()) : "0"); + } + @Subscribe public void walletNodesChanged(WalletNodesChangedEvent event) { if(event.getWallet().equals(walletForm.getWallet())) { @@ -76,6 +90,7 @@ public class TransactionsController extends WalletFormController implements Init balance.setValue(walletTransactionsEntry.getBalance()); mempoolBalance.setValue(walletTransactionsEntry.getMempoolBalance()); balanceChart.update(walletTransactionsEntry); + setTransactionCount(walletTransactionsEntry); } } @@ -91,6 +106,7 @@ public class TransactionsController extends WalletFormController implements Init balance.setValue(walletTransactionsEntry.getBalance()); mempoolBalance.setValue(walletTransactionsEntry.getMempoolBalance()); balanceChart.update(walletTransactionsEntry); + setTransactionCount(walletTransactionsEntry); } } @@ -115,12 +131,15 @@ public class TransactionsController extends WalletFormController implements Init if(event.getExchangeSource() == ExchangeSource.NONE) { fiatBalance.setCurrency(null); fiatBalance.setBtcRate(0.0); + fiatMempoolBalance.setCurrency(null); + fiatMempoolBalance.setBtcRate(0.0); } } @Subscribe public void exchangeRatesUpdated(ExchangeRatesUpdatedEvent event) { - setFiatBalance(event.getCurrencyRate(), getWalletForm().getWalletTransactionsEntry().getBalance()); + setFiatBalance(fiatBalance, event.getCurrencyRate(), getWalletForm().getWalletTransactionsEntry().getBalance()); + setFiatBalance(fiatMempoolBalance, event.getCurrencyRate(), getWalletForm().getWalletTransactionsEntry().getMempoolBalance()); } @Subscribe diff --git a/src/main/resources/com/sparrowwallet/sparrow/wallet/transactions.fxml b/src/main/resources/com/sparrowwallet/sparrow/wallet/transactions.fxml index 39ebf611..9bbdc27a 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/wallet/transactions.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/wallet/transactions.fxml @@ -14,6 +14,7 @@ +
@@ -32,13 +33,13 @@
- - - - + - + + + +