mirror of
https://github.com/monero-project/monero-gui.git
synced 2025-01-03 09:29:38 +00:00
Merge pull request #4088
a01dc06
open-wallet: set network type when using file browser (plowsof)
This commit is contained in:
commit
4487471ada
4 changed files with 42 additions and 21 deletions
|
@ -63,6 +63,7 @@
|
||||||
|
|
||||||
#include "QR-Code-scanner/Decoder.h"
|
#include "QR-Code-scanner/Decoder.h"
|
||||||
#include "qt/ScopeGuard.h"
|
#include "qt/ScopeGuard.h"
|
||||||
|
#include "NetworkType.h"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -280,3 +281,35 @@ bool OSHelper::installed() const
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#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;
|
||||||
|
}
|
||||||
|
|
|
@ -52,7 +52,9 @@ public:
|
||||||
Q_INVOKABLE QString temporaryPath() const;
|
Q_INVOKABLE QString temporaryPath() const;
|
||||||
Q_INVOKABLE bool removeTemporaryWallet(const QString &walletName) const;
|
Q_INVOKABLE bool removeTemporaryWallet(const QString &walletName) const;
|
||||||
Q_INVOKABLE bool isCapsLock() const;
|
Q_INVOKABLE bool isCapsLock() const;
|
||||||
|
Q_INVOKABLE quint8 getNetworkTypeFromFile(const QString &keysPath) const;
|
||||||
|
|
||||||
|
static std::pair<quint8, QString> getNetworkTypeAndAddressFromFile(const QString &wallet);
|
||||||
private:
|
private:
|
||||||
bool installed() const;
|
bool installed() const;
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "libwalletqt/WalletManager.h"
|
#include "libwalletqt/WalletManager.h"
|
||||||
#include "NetworkType.h"
|
#include "NetworkType.h"
|
||||||
#include "qt/utils.h"
|
#include "qt/utils.h"
|
||||||
|
#include "main/oshelper.h"
|
||||||
|
|
||||||
#include "KeysFiles.h"
|
#include "KeysFiles.h"
|
||||||
|
|
||||||
|
@ -121,26 +122,9 @@ void WalletKeysFilesModel::findWallets(const QString &moneroAccountsDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
QString wallet(keysFileinfo.path() + QDir::separator() + keysFileinfo.completeBaseName());
|
QString wallet(keysFileinfo.path() + QDir::separator() + keysFileinfo.completeBaseName());
|
||||||
quint8 networkType = NetworkType::MAINNET;
|
auto networkTypeAndAddress = OSHelper::getNetworkTypeAndAddressFromFile(wallet);
|
||||||
QString address = QString("");
|
quint8 networkType = networkTypeAndAddress.first;
|
||||||
|
QString address = networkTypeAndAddress.second;
|
||||||
// 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
this->addWalletKeysFile(WalletKeysFiles(wallet, networkType, std::move(address)));
|
this->addWalletKeysFile(WalletKeysFiles(wallet, networkType, std::move(address)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -308,7 +308,9 @@ Rectangle {
|
||||||
sidebarVisible: false
|
sidebarVisible: false
|
||||||
|
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
wizardController.openWalletFile(fileDialog.fileUrl);
|
var keysPath = walletManager.urlToLocalPath(fileDialog.fileUrl)
|
||||||
|
persistentSettings.nettype = oshelper.getNetworkTypeFromFile(keysPath);
|
||||||
|
wizardController.openWalletFile(keysPath);
|
||||||
}
|
}
|
||||||
onRejected: {
|
onRejected: {
|
||||||
console.log("Canceled")
|
console.log("Canceled")
|
||||||
|
|
Loading…
Reference in a new issue