From 771bd1545c34062c1226238daf8e0c2369fa5218 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Thu, 1 Apr 2021 12:41:27 +0200 Subject: [PATCH] fix export of sparrow wallet from settings screen --- .../sparrow/wallet/SettingsController.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java index 604e7faa..61f6281c 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java @@ -316,8 +316,17 @@ public class SettingsController extends WalletFormController implements Initiali } public void exportWallet(ActionEvent event) { - WalletExportDialog dlg = new WalletExportDialog(walletForm.getWallet()); - dlg.showAndWait(); + if(walletForm.getWalletFile() == null) { + throw new IllegalStateException("Cannot export unsaved wallet"); + } + + Optional optWallet = AppServices.get().getOpenWallets().entrySet().stream().filter(entry -> walletForm.getWalletFile().equals(entry.getValue().getWalletFile())).map(Map.Entry::getKey).findFirst(); + if(optWallet.isPresent()) { + WalletExportDialog dlg = new WalletExportDialog(optWallet.get()); + dlg.showAndWait(); + } else { + AppServices.showErrorDialog("Cannot export wallet", "Wallet cannot be exported, please save it first."); + } } @Override