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 #4163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 onOk() {
root.success = true;
Expand All @@ -62,6 +63,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 @@ -74,13 +78,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 @@ -89,6 +96,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
9 changes: 7 additions & 2 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 @@ -90,6 +94,7 @@ ColumnLayout {
anchors.rightMargin: 80
color: "transparent"
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
100 changes: 95 additions & 5 deletions main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ ApplicationWindow {
passwordDialog.onAcceptedCallback = function() {
if(walletPassword === passwordDialog.password)
passwordDialog.close();
else
else
passwordDialog.showError(qsTr("Wrong password") + translationManager.emptyString);
}
passwordDialog.open(usefulName(persistentSettings.wallet_path));
Expand Down Expand Up @@ -358,6 +358,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 @@ -1042,10 +1082,10 @@ ApplicationWindow {
var isReserveProof = signature.indexOf("ReserveProofV") === 0;
if (address.length > 0 && !isReserveProof) {
result = currentWallet.checkTxProof(txid, address, message, signature);
}
}
else if (isReserveProof) {
result = currentWallet.checkReserveProof(address, message, signature);
}
}
else {
result = currentWallet.checkSpendProof(txid, message, signature);
}
Expand Down Expand Up @@ -1078,7 +1118,7 @@ ApplicationWindow {
informationPopup.title = qsTr("Payment proof check") + translationManager.emptyString;
informationPopup.icon = good ? StandardIcon.Information : StandardIcon.Critical;
informationPopup.text = good ? qsTr("Good signature") : qsTr("Bad signature");
}
}
else if (isReserveProof && results[0] === "true") {
var good = results[1] === "true";
informationPopup.title = qsTr("Reserve proof check") + translationManager.emptyString;
Expand Down Expand Up @@ -1480,6 +1520,9 @@ ApplicationWindow {
id: remoteNodesModel

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

signal store()

Expand All @@ -1491,6 +1534,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 @@ -1502,6 +1548,9 @@ ApplicationWindow {
}
persistentSettings.remoteNodesSerialized = JSON.stringify({
selected: selected,
lastMainnetNodeSelected: lastMainnetNodeSelected,
lastTestnetNodeSelected: lastTestnetNodeSelected,
lastStagenetNodeSelected: lastStagenetNodeSelected,
nodes: remoteNodes
});
});
Expand All @@ -1510,7 +1559,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 @@ -1530,13 +1581,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 @@ -1546,13 +1606,32 @@ 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;
}
}
return -1;
}

onCountChanged: store()
onDataChanged: store()
onSelectedChanged: store()
Expand Down Expand Up @@ -2305,6 +2384,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