mirror of
https://github.com/logos-blockchain/logos-execution-zone-wallet-ui.git
synced 2026-07-29 14:13:52 +00:00
add Network field on wallet creation
This commit is contained in:
parent
535481fbb7
commit
5f93ea3648
@ -4,8 +4,13 @@
|
||||
#include <QClipboard>
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QGuiApplication>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QSettings>
|
||||
#include <QTimer>
|
||||
#include <QUrl>
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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))
|
||||
}
|
||||
|
||||
@ -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.")
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user