Skip to content

Commit

Permalink
Update main.qml
Browse files Browse the repository at this point in the history
  • Loading branch information
rating89us authored Jan 15, 2022
1 parent 7dcb540 commit 1375ee4
Showing 1 changed file with 90 additions and 1 deletion.
91 changes: 90 additions & 1 deletion main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,46 @@ ApplicationWindow {

if (persistentSettings.useRemoteNode) {
const remoteNode = remoteNodesModel.currentRemoteNode();
var firstRemoteNodeAvailable = remoteNodesModel.findFirstRemoteNodeAvailable(persistentSettings.nettype)
if (!remoteNodesModel.currentRemoteNode()) {
remoteNodesModel.applyRemoteNode(firstRemoteNodeAvailable)
} else {
if (!remoteNodesModel.currentRemoteNode().networkType) {
//backward compatibility with previous remote nodes that don't have networkType set
if (persistentSettings.nettype != 0) {
if (persistentSettings.nettype == 1) {
if (remoteNodesModel.lastTestnetNodeSelected == -1) {
remoteNodesModel.lastTestnetNodeSelected = firstRemoteNodeAvailable
}
remoteNodesModel.applyRemoteNode(remoteNodesModel.lastTestnetNodeSelected)
} else if (persistentSettings.nettype == 2) {
if (remoteNodesModel.lastStagenetNodeSelected == -1) {
remoteNodesModel.lastStagenetNodeSelected = firstRemoteNodeAvailable
}
remoteNodesModel.applyRemoteNode(remoteNodesModel.lastStagenetNodeSelected)
}
}
} else {
if (remoteNodesModel.currentRemoteNode().networkType != persistentSettings.nettype) {
if (persistentSettings.nettype == 0) {
if (remoteNodesModel.lastMainnetNodeSelected == -1) {
remoteNodesModel.lastMainnetNodeSelected = firstRemoteNodeAvailable
}
remoteNodesModel.applyRemoteNode(remoteNodesModel.lastMainnetNodeSelected)
} else if (persistentSettings.nettype == 1) {
if (remoteNodesModel.lastTestnetNodeSelected == -1) {
remoteNodesModel.lastTestnetNodeSelected = firstRemoteNodeAvailable
}
remoteNodesModel.applyRemoteNode(remoteNodesModel.lastTestnetNodeSelected)
} else if (persistentSettings.nettype == 2) {
if (remoteNodesModel.lastStagenetNodeSelected == -1) {
remoteNodesModel.lastStagenetNodeSelected = firstRemoteNodeAvailable
}
remoteNodesModel.applyRemoteNode(remoteNodesModel.lastStagenetNodeSelected)
}
}
}
}
currentDaemonAddress = remoteNode.address;
currentWallet.setDaemonLogin(remoteNode.username, remoteNode.password);
} else {
Expand Down Expand Up @@ -1455,6 +1495,9 @@ ApplicationWindow {
id: remoteNodesModel

property int selected: 0
property int lastMainnetNodeSelected: -1
property int lastTestnetNodeSelected: -1
property int lastStagenetNodeSelected: -1

signal store()

Expand All @@ -1466,6 +1509,9 @@ ApplicationWindow {
remoteNodesModel.append(remoteNode);
}
selected = remoteNodes.selected % remoteNodesModel.count || 0;
lastMainnetNodeSelected = remoteNodes.lastMainnetNodeSelected;
lastTestnetNodeSelected = remoteNodes.lastTestnetNodeSelected;
lastStagenetNodeSelected = remoteNodes.lastStagenetNodeSelected;
} catch (e) {
console.error('failed to parse remoteNodesSerialized', e);
}
Expand All @@ -1477,6 +1523,9 @@ ApplicationWindow {
}
persistentSettings.remoteNodesSerialized = JSON.stringify({
selected: selected,
lastMainnetNodeSelected: lastMainnetNodeSelected,
lastTestnetNodeSelected: lastTestnetNodeSelected,
lastStagenetNodeSelected: lastStagenetNodeSelected,
nodes: remoteNodes
});
});
Expand All @@ -1485,7 +1534,9 @@ ApplicationWindow {
function appendIfNotExists(newRemoteNode) {
for (var index = 0; index < remoteNodesModel.count; ++index) {
const remoteNode = remoteNodesModel.get(index);
if (remoteNode.address == newRemoteNode.address &&
if (remoteNode.label == newRemoteNode.label &&
remoteNode.networkType == newRemoteNode.networkType &&
remoteNode.address == newRemoteNode.address &&
remoteNode.username == newRemoteNode.username &&
remoteNode.password == newRemoteNode.password &&
remoteNode.trusted == newRemoteNode.trusted) {
Expand All @@ -1505,13 +1556,22 @@ ApplicationWindow {
currentWallet.setTrustedDaemon(remoteNode.trusted);
appWindow.connectRemoteNode();
}
if (persistentSettings.nettype == 0) {
remoteNodesModel.lastMainnetNodeSelected = selected;
} else if (persistentSettings.nettype == 1) {
remoteNodesModel.lastTestnetNodeSelected = selected;
} else if (persistentSettings.nettype == 2) {
remoteNodesModel.lastStagenetNodeSelected = selected;
}
}

function currentRemoteNode() {
if (selected < remoteNodesModel.count) {
return remoteNodesModel.get(selected);
}
return {
label: "",
networkType: "",
address: "",
username: "",
password: "",
Expand All @@ -1521,13 +1581,31 @@ ApplicationWindow {

function removeSelectNextIfNeeded(index) {
remoteNodesModel.remove(index);
if (index < remoteNodesModel.lastMainnetNodeSelected) {
remoteNodesModel.lastMainnetNodeSelected = remoteNodesModel.lastMainnetNodeSelected - 1
}
if (index < remoteNodesModel.lastTestnetNodeSelected) {
remoteNodesModel.lastTestnetNodeSelected = remoteNodesModel.lastTestnetNodeSelected - 1
}
if (index < remoteNodesModel.lastStagenetNodeSelected) {
remoteNodesModel.lastStagenetNodeSelected = remoteNodesModel.lastStagenetNodeSelected - 1
}
if (selected == index) {
applyRemoteNode(selected % remoteNodesModel.count || 0);
} else if (selected > index) {
selected = selected - 1;
}
}

function findFirstRemoteNodeAvailable(nettype) {
for (var index = 0; index < remoteNodesModel.count; ++index) {
const remoteNode = remoteNodesModel.get(index);
if (remoteNode.networkType == nettype || persistentSettings.nettype == 0 && !remoteNode.networkType) {
return index;
}
}
}

onCountChanged: store()
onDataChanged: store()
onSelectedChanged: store()
Expand Down Expand Up @@ -2276,6 +2354,17 @@ ApplicationWindow {
console.log("walletMode: " + (mode === 0 ? "simple": mode === 1 ? "simple (bootstrap)" : "Advanced"));
}

function networkTypeAsString() {
if (persistentSettings.nettype == 0){
return "mainnet";
}
else if (persistentSettings.nettype == 1) {
return "testnet";
} else {
return "stagenet"
}
}

Rectangle {
id: inactiveOverlay
visible: blur.visible
Expand Down

0 comments on commit 1375ee4

Please sign in to comment.