Skip to content
This repository has been archived by the owner on Feb 26, 2021. It is now read-only.

Commit

Permalink
Light-wallet now changes node configuration properly with auth
Browse files Browse the repository at this point in the history
  • Loading branch information
bmavity committed Jul 10, 2017
1 parent 6fa12fb commit 4479fc3
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 9 deletions.
18 changes: 12 additions & 6 deletions app/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
20 changes: 18 additions & 2 deletions app/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand All @@ -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")) {
Expand Down Expand Up @@ -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,
Expand Down
43 changes: 42 additions & 1 deletion ui/js/ui.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 4479fc3

Please sign in to comment.