From 4479fc3fbdd52d3c45d9f51b74c2230be966b7ed Mon Sep 17 00:00:00 2001 From: bmavity Date: Sat, 8 Jul 2017 16:59:31 -0500 Subject: [PATCH] Light-wallet now changes node configuration properly with auth --- app/js/index.js | 18 ++++++++++++------ app/js/main.js | 20 ++++++++++++++++++-- ui/js/ui.utils.js | 43 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 72 insertions(+), 9 deletions(-) diff --git a/app/js/index.js b/app/js/index.js index fcb20b7f..e93d8d51 100644 --- a/app/js/index.js +++ b/app/js/index.js @@ -586,14 +586,14 @@ var UI = (function(UI, undefined) { var selectedHost; var select = document.getElementById("server_config_host_select"); - var username = ""; - var password = ""; + var lightWalletUser = ""; + var lightWalletPassword = ""; if (select) { var selectedHost = select.options[select.selectedIndex].value; if (selectedHost == "custom") { selectedHost = document.getElementById("server_config_host").value; - username = document.getElementById("light_wallet_user").value; - password = document.getElementById("light_wallet_password").value; + lightWalletUser = document.getElementById("light_wallet_user").value; + lightWalletPassword = document.getElementById("light_wallet_password").value; } } else { selectedHost = document.getElementById("server_config_host").value; @@ -609,8 +609,14 @@ var UI = (function(UI, undefined) { config.lightWalletHost = res[1]; config.lightWalletPort = res[2]; - config.lightWalletUser = username; - config.lightWalletPassword = password; + + if (lightWalletUser !== "") { + config.lightWalletUser = lightWalletUser; + } + if (lightWalletPassword !== "") { + config.lightWalletPassword = lightWalletPassword; + } + config.minWeightMagnitude = parseInt(document.getElementById("server_config_min_weight_magnitude").value, 10); } else { config.port = parseInt(document.getElementById("server_config_port").value, 10); diff --git a/app/js/main.js b/app/js/main.js index bb77f257..9913318b 100644 --- a/app/js/main.js +++ b/app/js/main.js @@ -2125,6 +2125,11 @@ var App = (function(App, undefined) { settings.lightWalletUser = lightWalletUser; lightWalletHostChange = true; } + } else { + if (settings.hasOwnProperty("lightWalletUser")) { + delete settings["lightWalletUser"] + lightWalletHostChange = true; + } } if (configuration.hasOwnProperty("lightWalletPassword")) { @@ -2133,6 +2138,11 @@ var App = (function(App, undefined) { settings.lightWalletPassword = lightWalletPassword; lightWalletHostChange = true; } + } else { + if (settings.hasOwnProperty("lightWalletPassword")) { + delete settings["lightWalletPassword"] + lightWalletHostChange = true; + } } } else { if (configuration.hasOwnProperty("nodes")) { @@ -2221,10 +2231,16 @@ var App = (function(App, undefined) { if (relaunch || !App.windowIsReady()) { App.relaunchApplication(); } else if (lightWalletHostChange && settings.lightWallet == 1) { - win.webContents.send("updateSettings", { + var updatedSettings = { "host": settings.lightWalletHost, "port": settings.lightWalletPort - }); + }; + if(settings.lightWalletUser) { + updatedSettings.lightWalletUser = settings.lightWalletUser; + updatedSettings.lightWalletPassword = settings.lightWalletPassword; + } + + win.webContents.send("updateSettings", updatedSettings); } else { win.webContents.send("updateSettings", { "depth": settings.depth, diff --git a/ui/js/ui.utils.js b/ui/js/ui.utils.js index eb225427..ebcb2fe0 100644 --- a/ui/js/ui.utils.js +++ b/ui/js/ui.utils.js @@ -247,6 +247,7 @@ var UI = (function(UI, $, undefined) { } var changeNode = false; + var hasAuth = false; if (settings.hasOwnProperty("host") && settings.host != connection.host) { connection.host = settings.host; @@ -257,8 +258,48 @@ var UI = (function(UI, $, undefined) { changeNode = true; } + if (settings.hasOwnProperty("lightWalletUser")) { + hasAuth = true; + + if (settings.lightWalletUser != connection.lightWalletUser) { + connection.lightWalletUser = settings.lightWalletUser; + changeNode = true; + } + } else { + if(connection.hasOwnProperty("lightWalletUser")) { + delete connection["lightWalletUser"] + changeNode = true; + } + } + + if (settings.hasOwnProperty("lightWalletPassword")) { + hasAuth = true; + if (settings.lightWalletPassword != connection.lightWalletPassword) { + connection.lightWalletPassword = settings.lightWalletPassword; + changeNode = true; + } + } else { + if(connection.hasOwnProperty("lightWalletPassword")) { + delete connection["lightWalletPassword"] + changeNode = true; + } + } + if (changeNode) { - iota.changeNode({"host": connection.host, "port": connection.port}); + var nodeSettings = { + "host": connection.host, + "port": connection.port, + }; + + if (hasAuth) { + nodeSettings.auth = { + "type": "basic", + "user": connection.lightWalletUser, + "password": connection.lightWalletPassword + }; + } + + iota.changeNode(nodeSettings); if (localAttachToTangle) { iota.api.attachToTangle = localAttachToTangle;