Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RemoteNodeList, RemoteNodeDialog: different remote node for each network type; implement labels #3820

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions components/RemoteNodeDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ import "." as MoneroComponents

MoneroComponents.Dialog {
id: root
title: (editMode ? qsTr("Edit remote node") : qsTr("Add remote node")) + translationManager.emptyString

title: (editMode ? qsTr("Edit remote node") + (persistentSettings.nettype != 0 ? " (%1)".arg(networkTypeAsString()) : "")
: qsTr("Add remote node") + (persistentSettings.nettype != 0 ? " (%1)".arg(networkTypeAsString()) : "")
) + translationManager.emptyString
property var callbackOnSuccess: null
property bool editMode: false
property bool success: false

onActiveFocusChanged: activeFocus && remoteNodeAddress.forceActiveFocus()
onActiveFocusChanged: activeFocus && remoteNodeLabel.forceActiveFocus()

function add(callbackOnSuccess) {
root.editMode = false;
Expand All @@ -55,6 +56,9 @@ MoneroComponents.Dialog {
remoteNodeAddress.daemonAddrText = hostPort[1];
remoteNodeAddress.daemonPortText = hostPort[2];
}
if (remoteNode.label) {
remoteNodeLabel.text = remoteNode.label;
}
daemonUsername.text = remoteNode.username;
daemonPassword.text = remoteNode.password;
setTrustedDaemonCheckBox.checked = remoteNode.trusted;
Expand All @@ -67,13 +71,16 @@ MoneroComponents.Dialog {
onClosed: {
if (root.success && callbackOnSuccess) {
callbackOnSuccess({
label: remoteNodeLabel.text,
networkType: persistentSettings.nettype.toString(),
address: remoteNodeAddress.getAddress(),
username: daemonUsername.text,
password: daemonPassword.text,
trusted: setTrustedDaemonCheckBox.checked,
});
}

remoteNodeLabel.text = "";
remoteNodeAddress.daemonAddrText = "";
remoteNodeAddress.daemonPortText = "";
daemonUsername.text = "";
Expand All @@ -82,6 +89,18 @@ MoneroComponents.Dialog {
root.success = false;
}

MoneroComponents.LineEdit {
id: remoteNodeLabel
Layout.fillWidth: true
Layout.minimumWidth: 220
labelText: qsTr("Label") + translationManager.emptyString
placeholderText: qsTr("(optional)") + translationManager.emptyString
placeholderFontSize: 15
text: ""
labelFontSize: 14
fontSize: 15
}

MoneroComponents.RemoteNodeEdit {
id: remoteNodeAddress
Layout.fillWidth: true
Expand Down
11 changes: 8 additions & 3 deletions components/RemoteNodeList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ ColumnLayout {
height: 30
Layout.fillWidth: true
color: itemMouseArea.containsMouse || trustedDaemonCheckMark.labelMouseArea.containsMouse || index === remoteNodesModel.selected ? MoneroComponents.Style.titleBarButtonHoverColor : "transparent"
property var networkType: remoteNodesModel.get(index) ? remoteNodesModel.get(index).networkType : ""
visible: (networkType ? networkType == persistentSettings.nettype.toString()
: persistentSettings.nettype.toString() == 0 ? true
: false)

Rectangle {
visible: index === remoteNodesModel.selected
Expand All @@ -76,7 +80,7 @@ ColumnLayout {
anchors.left: parent.left
anchors.top: parent.top
height: 1
visible: index > 0
visible: index != remoteNodesModel.findFirstRemoteNodeAvailable(persistentSettings.nettype)

MoneroEffects.ColorTransition {
targetObj: parent
Expand All @@ -89,7 +93,8 @@ ColumnLayout {
anchors.fill: parent
anchors.rightMargin: 80
color: "transparent"
property var trusted: remoteNodesModel.get(index).trusted
property var trusted: remoteNodesModel.get(index) ? remoteNodesModel.get(index).trusted : false
property var label: remoteNodesModel.get(index) ? remoteNodesModel.get(index).label : ""

MoneroComponents.TextPlain {
id: addressText
Expand All @@ -99,7 +104,7 @@ ColumnLayout {
anchors.left: parent.left
anchors.leftMargin: 6
font.pixelSize: 16
text: address
text: (label ? label + " (" + address + ")" : address)
themeTransition: false
elide: Text.ElideMiddle
}
Expand Down
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