mirror of
https://github.com/logos-blockchain/lez-programs.git
synced 2026-07-02 21:19:44 +00:00
Turns the dummy-data AMM UI into a real client of the on-chain LEZ wallet.
Adds a hand-written ui_qml C++ backend (src/AmmUi*) over the core
logos_execution_zone module: create/open a local wallet, create and list
public/private accounts, and a navbar Connect / Connected + account-selector
+ Disconnect flow. Onboarding is password-only (no path picking) with a
per-app wallet at ~/.lee/amm-wallet (override: AMM_WALLET_HOME_DIR);
standalone gets its own wallet, Basecamp shares accounts via adopt-on-start.
Requires Nix with flakes; macOS also needs `sandbox = false` (the default).
The logos_execution_zone input is pinned to a module rev whose LEZ (lssa)
already includes the macOS Metal-build fix, so no `--override-input` is
needed — plain `nix run .` works:
cd apps/amm
nix run .
- create_new now returns the new wallet's BIP39 mnemonic (not an int status);
the app currently discards it, so the wallet can't yet be recovered. Surfacing
it in onboarding (+ restore_storage) is a follow-up.
- The wallet password is currently a no-op upstream (storage.rs: "TODO: use
password for storage encryption"); storage.json is plaintext. So Disconnect
is a UI-level lock and reconnect does not (cannot yet) re-prompt for it.
- wallet-ffi requires explicit config/storage paths; a *_default() FFI would
let the app drop its path handling.
- Bundled network config: connects to whatever WalletConfig::default() points
at; real testnet endpoints still TBD.
78 lines
2.7 KiB
C++
78 lines
2.7 KiB
C++
#ifndef AMM_UI_BACKEND_H
|
|
#define AMM_UI_BACKEND_H
|
|
|
|
#include <QObject>
|
|
#include <QString>
|
|
|
|
#include "rep_AmmUiBackend_source.h"
|
|
|
|
#include "AccountModel.h"
|
|
|
|
class LogosAPI;
|
|
struct LogosModules;
|
|
class QNetworkAccessManager;
|
|
class QTimer;
|
|
|
|
// Source-side implementation of the AmmUiBackend .rep interface.
|
|
// Inheriting from AmmUiBackendSimpleSource gives us the generated PROPs and
|
|
// SLOTs from AmmUiBackend.rep — all the simple ones flow over QtRO. Talks to
|
|
// the core logos_execution_zone wallet module via LogosModules.
|
|
class AmmUiBackend : public AmmUiBackendSimpleSource {
|
|
Q_OBJECT
|
|
Q_PROPERTY(AccountModel* accountModel READ accountModel CONSTANT)
|
|
|
|
public:
|
|
explicit AmmUiBackend(LogosAPI* logosAPI = nullptr, QObject* parent = nullptr);
|
|
~AmmUiBackend() override;
|
|
|
|
AccountModel* accountModel() const { return m_accountModel; }
|
|
|
|
public slots:
|
|
// Overrides of the pure-virtual slots generated from the .rep.
|
|
QString createAccountPublic() override;
|
|
QString createAccountPrivate() override;
|
|
void refreshAccounts() override;
|
|
void refreshBalances() override;
|
|
QString getBalance(QString accountIdHex, bool isPublic) override;
|
|
// Return the new wallet's BIP39 mnemonic (empty string on failure) so the
|
|
// UI can force a one-time seed-phrase backup step.
|
|
QString createNewDefault(QString password) override;
|
|
QString createNew(QString configPath, QString storagePath, QString password) override;
|
|
bool openExisting() override;
|
|
void disconnectWallet() override;
|
|
bool changeSequencerAddr(QString url) override;
|
|
void copyToClipboard(QString text) override;
|
|
|
|
private:
|
|
// Per-app wallet home (kept distinct from the wallet's canonical
|
|
// ~/.lee/wallet so standalone instances stay isolated; Basecamp sharing
|
|
// is handled by adopting an already-open shared wallet on startup).
|
|
static QString defaultWalletHome();
|
|
QString defaultConfigPath() const;
|
|
QString defaultStoragePath() const;
|
|
|
|
void persistConfigPath(const QString& path);
|
|
void persistStoragePath(const QString& path);
|
|
void openOrAdoptWallet();
|
|
// True when the shared core already has a wallet open — including a freshly
|
|
// created one with zero accounts. See the definition for why list_accounts()
|
|
// alone is insufficient.
|
|
bool sharedWalletIsOpen();
|
|
void refreshBlockHeights();
|
|
void refreshSequencerAddr();
|
|
void saveWallet();
|
|
|
|
// Probe the configured sequencer over HTTP and update sequencerReachable.
|
|
void checkReachability();
|
|
|
|
AccountModel* m_accountModel;
|
|
|
|
LogosAPI* m_logosAPI;
|
|
LogosModules* m_logos;
|
|
|
|
QNetworkAccessManager* m_net;
|
|
QTimer* m_reachabilityTimer;
|
|
};
|
|
|
|
#endif // AMM_UI_BACKEND_H
|