support multiple seed languages

pull/258/head
larteyoh 1 month ago
parent 538fc81c51
commit 511c28eebb

@ -574,7 +574,7 @@ Popup {
anchors.right: parent.right//Layout.alignment: Qt.AlignRight; Layout.rightMargin: 0
width: settingsStack.comboBoxWidth
currentIndex: model.indexOf(Script.getJsonRootObject()["language"])
model: ["English"] // TODO logic from controller
model: Wallet.getSeedLanguages()
onCurrentTextChanged: settingsDialog.save()
indicatorWidth: settingsStack.comboBoxButtonWidth
indicatorDoNotPassBorder: settingsStack.comboBoxNestedButton

@ -1,6 +1,9 @@
#include "monero.hpp"
#include "../../tools/string.hpp"
#include "../../settings.hpp" // language
#include <nlohmann/json.hpp>
neroshop::MoneroWallet::MoneroWallet() : Wallet(WalletType::Monero)
{}
@ -23,6 +26,12 @@ int neroshop::MoneroWallet::create_random(const std::string& password, const std
wallet_config_obj.m_path = path;
wallet_config_obj.m_password = password;
wallet_config_obj.m_network_type = static_cast<monero::monero_network_type>(Wallet::network_type);
nlohmann::json settings = nlohmann::json::parse(neroshop::load_json(), nullptr, false);
if(settings.is_discarded()) {
wallet_config_obj.m_language = "English";
} else {
wallet_config_obj.m_language = settings["language"];
}
monero_wallet_obj = std::unique_ptr<monero_wallet_full>(monero_wallet_full::create_wallet (wallet_config_obj, nullptr));
if(monero_wallet_obj.get()) std::cout << "\033[1;35m" << "created wallet \"" << path << ".keys\"" << "\033[0m" << std::endl;
@ -413,6 +422,11 @@ std::string neroshop::MoneroWallet::get_seed() const {
return monero_wallet_obj->get_seed();
}
//-------------------------------------------------------
std::string neroshop::MoneroWallet::get_seed_language() const {
if(!monero_wallet_obj.get()) throw std::runtime_error("monero_wallet_full is not opened");
return monero_wallet_obj->get_seed_language();
}
//-------------------------------------------------------
//-------------------------------------------------------
std::string neroshop::MoneroWallet::get_path() const {
if(!monero_wallet_obj.get()) throw std::runtime_error("monero_wallet_full is not opened");

@ -59,6 +59,7 @@ public:
std::pair<std::string, std::string> get_spend_keys() const override;
std::string get_seed() const override;
std::string get_seed_language() const override;
std::string get_path() const override;

@ -3,6 +3,9 @@
#include "../tools/logger.hpp"
#include "../tools/string.hpp"
#include "../tools/process.hpp" // for monerod daemon process
#include "../settings.hpp" // language
#include <nlohmann/json.hpp>
#include <cmath>
#include <filesystem>
@ -55,6 +58,12 @@ int neroshop::Wallet::create_random(const std::string& password, const std::stri
wallet_config_obj.m_path = path;
wallet_config_obj.m_password = password;
wallet_config_obj.m_network_type = static_cast<monero::monero_network_type>(Wallet::network_type);
nlohmann::json settings = nlohmann::json::parse(neroshop::load_json(), nullptr, false);
if(settings.is_discarded()) {
wallet_config_obj.m_language = "English";
} else {
wallet_config_obj.m_language = settings["language"];
}
monero_wallet_obj = std::unique_ptr<monero_wallet_full>(monero_wallet_full::create_wallet (wallet_config_obj, nullptr));
if(monero_wallet_obj.get()) std::cout << "\033[1;35;49m" << "created wallet \"" << path << ".keys\"" << "\033[0m" << std::endl;
@ -1119,6 +1128,23 @@ std::string neroshop::Wallet::get_seed() const {
}
}
//-------------------------------------------------------
std::string neroshop::Wallet::get_seed_language() const {
switch(wallet_type) {
case WalletType::Monero:
if(!monero_wallet_obj.get()) throw std::runtime_error("monero_wallet_full is not opened");
return monero_wallet_obj->get_seed_language();
case WalletType::Wownero:
return "";
default:
return "";
}
}
//-------------------------------------------------------
std::vector<std::string> neroshop::Wallet::get_seed_languages() {
return monero::monero_wallet_full::get_seed_languages();
}
//-------------------------------------------------------
//-------------------------------------------------------
std::string neroshop::Wallet::get_path() const {
switch(wallet_type) {
case WalletType::Monero:

@ -163,6 +163,8 @@ public:
virtual std::pair<std::string, std::string> get_spend_keys() const; // secret, public
virtual std::string get_seed() const;
virtual std::string get_seed_language() const;
static std::vector<std::string> get_seed_languages();
virtual std::string get_path() const;
std::string get_type() const; // "wallet_info": Normal, HW

@ -151,6 +151,20 @@ QStringList neroshop::WalletController::getSeedList() const {
return seed_phrase;
}
QString neroshop::WalletController::getSeedLanguage() const {
if (!_wallet) throw std::runtime_error("neroshop::Wallet is not initialized");
return QString::fromStdString(_wallet->get_seed_language());
}
QStringList neroshop::WalletController::getSeedLanguages() const {
if (!_wallet) throw std::runtime_error("neroshop::Wallet is not initialized");
QStringList seed_languages;
for(const auto& lang : _wallet->get_seed_languages()) {
seed_languages.append(QString::fromStdString(lang));
}
return seed_languages;
}
QString neroshop::WalletController::getPrimaryAddress() const {
if (!_wallet)
throw std::runtime_error("neroshop::Wallet is not initialized");

@ -49,6 +49,8 @@ public:
Q_INVOKABLE QString getNetworkPort() const;
Q_INVOKABLE QString getSeed() const;
Q_INVOKABLE QStringList getSeedList() const;
Q_INVOKABLE QString getSeedLanguage() const;
Q_INVOKABLE QStringList getSeedLanguages() const;
Q_INVOKABLE QString getPrimaryAddress() const;
// todo: change getAddresses* functions to return a QVariantList (array) containing QVariantMaps (objects) that represent a monero subaddress
Q_INVOKABLE QStringList getAddressesAll() const;

Loading…
Cancel
Save