show warning before changing a wallet with transactions

This commit is contained in:
Craig Raw 2021-01-12 10:15:42 +02:00
parent 826162ba9f
commit 99959470e2
3 changed files with 43 additions and 14 deletions

View file

@ -24,6 +24,7 @@ import javafx.fxml.FXMLLoader;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.text.Font; import javafx.scene.text.Font;
import javafx.stage.Stage; import javafx.stage.Stage;
@ -357,14 +358,21 @@ public class AppServices {
payjoinURIs.put(bitcoinURI.getAddress(), bitcoinURI); payjoinURIs.put(bitcoinURI.getAddress(), bitcoinURI);
} }
public static void showErrorDialog(String title, String content) { public static Optional<ButtonType> showWarningDialog(String title, String content, ButtonType... buttons) {
Alert alert = new Alert(Alert.AlertType.ERROR); return showAlertDialog(title, content, Alert.AlertType.WARNING, buttons);
}
public static Optional<ButtonType> showErrorDialog(String title, String content, ButtonType... buttons) {
return showAlertDialog(title, content, Alert.AlertType.ERROR, buttons);
}
public static Optional<ButtonType> showAlertDialog(String title, String content, Alert.AlertType alertType, ButtonType... buttons) {
Alert alert = new Alert(alertType, content, buttons);
setStageIcon(alert.getDialogPane().getScene().getWindow()); setStageIcon(alert.getDialogPane().getScene().getWindow());
alert.getDialogPane().getScene().getStylesheets().add(AppServices.class.getResource("general.css").toExternalForm()); alert.getDialogPane().getScene().getStylesheets().add(AppServices.class.getResource("general.css").toExternalForm());
alert.setTitle(title); alert.setTitle(title);
alert.setHeaderText(title); alert.setHeaderText(title);
alert.setContentText(content); return alert.showAndWait();
alert.showAndWait();
} }
public static void setStageIcon(Window window) { public static void setStageIcon(Window window) {

View file

@ -355,6 +355,15 @@ public class SettingsController extends WalletFormController implements Initiali
requirement = WalletPasswordDialog.PasswordRequirement.UPDATE_SET; requirement = WalletPasswordDialog.PasswordRequirement.UPDATE_SET;
} }
if(!changePassword && ((SettingsWalletForm)walletForm).isAddressChange() && !walletForm.getWallet().getTransactions().isEmpty()) {
Optional<ButtonType> 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); WalletPasswordDialog dlg = new WalletPasswordDialog(requirement);
Optional<SecureString> password = dlg.showAndWait(); Optional<SecureString> password = dlg.showAndWait();
if(password.isPresent()) { if(password.isPresent()) {

View file

@ -56,6 +56,26 @@ public class SettingsWalletForm extends WalletForm {
return true; 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()) { if(original.getPolicyType() != changed.getPolicyType()) {
return true; return true;
} }
@ -74,23 +94,15 @@ public class SettingsWalletForm extends WalletForm {
Keystore originalKeystore = original.getKeystores().get(i); Keystore originalKeystore = original.getKeystores().get(i);
Keystore changedKeystore = changed.getKeystores().get(i); Keystore changedKeystore = changed.getKeystores().get(i);
if(!originalKeystore.getKeyDerivation().equals(changedKeystore.getKeyDerivation())) { if(!Objects.equals(originalKeystore.getKeyDerivation(), changedKeystore.getKeyDerivation())) {
return true; return true;
} }
if(!originalKeystore.getExtendedPublicKey().equals(changedKeystore.getExtendedPublicKey())) { if(!Objects.equals(originalKeystore.getExtendedPublicKey(), changedKeystore.getExtendedPublicKey())) {
return true; return true;
} }
} }
if(original.getGapLimit() != changed.getGapLimit()) {
return true;
}
if(!Objects.equals(original.getBirthDate(), changed.getBirthDate())) {
return true;
}
return false; return false;
} }
} }