diff --git a/src/main/java/com/sparrowwallet/sparrow/AppServices.java b/src/main/java/com/sparrowwallet/sparrow/AppServices.java index 5cba587e..ba7cf781 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppServices.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppServices.java @@ -24,6 +24,7 @@ import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Alert; +import javafx.scene.control.ButtonType; import javafx.scene.image.Image; import javafx.scene.text.Font; import javafx.stage.Stage; @@ -357,14 +358,21 @@ public class AppServices { payjoinURIs.put(bitcoinURI.getAddress(), bitcoinURI); } - public static void showErrorDialog(String title, String content) { - Alert alert = new Alert(Alert.AlertType.ERROR); + public static Optional showWarningDialog(String title, String content, ButtonType... buttons) { + return showAlertDialog(title, content, Alert.AlertType.WARNING, buttons); + } + + public static Optional showErrorDialog(String title, String content, ButtonType... buttons) { + return showAlertDialog(title, content, Alert.AlertType.ERROR, buttons); + } + + public static Optional showAlertDialog(String title, String content, Alert.AlertType alertType, ButtonType... buttons) { + Alert alert = new Alert(alertType, content, buttons); setStageIcon(alert.getDialogPane().getScene().getWindow()); alert.getDialogPane().getScene().getStylesheets().add(AppServices.class.getResource("general.css").toExternalForm()); alert.setTitle(title); alert.setHeaderText(title); - alert.setContentText(content); - alert.showAndWait(); + return alert.showAndWait(); } public static void setStageIcon(Window window) { diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java index 906c3d86..6ef1130e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java @@ -355,6 +355,15 @@ public class SettingsController extends WalletFormController implements Initiali requirement = WalletPasswordDialog.PasswordRequirement.UPDATE_SET; } + if(!changePassword && ((SettingsWalletForm)walletForm).isAddressChange() && !walletForm.getWallet().getTransactions().isEmpty()) { + Optional optResponse = AppServices.showWarningDialog("Change Wallet Addresses?", "This wallet has existing transactions which will be replaced as the wallet addresses will change. Ok to proceed?", ButtonType.CANCEL, ButtonType.OK); + if(optResponse.isPresent() && optResponse.get().equals(ButtonType.CANCEL)) { + revert.setDisable(false); + apply.setDisable(false); + return; + } + } + WalletPasswordDialog dlg = new WalletPasswordDialog(requirement); Optional password = dlg.showAndWait(); if(password.isPresent()) { diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsWalletForm.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsWalletForm.java index aeafb55d..17e07718 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsWalletForm.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsWalletForm.java @@ -56,6 +56,26 @@ public class SettingsWalletForm extends WalletForm { return true; } + if(isAddressChange(original, changed)) { + return true; + } + + if(original.getGapLimit() != changed.getGapLimit()) { + return true; + } + + if(!Objects.equals(original.getBirthDate(), changed.getBirthDate())) { + return true; + } + + return false; + } + + protected boolean isAddressChange() { + return isAddressChange(wallet, walletCopy); + } + + private boolean isAddressChange(Wallet original, Wallet changed) { if(original.getPolicyType() != changed.getPolicyType()) { return true; } @@ -74,23 +94,15 @@ public class SettingsWalletForm extends WalletForm { Keystore originalKeystore = original.getKeystores().get(i); Keystore changedKeystore = changed.getKeystores().get(i); - if(!originalKeystore.getKeyDerivation().equals(changedKeystore.getKeyDerivation())) { + if(!Objects.equals(originalKeystore.getKeyDerivation(), changedKeystore.getKeyDerivation())) { return true; } - if(!originalKeystore.getExtendedPublicKey().equals(changedKeystore.getExtendedPublicKey())) { + if(!Objects.equals(originalKeystore.getExtendedPublicKey(), changedKeystore.getExtendedPublicKey())) { return true; } } - if(original.getGapLimit() != changed.getGapLimit()) { - return true; - } - - if(!Objects.equals(original.getBirthDate(), changed.getBirthDate())) { - return true; - } - return false; } }