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); exportWallet.setDisable(true);
showTxHex.setDisable(false); showTxHex.setDisable(false);
} else if(tabData.getType() == TabData.TabType.WALLET) { } else if(tabData.getType() == TabData.TabType.WALLET) {
WalletTabData walletTabData = (WalletTabData)tabData;
EventManager.get().post(new WalletTabSelectedEvent(selectedTab)); EventManager.get().post(new WalletTabSelectedEvent(selectedTab));
exportWallet.setDisable(false); exportWallet.setDisable(walletTabData.getWallet() == null || !walletTabData.getWallet().isValid());
showTxHex.setDisable(true); showTxHex.setDisable(true);
} }
} }
@ -511,6 +512,11 @@ public class AppController implements Initializable {
} }
} }
@Subscribe
public void walletChanged(WalletChangedEvent event) {
exportWallet.setDisable(!event.getWallet().isValid());
}
@Subscribe @Subscribe
public void timedWorker(TimedEvent event) { public void timedWorker(TimedEvent event) {
if(event.getTimeMills() == 0) { if(event.getTimeMills() == 0) {

View file

@ -62,6 +62,21 @@ public class FileWalletExportPane extends TitledDescriptionPane {
decryptWalletService.setOnSucceeded(workerStateEvent -> { decryptWalletService.setOnSucceeded(workerStateEvent -> {
EventManager.get().post(new StorageEvent(file, TimedEvent.Action.END, "Done")); EventManager.get().post(new StorageEvent(file, TimedEvent.Action.END, "Done"));
Wallet decryptedWallet = decryptWalletService.getValue(); Wallet decryptedWallet = decryptWalletService.getValue();
exportWallet(file, decryptedWallet);
});
decryptWalletService.setOnFailed(workerStateEvent -> {
EventManager.get().post(new StorageEvent(file, TimedEvent.Action.END, "Failed"));
setError("Export Error", decryptWalletService.getException().getMessage());
});
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 { try {
OutputStream outputStream = new FileOutputStream(file); OutputStream outputStream = new FileOutputStream(file);
exporter.exportWallet(decryptedWallet, outputStream); exporter.exportWallet(decryptedWallet, outputStream);
@ -75,14 +90,5 @@ public class FileWalletExportPane extends TitledDescriptionPane {
} finally { } finally {
decryptedWallet.clearPrivate(); decryptedWallet.clearPrivate();
} }
});
decryptWalletService.setOnFailed(workerStateEvent -> {
EventManager.get().post(new StorageEvent(file, TimedEvent.Action.END, "Failed"));
setError("Export Error", decryptWalletService.getException().getMessage());
});
EventManager.get().post(new StorageEvent(file, TimedEvent.Action.START, "Decrypting wallet..."));
decryptWalletService.start();
}
}
} }
} }

View file

@ -43,7 +43,7 @@ public class WalletNameDialog extends Dialog<String> {
Platform.runLater( () -> { Platform.runLater( () -> {
validationSupport.registerValidator(name, Validator.combine( validationSupport.registerValidator(name, Validator.combine(
Validator.createEmptyValidator("Wallet name is required"), 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()); validationSupport.setValidationDecorator(new StyleClassValidationDecoration());
}); });

View file

@ -206,6 +206,13 @@ public class Storage {
return "BIE1".getBytes(StandardCharsets.UTF_8); 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) { public static File getWalletFile(String walletName) {
//TODO: Check for existing file //TODO: Check for existing file
return new File(getWalletsDir(), walletName); return new File(getWalletsDir(), walletName);

View file

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