diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index 20aefbe0..f1327b58 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -926,30 +926,32 @@ public class AppController implements Initializable { @Subscribe public void newWalletTransactions(NewWalletTransactionsEvent event) { - String text = "New " + (event.getBlockTransactions().size() > 1 ? "transactions: " : "transaction: "); + if(Config.get().isNotifyNewTransactions()) { + String text = "New " + (event.getBlockTransactions().size() > 1 ? "transactions: " : "transaction: "); - BitcoinUnit unit = Config.get().getBitcoinUnit(); - if(unit == null || unit.equals(BitcoinUnit.AUTO)) { - unit = (event.getTotalValue() >= BitcoinUnit.getAutoThreshold() ? BitcoinUnit.BTC : BitcoinUnit.SATOSHIS); + BitcoinUnit unit = Config.get().getBitcoinUnit(); + if(unit == null || unit.equals(BitcoinUnit.AUTO)) { + unit = (event.getTotalValue() >= BitcoinUnit.getAutoThreshold() ? BitcoinUnit.BTC : BitcoinUnit.SATOSHIS); + } + + if(unit == BitcoinUnit.BTC) { + text += CoinLabel.getBTCFormat().format((double)event.getTotalValue() / Transaction.SATOSHIS_PER_BITCOIN) + " BTC"; + } else { + text += String.format(Locale.ENGLISH, "%,d", event.getTotalValue()) + " sats"; + } + + Image image = new Image("image/sparrow-small.png", 50, 50, false, false); + Notifications notificationBuilder = Notifications.create() + .title("Sparrow - " + event.getWallet().getName()) + .text(text) + .graphic(new ImageView(image)) + .hideAfter(Duration.seconds(180)) + .position(Pos.TOP_RIGHT) + .threshold(5, Notifications.create().title("Sparrow").text("Multiple new wallet transactions").graphic(new ImageView(image))) + .onAction(e -> selectTab(event.getWallet())); + + notificationBuilder.show(); } - - if(unit == BitcoinUnit.BTC) { - text += CoinLabel.getBTCFormat().format((double)event.getTotalValue() / Transaction.SATOSHIS_PER_BITCOIN) + " BTC"; - } else { - text += String.format(Locale.ENGLISH, "%,d", event.getTotalValue()) + " sats"; - } - - Image image = new Image("image/sparrow-small.png", 50, 50, false, false); - Notifications notificationBuilder = Notifications.create() - .title("Sparrow - " + event.getWallet().getName()) - .text(text) - .graphic(new ImageView(image)) - .hideAfter(Duration.seconds(180)) - .position(Pos.TOP_RIGHT) - .threshold(5, Notifications.create().title("Sparrow").text("Multiple new wallet transactions").graphic(new ImageView(image))) - .onAction(e -> selectTab(event.getWallet())); - - notificationBuilder.show(); } @Subscribe diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Config.java b/src/main/java/com/sparrowwallet/sparrow/io/Config.java index 70f11838..0196e2db 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Config.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Config.java @@ -21,6 +21,7 @@ public class Config { private ExchangeSource exchangeSource; private boolean groupByAddress = true; private boolean includeMempoolChange = true; + private boolean notifyNewTransactions = true; private Integer keyDerivationPeriod; private File hwi; private String electrumServer; @@ -123,6 +124,15 @@ public class Config { flush(); } + public boolean isNotifyNewTransactions() { + return notifyNewTransactions; + } + + public void setNotifyNewTransactions(boolean notifyNewTransactions) { + this.notifyNewTransactions = notifyNewTransactions; + flush(); + } + public Integer getKeyDerivationPeriod() { return keyDerivationPeriod; } diff --git a/src/main/java/com/sparrowwallet/sparrow/preferences/GeneralPreferencesController.java b/src/main/java/com/sparrowwallet/sparrow/preferences/GeneralPreferencesController.java index bbc9449d..34269875 100644 --- a/src/main/java/com/sparrowwallet/sparrow/preferences/GeneralPreferencesController.java +++ b/src/main/java/com/sparrowwallet/sparrow/preferences/GeneralPreferencesController.java @@ -35,6 +35,9 @@ public class GeneralPreferencesController extends PreferencesDetailController { @FXML private UnlabeledToggleSwitch includeMempoolChange; + @FXML + private UnlabeledToggleSwitch notifyNewTransactions; + private final ChangeListener fiatCurrencyListener = new ChangeListener() { @Override public void changed(ObservableValue observable, Currency oldValue, Currency newValue) { @@ -78,6 +81,11 @@ public class GeneralPreferencesController extends PreferencesDetailController { includeMempoolChange.selectedProperty().addListener((observableValue, oldValue, newValue) -> { config.setIncludeMempoolChange(newValue); }); + + notifyNewTransactions.setSelected(config.isNotifyNewTransactions()); + notifyNewTransactions.selectedProperty().addListener((observableValue, oldValue, newValue) -> { + config.setNotifyNewTransactions(newValue); + }); } private void updateCurrencies(ExchangeSource exchangeSource) { diff --git a/src/main/resources/com/sparrowwallet/sparrow/preferences/general.fxml b/src/main/resources/com/sparrowwallet/sparrow/preferences/general.fxml index 0aa0b020..b8c5ff5b 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/preferences/general.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/preferences/general.fxml @@ -68,5 +68,11 @@ +
+ + + + +