diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index 981d2a8e..09c14972 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -961,6 +961,10 @@ public class AppController implements Initializable { walletFile.delete(); } + if(wallet.isEncrypted()) { + throw new IllegalArgumentException("Imported wallet must be unencrypted"); + } + Storage storage = new Storage(Storage.getWalletFile(wallet.getName())); WalletPasswordDialog dlg = new WalletPasswordDialog(wallet.getName(), WalletPasswordDialog.PasswordRequirement.UPDATE_NEW); Optional password = dlg.showAndWait(); @@ -969,8 +973,10 @@ public class AppController implements Initializable { try { storage.setEncryptionPubKey(Storage.NO_PASSWORD_KEY); storage.saveWallet(wallet); + checkWalletNetwork(wallet); + restorePublicKeysFromSeed(wallet, null); addWalletTabOrWindow(storage, wallet, null, false); - } catch(IOException | StorageException e) { + } catch(IOException | StorageException | MnemonicException e) { log.error("Error saving imported wallet", e); } } else { @@ -986,8 +992,10 @@ public class AppController implements Initializable { wallet.encrypt(key); storage.setEncryptionPubKey(encryptionPubKey); storage.saveWallet(wallet); + checkWalletNetwork(wallet); + restorePublicKeysFromSeed(wallet, key); addWalletTabOrWindow(storage, wallet, null, false); - } catch(IOException | StorageException e) { + } catch(IOException | StorageException | MnemonicException e) { log.error("Error saving imported wallet", e); } finally { encryptionFullKey.clear(); diff --git a/src/main/java/com/sparrowwallet/sparrow/control/TitledDescriptionPane.java b/src/main/java/com/sparrowwallet/sparrow/control/TitledDescriptionPane.java index c245a8c2..7cd41edd 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/TitledDescriptionPane.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/TitledDescriptionPane.java @@ -16,6 +16,7 @@ import java.util.Arrays; import java.util.OptionalDouble; public class TitledDescriptionPane extends TitledPane { + private Label mainLabel; private Label descriptionLabel; protected Hyperlink showHideLink; protected HBox buttonBox; @@ -50,7 +51,7 @@ public class TitledDescriptionPane extends TitledPane { VBox labelsBox = new VBox(); labelsBox.setSpacing(5); labelsBox.setAlignment(Pos.CENTER_LEFT); - Label mainLabel = new Label(); + mainLabel = new Label(); mainLabel.setText(title); mainLabel.getStyleClass().add("main-label"); labelsBox.getChildren().add(mainLabel); @@ -99,6 +100,10 @@ public class TitledDescriptionPane extends TitledPane { return null; } + public String getTitle() { + return mainLabel.getText(); + } + protected void setDescription(String text) { descriptionLabel.getStyleClass().remove("description-error"); descriptionLabel.getStyleClass().add("description-label"); diff --git a/src/main/java/com/sparrowwallet/sparrow/control/WalletExportDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/WalletExportDialog.java index aea52bf5..cf930cf0 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/WalletExportDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/WalletExportDialog.java @@ -11,6 +11,7 @@ import javafx.scene.control.*; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.StackPane; +import java.util.Comparator; import java.util.List; public class WalletExportDialog extends Dialog { @@ -53,6 +54,8 @@ public class WalletExportDialog extends Dialog { FileWalletExportPane exportPane = new FileWalletExportPane(wallet, exporter); exportAccordion.getPanes().add(exportPane); } + + exportAccordion.getPanes().sort(Comparator.comparing(o -> ((TitledDescriptionPane) o).getTitle())); scrollPane.setContent(exportAccordion); final ButtonType cancelButtonType = new javafx.scene.control.ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE); diff --git a/src/main/java/com/sparrowwallet/sparrow/control/WalletImportDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/WalletImportDialog.java index 1a384509..45242e32 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/WalletImportDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/WalletImportDialog.java @@ -16,6 +16,7 @@ import javafx.scene.layout.AnchorPane; import javafx.scene.layout.StackPane; import org.controlsfx.glyphfont.Glyph; +import java.util.Comparator; import java.util.List; public class WalletImportDialog extends Dialog { @@ -58,6 +59,8 @@ public class WalletImportDialog extends Dialog { FileWalletImportPane importPane = new FileWalletImportPane(importer); importAccordion.getPanes().add(importPane); } + + importAccordion.getPanes().sort(Comparator.comparing(o -> ((TitledDescriptionPane) o).getTitle())); scrollPane.setContent(importAccordion); final ButtonType cancelButtonType = new javafx.scene.control.ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE); diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Sparrow.java b/src/main/java/com/sparrowwallet/sparrow/io/Sparrow.java index 8ad0342c..a28a06db 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Sparrow.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Sparrow.java @@ -91,7 +91,9 @@ public class Sparrow implements WalletImport, WalletExport { if(!isEncrypted(tempFile)) { return storage.loadUnencryptedWallet().getWallet(); } else { - return storage.loadEncryptedWallet(password).getWallet(); + WalletBackupAndKey walletBackupAndKey = storage.loadEncryptedWallet(password); + walletBackupAndKey.getWallet().decrypt(walletBackupAndKey.getKey()); + return walletBackupAndKey.getWallet(); } } catch(IOException | StorageException e) { log.error("Error importing Sparrow wallet", e); diff --git a/src/main/java/com/sparrowwallet/sparrow/io/db/DbPersistence.java b/src/main/java/com/sparrowwallet/sparrow/io/db/DbPersistence.java index 624f8df5..7aa6a214 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/db/DbPersistence.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/db/DbPersistence.java @@ -555,7 +555,7 @@ public class DbPersistence implements Persistence { log.error("Wallet file may already be in use. Make sure the application is not running elsewhere.", e); throw new StorageException("Wallet file may already be in use. Make sure the application is not running elsewhere.", e); } else if(e.getMessage() != null && (e.getMessage().contains("Wrong user name or password") || e.getMessage().contains("Encryption error in file"))) { - throw new InvalidPasswordException("Incorrect password for wallet file.", e); + throw new InvalidPasswordException("Incorrect password for wallet file " + walletFile.getAbsolutePath(), e); } else { log.error("Failed to open database file", e); throw new StorageException("Failed to open database file.\n" + e.getMessage(), e); diff --git a/src/main/java/com/sparrowwallet/sparrow/keystoreimport/HwAirgappedController.java b/src/main/java/com/sparrowwallet/sparrow/keystoreimport/HwAirgappedController.java index 3d8cfb4a..ca540a21 100644 --- a/src/main/java/com/sparrowwallet/sparrow/keystoreimport/HwAirgappedController.java +++ b/src/main/java/com/sparrowwallet/sparrow/keystoreimport/HwAirgappedController.java @@ -2,11 +2,13 @@ package com.sparrowwallet.sparrow.keystoreimport; import com.sparrowwallet.drongo.policy.PolicyType; import com.sparrowwallet.sparrow.control.FileKeystoreImportPane; +import com.sparrowwallet.sparrow.control.TitledDescriptionPane; import com.sparrowwallet.sparrow.io.*; import javafx.fxml.FXML; import javafx.scene.control.Accordion; import java.util.Collections; +import java.util.Comparator; import java.util.List; public class HwAirgappedController extends KeystoreImportDetailController { @@ -25,5 +27,7 @@ public class HwAirgappedController extends KeystoreImportDetailController { FileKeystoreImportPane importPane = new FileKeystoreImportPane(getMasterController().getWallet(), (KeystoreFileImport)importer);; importAccordion.getPanes().add(importPane); } + + importAccordion.getPanes().sort(Comparator.comparing(o -> ((TitledDescriptionPane) o).getTitle())); } }