mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
exporting fixes
This commit is contained in:
parent
7fc0e9b530
commit
6f2a0cd3c3
6 changed files with 36 additions and 15 deletions
BIN
.DS_Store
vendored
BIN
.DS_Store
vendored
Binary file not shown.
|
@ -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) {
|
||||||
|
|
|
@ -62,19 +62,7 @@ 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();
|
||||||
try {
|
exportWallet(file, decryptedWallet);
|
||||||
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();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
decryptWalletService.setOnFailed(workerStateEvent -> {
|
decryptWalletService.setOnFailed(workerStateEvent -> {
|
||||||
EventManager.get().post(new StorageEvent(file, TimedEvent.Action.END, "Failed"));
|
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..."));
|
EventManager.get().post(new StorageEvent(file, TimedEvent.Action.START, "Decrypting wallet..."));
|
||||||
decryptWalletService.start();
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
||||||
});
|
});
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in a new issue