aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorplowsof <plowsof@protonmail.com>2022-12-23 08:30:03 +0000
committerplowsof <plowsof@protonmail.com>2022-12-28 18:46:22 +0000
commita01dc06a54c5f30bb2bf49b0e28d8853c95df7af (patch)
tree2871ee5489d496a749fbe14881f137c9511455c6
parent48393db2c75bd306e7d7f5cd2c226880a5eb0386 (diff)
downloadmonzero-gui-a01dc06a54c5f30bb2bf49b0e28d8853c95df7af.tar.gz
monzero-gui-a01dc06a54c5f30bb2bf49b0e28d8853c95df7af.tar.xz
monzero-gui-a01dc06a54c5f30bb2bf49b0e28d8853c95df7af.zip
open-wallet: set network type when using file browser
Co-authored-by: selsta <selsta@users.noreply.github.com>
-rw-r--r--src/main/oshelper.cpp33
-rw-r--r--src/main/oshelper.h2
-rw-r--r--src/qt/KeysFiles.cpp24
-rw-r--r--wizard/WizardController.qml4
4 files changed, 42 insertions, 21 deletions
diff --git a/src/main/oshelper.cpp b/src/main/oshelper.cpp
index c9b1e269..8294dd3c 100644
--- a/src/main/oshelper.cpp
+++ b/src/main/oshelper.cpp
@@ -63,6 +63,7 @@
#include "QR-Code-scanner/Decoder.h"
#include "qt/ScopeGuard.h"
+#include "NetworkType.h"
namespace
{
@@ -280,3 +281,35 @@ bool OSHelper::installed() const
return false;
#endif
}
+
+std::pair<quint8, QString> OSHelper::getNetworkTypeAndAddressFromFile(const QString &wallet)
+{
+ quint8 networkType = NetworkType::MAINNET;
+ QString address = QString("");
+ // attempt to retreive wallet address
+ if(QFile::exists(wallet + ".address.txt")){
+ QFile file(wallet + ".address.txt");
+ file.open(QFile::ReadOnly | QFile::Text);
+ QString _address = QString(file.readAll());
+ if(!_address.isEmpty()){
+ address = _address;
+ if(address.startsWith("5") || address.startsWith("7")){
+ networkType = NetworkType::STAGENET;
+ } else if(address.startsWith("9") || address.startsWith("B")){
+ networkType = NetworkType::TESTNET;
+ }
+ }
+
+ file.close();
+ }
+ return std::make_pair(networkType, address);
+}
+
+quint8 OSHelper::getNetworkTypeFromFile(const QString &keysPath) const
+{
+ QString walletPath = keysPath;
+ if(keysPath.endsWith(".keys")){
+ walletPath = keysPath.mid(0,keysPath.length()-5);
+ }
+ return getNetworkTypeAndAddressFromFile(walletPath).first;
+}
diff --git a/src/main/oshelper.h b/src/main/oshelper.h
index f4168071..eca1f2c7 100644
--- a/src/main/oshelper.h
+++ b/src/main/oshelper.h
@@ -52,7 +52,9 @@ public:
Q_INVOKABLE QString temporaryPath() const;
Q_INVOKABLE bool removeTemporaryWallet(const QString &walletName) const;
Q_INVOKABLE bool isCapsLock() const;
+ Q_INVOKABLE quint8 getNetworkTypeFromFile(const QString &keysPath) const;
+ static std::pair<quint8, QString> getNetworkTypeAndAddressFromFile(const QString &wallet);
private:
bool installed() const;
diff --git a/src/qt/KeysFiles.cpp b/src/qt/KeysFiles.cpp
index 31186950..2f10bab9 100644
--- a/src/qt/KeysFiles.cpp
+++ b/src/qt/KeysFiles.cpp
@@ -39,6 +39,7 @@
#include "libwalletqt/WalletManager.h"
#include "NetworkType.h"
#include "qt/utils.h"
+#include "main/oshelper.h"
#include "KeysFiles.h"
@@ -121,26 +122,9 @@ void WalletKeysFilesModel::findWallets(const QString &moneroAccountsDir)
}
QString wallet(keysFileinfo.path() + QDir::separator() + keysFileinfo.completeBaseName());
- quint8 networkType = NetworkType::MAINNET;
- QString address = QString("");
-
- // attempt to retreive wallet address
- if(fileExists(wallet + ".address.txt")){
- QFile file(wallet + ".address.txt");
- file.open(QFile::ReadOnly | QFile::Text);
- QString _address = QString(file.readAll());
-
- if(!_address.isEmpty()){
- address = _address;
- if(address.startsWith("5") || address.startsWith("7")){
- networkType = NetworkType::STAGENET;
- } else if(address.startsWith("9") || address.startsWith("B")){
- networkType = NetworkType::TESTNET;
- }
- }
-
- file.close();
- }
+ auto networkTypeAndAddress = OSHelper::getNetworkTypeAndAddressFromFile(wallet);
+ quint8 networkType = networkTypeAndAddress.first;
+ QString address = networkTypeAndAddress.second;
this->addWalletKeysFile(WalletKeysFiles(wallet, networkType, std::move(address)));
}
diff --git a/wizard/WizardController.qml b/wizard/WizardController.qml
index be4e5334..593f9c84 100644
--- a/wizard/WizardController.qml
+++ b/wizard/WizardController.qml
@@ -308,7 +308,9 @@ Rectangle {
sidebarVisible: false
onAccepted: {
- wizardController.openWalletFile(fileDialog.fileUrl);
+ var keysPath = walletManager.urlToLocalPath(fileDialog.fileUrl)
+ persistentSettings.nettype = oshelper.getNetworkTypeFromFile(keysPath);
+ wizardController.openWalletFile(keysPath);
}
onRejected: {
console.log("Canceled")