logos-execution-zone-wallet-ui/src/LEZWalletAccountModel.h

72 lines
2.8 KiB
C
Raw Normal View History

2026-02-22 02:03:13 +05:30
#pragma once
#include <QAbstractListModel>
2026-06-16 21:02:54 -03:00
#include <QVariant>
2026-02-22 02:03:13 +05:30
#include <QString>
#include <QVariantList>
2026-02-22 02:03:13 +05:30
2026-06-16 21:02:54 -03:00
// Public accounts have no key group, so they all share the PublicSectionKey section.
// Private accounts section by NPK (the key group they belong to) — see
// LEZWalletBackend::buildEnrichedAccountList, which attaches "npk"/"keys_json" per entry.
inline const QString PublicSectionKey = QStringLiteral("public");
2026-02-22 02:03:13 +05:30
struct LEZWalletAccountEntry {
QString name;
2026-06-06 01:24:27 -03:00
QString accountId;
2026-02-22 02:03:13 +05:30
QString balance;
2026-06-16 21:02:54 -03:00
QString vaultBalance; // claimable balance held in this account's bridge vault PDA
2026-02-22 02:03:13 +05:30
bool isPublic = true;
2026-06-16 21:02:54 -03:00
QString sectionKey;
QString keysJson; // {nullifier_public_key, viewing_public_key} shared by the whole section; private only
bool isFirstInGroup = false; // QML renders the section header above rows where this is true
2026-07-03 23:43:48 -03:00
// Whether some program (in practice, the authenticated-transfer program) has claimed
// this account yet. Defaults to false (shown as needing init) so an account whose
// state we failed to enrich isn't silently mistaken for a usable one.
bool isInitialized = false;
2026-02-22 02:03:13 +05:30
};
2026-06-16 21:02:54 -03:00
// Note: this model is exposed to QML via Qt Remote Objects model replication (see
// logos.model() in ExecutionZoneWalletView.qml), which only replicates roles — not
// arbitrary Q_PROPERTYs. Anything QML needs must be a role on the row, not a property
// on the model itself.
2026-02-22 02:03:13 +05:30
class LEZWalletAccountModel : public QAbstractListModel {
Q_OBJECT
Q_PROPERTY(int count READ count NOTIFY countChanged)
public:
enum Role {
NameRole = Qt::UserRole + 1,
2026-06-06 01:24:27 -03:00
AccountIdRole,
2026-02-22 02:03:13 +05:30
BalanceRole,
2026-06-16 21:02:54 -03:00
VaultBalanceRole,
IsPublicRole,
SectionKeyRole,
KeysJsonRole,
2026-07-03 23:43:48 -03:00
IsFirstInGroupRole,
IsInitializedRole
2026-02-22 02:03:13 +05:30
};
Q_ENUM(Role)
explicit LEZWalletAccountModel(QObject* parent = nullptr);
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
QHash<int, QByteArray> roleNames() const override;
void replaceFromVariantList(const QVariantList& list);
2026-06-06 01:24:27 -03:00
void setBalanceByAccountId(const QString& accountId, const QString& balance);
2026-06-16 21:02:54 -03:00
void setVaultBalanceByAccountId(const QString& accountId, const QString& vaultBalance);
2026-02-22 02:03:13 +05:30
int count() const { return m_entries.size(); }
2026-06-16 21:02:54 -03:00
// Authoritative isPublic lookup by account ID — used to validate/derive the flag
// server-side instead of trusting a caller-supplied value, since this model is the
// source of truth for which accounts the wallet actually owns. Falls back to
// `defaultValue` if the account isn't found.
bool isPublicAccount(const QString& accountId, bool defaultValue = true) const;
2026-02-22 02:03:13 +05:30
signals:
void countChanged();
private:
QVector<LEZWalletAccountEntry> m_entries;
};