From 9700944b7f67dc3f0d6b9de4994250f27dfe5066 Mon Sep 17 00:00:00 2001
From: Jacob Brydolf <jacob@brydolf.net>
Date: Wed, 5 Oct 2016 00:18:50 +0200
Subject: [PATCH] close wallet before reopen

---
 main.qml | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/main.qml b/main.qml
index 82f5c17f..d6d45409 100644
--- a/main.qml
+++ b/main.qml
@@ -139,11 +139,19 @@ ApplicationWindow {
         middlePanel.paymentClicked.connect(handlePayment);
         // basicPanel.paymentClicked.connect(handlePayment);
 
+        // currentWallet is defined on daemon address change - close/reopen
+        if (currentWallet !== undefined) {
+            console.log("closing currentWallet")
+            walletManager.closeWallet(currentWallet);
+        }
 
         // wallet already opened with wizard, we just need to initialize it
         if (typeof wizard.settings['wallet'] !== 'undefined') {
+            console.log("using wizard wallet")
             connectWallet(wizard.settings['wallet'])
             isNewWallet = true
+            // We don't need the wizard wallet any more - delete to avoid conflict with daemon adress change
+            delete wizard.settings['wallet']
         }  else {
             var wallet_path = walletPath();
             // console.log("opening wallet at: ", wallet_path, "with password: ", appWindow.password);