exporting fixes

This commit is contained in:
Craig Raw 2020-05-21 16:10:07 +02:00
parent 7fc0e9b530
commit 6f2a0cd3c3
6 changed files with 36 additions and 15 deletions

BIN
.DS_Store vendored

Binary file not shown.

View file

@ -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) {

View file

@ -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();
}
}
}

View file

@ -43,7 +43,7 @@ public class WalletNameDialog extends Dialog<String> {
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());
});

View file

@ -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);

View file

@ -21,8 +21,10 @@
<MenuItem text="Examples" onAction="#openExamples"/>
</items>
</Menu>
<SeparatorMenuItem />
<MenuItem mnemonicParsing="false" text="Import Wallet..." onAction="#importWallet"/>
<MenuItem fx:id="exportWallet" mnemonicParsing="false" text="Export Wallet..." onAction="#exportWallet"/>
<SeparatorMenuItem />
<MenuItem mnemonicParsing="false" text="Close" onAction="#closeTab"/>
</items>
</Menu>