lez-programs/apps/amm/src/NewPositionRuntime.h
Ricardo Guilherme Schmidt 0e01962bec
feat: Introduce SequencerClient for enhanced account management and transaction querying
- Added SequencerClient class to handle asynchronous account reads and transaction queries.
- Updated NewPositionRuntime to integrate SequencerClient, allowing for improved wallet account management.
- Modified existing tests to accommodate changes in the new position schema from v1 to v2.
- Enhanced QML tests to validate new position form behavior with updated holding selections and context handling.
- Refactored code to ensure compatibility with the new SequencerClient functionalities.
2026-07-17 14:14:50 -03:00

76 lines
2.7 KiB
C++

#pragma once
#include <QJsonArray>
#include <QJsonObject>
#include <QString>
#include <QVariantMap>
#include <QVector>
#include <functional>
#include "ActiveNetwork.h"
class AmmClient;
class WalletProvider;
class SequencerClient;
struct WalletAccount;
class NewPositionRuntime {
public:
using ResultCallback = std::function<void(QVariantMap)>;
NewPositionRuntime(WalletProvider* wallet,
AmmClient* client,
SequencerClient* sequencer = nullptr);
void clearWalletAccounts();
void setWalletAccounts(const QVector<WalletAccount>& accounts);
void contextAsync(const QVariantMap& request,
const ActiveNetworkSnapshot& network,
bool walletOpen,
bool refreshPublicData,
ResultCallback callback);
void quoteAsync(const QVariantMap& request,
const ActiveNetworkSnapshot& network,
bool walletOpen,
bool forceRefresh,
ResultCallback callback);
void submitAsync(const QVariantMap& request,
const QString& quoteHash,
const ActiveNetworkSnapshot& network,
bool walletCanSubmit,
ResultCallback callback);
QVariantMap context(const QVariantMap& request,
const ActiveNetworkSnapshot& network,
bool walletOpen,
bool refreshWalletAccounts);
QVariantMap quote(const QVariantMap& request,
const ActiveNetworkSnapshot& network,
bool walletOpen);
QVariantMap submit(const QVariantMap& request,
const QString& quoteHash,
const ActiveNetworkSnapshot& network,
bool walletOpen);
private:
QJsonArray walletAccountReads(bool walletOpen, bool refresh) const;
QJsonObject buildQuoteInput(const QVariantMap& request,
const ActiveNetworkSnapshot& network,
bool walletOpen,
bool freshWalletAccounts,
QJsonObject* error) const;
void buildQuoteInputAsync(const QVariantMap& request,
const ActiveNetworkSnapshot& network,
bool walletOpen,
bool forceRefresh,
std::function<void(QJsonObject, QJsonObject)> callback) const;
WalletProvider* m_wallet;
AmmClient* m_client;
SequencerClient* m_sequencer;
QStringList m_walletPublicAccountIds;
bool m_submitInFlight = false;
};