diff --git a/.DS_Store b/.DS_Store index cae61d60..650b9d96 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index 14246546..02b400aa 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -109,8 +109,9 @@ public class AppController implements Initializable { exportWallet.setDisable(true); showTxHex.setDisable(false); } else if(tabData.getType() == TabData.TabType.WALLET) { + WalletTabData walletTabData = (WalletTabData)tabData; EventManager.get().post(new WalletTabSelectedEvent(selectedTab)); - exportWallet.setDisable(false); + exportWallet.setDisable(walletTabData.getWallet() == null || !walletTabData.getWallet().isValid()); showTxHex.setDisable(true); } } @@ -511,6 +512,11 @@ public class AppController implements Initializable { } } + @Subscribe + public void walletChanged(WalletChangedEvent event) { + exportWallet.setDisable(!event.getWallet().isValid()); + } + @Subscribe public void timedWorker(TimedEvent event) { if(event.getTimeMills() == 0) { diff --git a/src/main/java/com/sparrowwallet/sparrow/control/FileWalletExportPane.java b/src/main/java/com/sparrowwallet/sparrow/control/FileWalletExportPane.java index 182db16e..26e8f5f7 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/FileWalletExportPane.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/FileWalletExportPane.java @@ -62,19 +62,7 @@ public class FileWalletExportPane extends TitledDescriptionPane { decryptWalletService.setOnSucceeded(workerStateEvent -> { EventManager.get().post(new StorageEvent(file, TimedEvent.Action.END, "Done")); Wallet decryptedWallet = decryptWalletService.getValue(); - try { - OutputStream outputStream = new FileOutputStream(file); - exporter.exportWallet(decryptedWallet, outputStream); - EventManager.get().post(new WalletExportEvent(decryptedWallet)); - } catch(Exception e) { - String errorMessage = e.getMessage(); - if(e.getCause() != null && e.getCause().getMessage() != null && !e.getCause().getMessage().isEmpty()) { - errorMessage = e.getCause().getMessage(); - } - setError("Export Error", errorMessage); - } finally { - decryptedWallet.clearPrivate(); - } + exportWallet(file, decryptedWallet); }); decryptWalletService.setOnFailed(workerStateEvent -> { EventManager.get().post(new StorageEvent(file, TimedEvent.Action.END, "Failed")); @@ -83,6 +71,24 @@ public class FileWalletExportPane extends TitledDescriptionPane { EventManager.get().post(new StorageEvent(file, TimedEvent.Action.START, "Decrypting wallet...")); decryptWalletService.start(); } + } else { + exportWallet(file, copy); + } + } + + private void exportWallet(File file, Wallet decryptedWallet) { + try { + OutputStream outputStream = new FileOutputStream(file); + exporter.exportWallet(decryptedWallet, outputStream); + EventManager.get().post(new WalletExportEvent(decryptedWallet)); + } catch(Exception e) { + String errorMessage = e.getMessage(); + if(e.getCause() != null && e.getCause().getMessage() != null && !e.getCause().getMessage().isEmpty()) { + errorMessage = e.getCause().getMessage(); + } + setError("Export Error", errorMessage); + } finally { + decryptedWallet.clearPrivate(); } } } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/WalletNameDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/WalletNameDialog.java index d78fe77e..69ad3d9f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/WalletNameDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/WalletNameDialog.java @@ -43,7 +43,7 @@ public class WalletNameDialog extends Dialog { Platform.runLater( () -> { validationSupport.registerValidator(name, Validator.combine( Validator.createEmptyValidator("Wallet name is required"), - (Control c, String newValue) -> ValidationResult.fromErrorIf( c, "Wallet name is not unique", Storage.getWalletFile(newValue).exists()) + (Control c, String newValue) -> ValidationResult.fromErrorIf( c, "Wallet name is not unique", Storage.walletExists(newValue)) )); validationSupport.setValidationDecorator(new StyleClassValidationDecoration()); }); diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Storage.java b/src/main/java/com/sparrowwallet/sparrow/io/Storage.java index 581d8896..8e1e558b 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Storage.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Storage.java @@ -206,6 +206,13 @@ public class Storage { return "BIE1".getBytes(StandardCharsets.UTF_8); } + public static boolean walletExists(String walletName) { + File encrypted = new File(getWalletsDir(), walletName); + File unencrypted = new File(getWalletsDir(), walletName + ".json"); + + return (encrypted.exists() || unencrypted.exists()); + } + public static File getWalletFile(String walletName) { //TODO: Check for existing file return new File(getWalletsDir(), walletName); diff --git a/src/main/resources/com/sparrowwallet/sparrow/app.fxml b/src/main/resources/com/sparrowwallet/sparrow/app.fxml index de7b1f4c..4e16dab6 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/app.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/app.fxml @@ -21,8 +21,10 @@ + +