From 5f93ea364870e0d41be16f45ad7d7575c8db995d Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Fri, 5 Jun 2026 03:24:03 -0300 Subject: [PATCH] add Network field on wallet creation --- src/LEZWalletBackend.cpp | 32 ++++++++++++++++++++++- src/LEZWalletBackend.h | 3 ++- src/LEZWalletBackend.rep | 2 +- src/qml/ExecutionZoneWalletView.qml | 4 +-- src/qml/views/OnboardingView.qml | 39 +++++++++++++++++++++++++++-- 5 files changed, 73 insertions(+), 7 deletions(-) diff --git a/src/LEZWalletBackend.cpp b/src/LEZWalletBackend.cpp index ad9111c..8d0249a 100644 --- a/src/LEZWalletBackend.cpp +++ b/src/LEZWalletBackend.cpp @@ -4,8 +4,13 @@ #include #include #include +#include +#include +#include #include #include +#include +#include #include #include #include @@ -290,10 +295,35 @@ QString LEZWalletBackend::transferDeshielded(QString fromHex, QString toHex, QSt NO_TIMEOUT).toString(); } -bool LEZWalletBackend::createNew(QString configPath, QString storagePath, QString password) +void LEZWalletBackend::applySequencerAddrToConfig(const QString& configPath, const QString& sequencerAddr) +{ + QJsonObject obj; + QFile file(configPath); + if (file.open(QIODevice::ReadOnly)) { + obj = QJsonDocument::fromJson(file.readAll()).object(); + file.close(); + } else { + // Defaults matching WalletConfig::default() in the wallet crate. + obj[QStringLiteral("seq_poll_timeout")] = QStringLiteral("30s"); + obj[QStringLiteral("seq_tx_poll_max_blocks")] = 15; + obj[QStringLiteral("seq_poll_max_retries")] = 10; + obj[QStringLiteral("seq_block_poll_max_amount")] = 100; + } + obj[QStringLiteral("sequencer_addr")] = sequencerAddr; + + QDir().mkpath(QFileInfo(configPath).absolutePath()); + if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) + file.write(QJsonDocument(obj).toJson(QJsonDocument::Indented)); +} + +bool LEZWalletBackend::createNew(QString configPath, QString storagePath, QString password, QString sequencerAddr) { const QString localConfigPath = toLocalPath(configPath); const QString localStoragePath = toLocalPath(storagePath); + + if (!sequencerAddr.isEmpty()) + applySequencerAddrToConfig(localConfigPath, sequencerAddr); + int err = m_logos->logos_execution_zone.create_new(localConfigPath, localStoragePath, password); if (err != WALLET_FFI_SUCCESS) return false; diff --git a/src/LEZWalletBackend.h b/src/LEZWalletBackend.h index 17c2cda..2d20cc7 100644 --- a/src/LEZWalletBackend.h +++ b/src/LEZWalletBackend.h @@ -45,12 +45,13 @@ public slots: QString transferShielded(QString fromHex, QString toKeysJson, QString amountStr) override; QString transferShieldedOwned(QString fromHex, QString toHex, QString amountStr) override; QString transferDeshielded(QString fromHex, QString toHex, QString amountStr) override; - bool createNew(QString configPath, QString storagePath, QString password) override; + bool createNew(QString configPath, QString storagePath, QString password, QString sequencerAddr) override; void copyToClipboard(QString text) override; private: void persistConfigPath(const QString& path); void persistStoragePath(const QString& path); + void applySequencerAddrToConfig(const QString& configPath, const QString& sequencerAddr); void refreshBlockHeights(); void refreshSequencerAddr(); void saveWallet(); diff --git a/src/LEZWalletBackend.rep b/src/LEZWalletBackend.rep index 0bd0a33..376f3e4 100644 --- a/src/LEZWalletBackend.rep +++ b/src/LEZWalletBackend.rep @@ -23,7 +23,7 @@ class LEZWalletBackend SLOT(QString transferShieldedOwned(QString fromHex, QString toHex, QString amountStr)) SLOT(QString transferDeshielded(QString fromHex, QString toHex, QString amountStr)) - SLOT(bool createNew(QString configPath, QString storagePath, QString password)) + SLOT(bool createNew(QString configPath, QString storagePath, QString password, QString sequencerAddr)) SLOT(void copyToClipboard(QString text)) } diff --git a/src/qml/ExecutionZoneWalletView.qml b/src/qml/ExecutionZoneWalletView.qml index de4f165..ebf6152 100644 --- a/src/qml/ExecutionZoneWalletView.qml +++ b/src/qml/ExecutionZoneWalletView.qml @@ -115,9 +115,9 @@ Rectangle { OnboardingView { storePath: backend ? backend.storagePath : "" configPath: backend ? backend.configPath : "" - onCreateWallet: function(configPath, storagePath, password) { + onCreateWallet: function(configPath, storagePath, password, sequencerUrl) { if (!backend) return - logos.watch(backend.createNew(configPath, storagePath, password), + logos.watch(backend.createNew(configPath, storagePath, password, sequencerUrl), function(ok) { if (!ok) createError = qsTr("Failed to create wallet. Check paths and try again.") diff --git a/src/qml/views/OnboardingView.qml b/src/qml/views/OnboardingView.qml index 30bb903..71cf5fd 100644 --- a/src/qml/views/OnboardingView.qml +++ b/src/qml/views/OnboardingView.qml @@ -13,7 +13,10 @@ Control { property string storePath: "" property string createError: "" - signal createWallet(string configPath, string storagePath, string password) + signal createWallet(string configPath, string storagePath, string password, string sequencerUrl) + + readonly property string testnetUrl: "https://testnet.lez.logos.co" + readonly property string localhostUrl: "http://127.0.0.1:3040" QtObject { @@ -90,6 +93,38 @@ Control { } } + RowLayout { + Layout.fillWidth: true + Layout.topMargin: Theme.spacing.medium + spacing: Theme.spacing.small + LogosText { + text: qsTr("Network") + font.pixelSize: Theme.typography.secondaryText + font.weight: Theme.typography.weightMedium + color: Theme.palette.text + } + LogosTextField { + id: sequencerUrlField + Layout.fillWidth: true + placeholderText: qsTr("Sequencer URL") + text: root.testnetUrl + } + } + RowLayout { + Layout.fillWidth: true + spacing: Theme.spacing.small + LogosButton { + text: qsTr("Testnet") + opacity: sequencerUrlField.text === root.testnetUrl ? 1.0 : 0.4 + onClicked: sequencerUrlField.text = root.testnetUrl + } + LogosButton { + text: qsTr("Localhost") + opacity: sequencerUrlField.text === root.localhostUrl ? 1.0 : 0.4 + onClicked: sequencerUrlField.text = root.localhostUrl + } + } + LogosText { text: qsTr("Security") font.pixelSize: Theme.typography.secondaryText @@ -131,7 +166,7 @@ Control { root.createError = qsTr("Passwords do not match.") } else { root.createError = "" - root.createWallet(configPathField.text, storagePathField.text, passwordField.text) + root.createWallet(configPathField.text, storagePathField.text, passwordField.text, sequencerUrlField.text) } } }