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

Commit 4479fc3

Browse files
committed
Light-wallet now changes node configuration properly with auth
1 parent 6fa12fb commit 4479fc3

File tree

3 files changed

+72
-9
lines changed

3 files changed

+72
-9
lines changed

app/js/index.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -586,14 +586,14 @@ var UI = (function(UI, undefined) {
586586
var selectedHost;
587587

588588
var select = document.getElementById("server_config_host_select");
589-
var username = "";
590-
var password = "";
589+
var lightWalletUser = "";
590+
var lightWalletPassword = "";
591591
if (select) {
592592
var selectedHost = select.options[select.selectedIndex].value;
593593
if (selectedHost == "custom") {
594594
selectedHost = document.getElementById("server_config_host").value;
595-
username = document.getElementById("light_wallet_user").value;
596-
password = document.getElementById("light_wallet_password").value;
595+
lightWalletUser = document.getElementById("light_wallet_user").value;
596+
lightWalletPassword = document.getElementById("light_wallet_password").value;
597597
}
598598
} else {
599599
selectedHost = document.getElementById("server_config_host").value;
@@ -609,8 +609,14 @@ var UI = (function(UI, undefined) {
609609

610610
config.lightWalletHost = res[1];
611611
config.lightWalletPort = res[2];
612-
config.lightWalletUser = username;
613-
config.lightWalletPassword = password;
612+
613+
if (lightWalletUser !== "") {
614+
config.lightWalletUser = lightWalletUser;
615+
}
616+
if (lightWalletPassword !== "") {
617+
config.lightWalletPassword = lightWalletPassword;
618+
}
619+
614620
config.minWeightMagnitude = parseInt(document.getElementById("server_config_min_weight_magnitude").value, 10);
615621
} else {
616622
config.port = parseInt(document.getElementById("server_config_port").value, 10);

app/js/main.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,6 +2125,11 @@ var App = (function(App, undefined) {
21252125
settings.lightWalletUser = lightWalletUser;
21262126
lightWalletHostChange = true;
21272127
}
2128+
} else {
2129+
if (settings.hasOwnProperty("lightWalletUser")) {
2130+
delete settings["lightWalletUser"]
2131+
lightWalletHostChange = true;
2132+
}
21282133
}
21292134

21302135
if (configuration.hasOwnProperty("lightWalletPassword")) {
@@ -2133,6 +2138,11 @@ var App = (function(App, undefined) {
21332138
settings.lightWalletPassword = lightWalletPassword;
21342139
lightWalletHostChange = true;
21352140
}
2141+
} else {
2142+
if (settings.hasOwnProperty("lightWalletPassword")) {
2143+
delete settings["lightWalletPassword"]
2144+
lightWalletHostChange = true;
2145+
}
21362146
}
21372147
} else {
21382148
if (configuration.hasOwnProperty("nodes")) {
@@ -2221,10 +2231,16 @@ var App = (function(App, undefined) {
22212231
if (relaunch || !App.windowIsReady()) {
22222232
App.relaunchApplication();
22232233
} else if (lightWalletHostChange && settings.lightWallet == 1) {
2224-
win.webContents.send("updateSettings", {
2234+
var updatedSettings = {
22252235
"host": settings.lightWalletHost,
22262236
"port": settings.lightWalletPort
2227-
});
2237+
};
2238+
if(settings.lightWalletUser) {
2239+
updatedSettings.lightWalletUser = settings.lightWalletUser;
2240+
updatedSettings.lightWalletPassword = settings.lightWalletPassword;
2241+
}
2242+
2243+
win.webContents.send("updateSettings", updatedSettings);
22282244
} else {
22292245
win.webContents.send("updateSettings", {
22302246
"depth": settings.depth,

ui/js/ui.utils.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ var UI = (function(UI, $, undefined) {
247247
}
248248

249249
var changeNode = false;
250+
var hasAuth = false;
250251

251252
if (settings.hasOwnProperty("host") && settings.host != connection.host) {
252253
connection.host = settings.host;
@@ -257,8 +258,48 @@ var UI = (function(UI, $, undefined) {
257258
changeNode = true;
258259
}
259260

261+
if (settings.hasOwnProperty("lightWalletUser")) {
262+
hasAuth = true;
263+
264+
if (settings.lightWalletUser != connection.lightWalletUser) {
265+
connection.lightWalletUser = settings.lightWalletUser;
266+
changeNode = true;
267+
}
268+
} else {
269+
if(connection.hasOwnProperty("lightWalletUser")) {
270+
delete connection["lightWalletUser"]
271+
changeNode = true;
272+
}
273+
}
274+
275+
if (settings.hasOwnProperty("lightWalletPassword")) {
276+
hasAuth = true;
277+
if (settings.lightWalletPassword != connection.lightWalletPassword) {
278+
connection.lightWalletPassword = settings.lightWalletPassword;
279+
changeNode = true;
280+
}
281+
} else {
282+
if(connection.hasOwnProperty("lightWalletPassword")) {
283+
delete connection["lightWalletPassword"]
284+
changeNode = true;
285+
}
286+
}
287+
260288
if (changeNode) {
261-
iota.changeNode({"host": connection.host, "port": connection.port});
289+
var nodeSettings = {
290+
"host": connection.host,
291+
"port": connection.port,
292+
};
293+
294+
if (hasAuth) {
295+
nodeSettings.auth = {
296+
"type": "basic",
297+
"user": connection.lightWalletUser,
298+
"password": connection.lightWalletPassword
299+
};
300+
}
301+
302+
iota.changeNode(nodeSettings);
262303

263304
if (localAttachToTangle) {
264305
iota.api.attachToTangle = localAttachToTangle;

0 commit comments

Comments
 (0)