From da3216156d22d96e72213ffe60ca534594c9e247 Mon Sep 17 00:00:00 2001 From: Tim L Date: Mon, 11 Dec 2017 16:44:01 -0500 Subject: [PATCH] Use wallet2_api isAddressLocal utils method for isDaemonLocal check --- main.qml | 12 +----------- pages/Mining.qml | 15 +++------------ src/libwalletqt/WalletManager.cpp | 5 +++++ src/libwalletqt/WalletManager.h | 1 + 4 files changed, 10 insertions(+), 23 deletions(-) diff --git a/main.qml b/main.qml index 7f35affa..339af938 100644 --- a/main.qml +++ b/main.qml @@ -317,7 +317,7 @@ ApplicationWindow { middlePanel.transferView.updatePriorityDropdown(); // If wallet isnt connected and no daemon is running - Ask - if(!isMobile && isDaemonLocal() && !walletInitialized && status === Wallet.ConnectionStatus_Disconnected && !daemonManager.running(persistentSettings.testnet)){ + if(!isMobile && walletManager.isDaemonLocal(appWindow.persistentSettings.daemon_address) && !walletInitialized && status === Wallet.ConnectionStatus_Disconnected && !daemonManager.running(persistentSettings.testnet)){ daemonManagerDialog.open(); } // initialize transaction history once wallet is initialized first time; @@ -1632,16 +1632,6 @@ ApplicationWindow { onTriggered: checkUpdates() } - function isDaemonLocal() { - var daemonAddress = appWindow.persistentSettings.daemon_address - if (daemonAddress === "") - return false - var daemonHost = daemonAddress.split(":")[0] - if (daemonHost === "127.0.0.1" || daemonHost === "localhost") - return true - return false - } - function releaseFocus() { // Workaround to release focus from textfield when scrolling (https://bugreports.qt.io/browse/QTBUG-34867) if(isAndroid) { diff --git a/pages/Mining.qml b/pages/Mining.qml index 0d87310f..f849b288 100644 --- a/pages/Mining.qml +++ b/pages/Mining.qml @@ -37,15 +37,6 @@ Rectangle { color: "#F0EEEE" property var currentHashRate: 0 - function isDaemonLocal() { - if (appWindow.currentDaemonAddress === "") - return false - var daemonHost = appWindow.currentDaemonAddress.split(":")[0] - if (daemonHost === "127.0.0.1" || daemonHost === "localhost") - return true - return false - } - /* main layout */ ColumnLayout { id: mainLayout @@ -75,7 +66,7 @@ Rectangle { fontSize: 18 color: "#D02020" text: qsTr("(only available for local daemons)") - visible: !isDaemonLocal() + visible: !walletManager.isDaemonLocal(appWindow.currentDaemonAddress) } Text { @@ -157,7 +148,7 @@ Rectangle { } else { errorPopup.title = qsTr("Error starting mining") + translationManager.emptyString; errorPopup.text = qsTr("Couldn't start mining.
") - if (!isDaemonLocal()) + if (!walletManager.isDaemonLocal(appWindow.currentDaemonAddress)) errorPopup.text += qsTr("Mining is only available on local daemons. Run a local daemon to be able to mine.
") errorPopup.icon = StandardIcon.Critical errorPopup.open() @@ -225,7 +216,7 @@ Rectangle { console.log("Mining page loaded"); update() - timer.running = isDaemonLocal() + timer.running = walletManager.isDaemonLocal(appWindow.currentDaemonAddress) } function onPageClosed() { diff --git a/src/libwalletqt/WalletManager.cpp b/src/libwalletqt/WalletManager.cpp index 875e4cca..0c28ad30 100644 --- a/src/libwalletqt/WalletManager.cpp +++ b/src/libwalletqt/WalletManager.cpp @@ -270,6 +270,11 @@ bool WalletManager::localDaemonSynced() const return blockchainHeight() > 1 && blockchainHeight() >= blockchainTargetHeight(); } +bool WalletManager::isDaemonLocal(const QString &daemon_address) const +{ + return Monero::Utils::isAddressLocal(daemon_address.toStdString()); +} + QString WalletManager::resolveOpenAlias(const QString &address) const { bool dnssec_valid = false; diff --git a/src/libwalletqt/WalletManager.h b/src/libwalletqt/WalletManager.h index 7eacc3f0..ddc506cf 100644 --- a/src/libwalletqt/WalletManager.h +++ b/src/libwalletqt/WalletManager.h @@ -111,6 +111,7 @@ public: Q_INVOKABLE quint64 blockchainTargetHeight() const; Q_INVOKABLE double miningHashRate() const; Q_INVOKABLE bool localDaemonSynced() const; + Q_INVOKABLE bool isDaemonLocal(const QString &daemon_address) const; Q_INVOKABLE bool isMining() const; Q_INVOKABLE bool startMining(const QString &address, quint32 threads, bool backgroundMining, bool ignoreBattery);