minor refactor

This commit is contained in:
Sergio Chouhy 2026-06-06 01:24:27 -03:00
parent 3efa884128
commit af12a03295
8 changed files with 22 additions and 22 deletions

View File

@ -31,7 +31,7 @@ bool LEZAccountFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex& s
int LEZAccountFilterModel::rowForAddress(const QString& address) const
{
for (int i = 0; i < rowCount(); ++i) {
if (data(index(i, 0), LEZWalletAccountModel::AddressRole).toString() == address)
if (data(index(i, 0), LEZWalletAccountModel::AccountIdRole).toString() == address)
return i;
}
return -1;

View File

@ -21,7 +21,7 @@ QVariant LEZWalletAccountModel::data(const QModelIndex& index, int role) const
const LEZWalletAccountEntry& e = m_entries.at(index.row());
switch (role) {
case NameRole: return e.name;
case AddressRole: return e.address;
case AccountIdRole: return e.accountId;
case BalanceRole: return e.balance;
case IsPublicRole: return e.isPublic;
default: return QVariant();
@ -32,7 +32,7 @@ QHash<int, QByteArray> LEZWalletAccountModel::roleNames() const
{
return {
{ NameRole, "name" },
{ AddressRole, "address" },
{ AccountIdRole, "accountId" },
{ BalanceRole, "balance" },
{ IsPublicRole, "isPublic" }
};
@ -48,13 +48,13 @@ void LEZWalletAccountModel::replaceFromJsonArray(const QJsonArray& arr)
e.balance = QString();
if (v.isObject()) {
const QJsonObject obj = v.toObject();
e.address = obj.value(QStringLiteral("account_id")).toString();
e.accountId = obj.value(QStringLiteral("account_id")).toString();
e.isPublic = obj.value(QStringLiteral("is_public")).toBool(true);
} else {
e.address = v.toString();
e.accountId = v.toString();
e.isPublic = true;
}
e.name = QStringLiteral("Account %1").arg(e.address.left(4));
e.name = QString();
m_entries.append(e);
}
endResetModel();
@ -62,10 +62,10 @@ void LEZWalletAccountModel::replaceFromJsonArray(const QJsonArray& arr)
emit countChanged();
}
void LEZWalletAccountModel::setBalanceByAddress(const QString& address, const QString& balance)
void LEZWalletAccountModel::setBalanceByAccountId(const QString& accountId, const QString& balance)
{
for (int i = 0; i < m_entries.size(); ++i) {
if (m_entries.at(i).address == address) {
if (m_entries.at(i).accountId == accountId) {
if (m_entries.at(i).balance != balance) {
m_entries[i].balance = balance;
QModelIndex idx = index(i, 0);

View File

@ -6,7 +6,7 @@
struct LEZWalletAccountEntry {
QString name;
QString address;
QString accountId;
QString balance;
bool isPublic = true;
};
@ -17,7 +17,7 @@ class LEZWalletAccountModel : public QAbstractListModel {
public:
enum Role {
NameRole = Qt::UserRole + 1,
AddressRole,
AccountIdRole,
BalanceRole,
IsPublicRole
};
@ -30,7 +30,7 @@ public:
QHash<int, QByteArray> roleNames() const override;
void replaceFromJsonArray(const QJsonArray& arr);
void setBalanceByAddress(const QString& address, const QString& balance);
void setBalanceByAccountId(const QString& accountId, const QString& balance);
int count() const { return m_entries.size(); }
signals:

View File

@ -188,11 +188,11 @@ void LEZWalletBackend::updateBalances()
bool anyFailed = false;
for (int i = 0; i < m_accountModel->count(); ++i) {
const QModelIndex idx = m_accountModel->index(i, 0);
const QString addr = m_accountModel->data(idx, LEZWalletAccountModel::AddressRole).toString();
const QString addr = m_accountModel->data(idx, LEZWalletAccountModel::AccountIdRole).toString();
const bool isPub = m_accountModel->data(idx, LEZWalletAccountModel::IsPublicRole).toBool();
const QString bal = getBalance(addr, isPub);
if (!bal.isEmpty())
m_accountModel->setBalanceByAddress(addr, bal);
m_accountModel->setBalanceByAccountId(addr, bal);
else
anyFailed = true;
}

View File

@ -18,7 +18,7 @@ ComboBox {
rightPadding: 12
implicitHeight: 40
textRole: "name"
valueRole: "address"
valueRole: "accountId"
background: Rectangle {
radius: Theme.spacing.radiusSmall
@ -47,7 +47,7 @@ ComboBox {
selectByMouse: true
font.pixelSize: Theme.typography.secondaryText
color: Theme.palette.text
text: root.currentValue ? ("Account " + Base58.encode(root.currentValue).substring(0, 6)) : root.displayText
text: root.currentValue ? ("Account " + Base58.encode(root.currentValue).substring(0, 4)) : root.displayText
verticalAlignment: Text.AlignVCenter
clip: true
}

View File

@ -35,7 +35,7 @@ ItemDelegate {
spacing: Theme.spacing.small
LogosText {
text: model.name ?? ""
text: model.name || ("Account " + Base58.encode(model.accountId ?? "").slice(0, 4))
font.pixelSize: Theme.typography.secondaryText
font.bold: true
}
@ -70,7 +70,7 @@ ItemDelegate {
id: addressLabel
Layout.fillWidth: true
verticalAlignment: Text.AlignVCenter
text: Base58.encode(model.address ?? "")
text: Base58.encode(model.accountId ?? "")
font.pixelSize: Theme.typography.secondaryText
color: Theme.palette.textMuted
elide: Text.ElideMiddle
@ -79,8 +79,8 @@ ItemDelegate {
Layout.preferredHeight: 40
Layout.preferredWidth: 40
onCopyText: model.isPublic
? root.copyRequested(Base58.encode(model.address ?? ""))
: root.copyPublicKeysRequested(model.address ?? "")
? root.copyRequested(Base58.encode(model.accountId ?? ""))
: root.copyPublicKeysRequested(model.accountId ?? "")
visible: addressLabel.text
icon.color: Theme.palette.textMuted
}

View File

@ -64,7 +64,7 @@ Popup {
LogosText {
text: tabBar.currentIndex === 0
? qsTr("Address visible. Balance on-chain.")
? qsTr("Account ID visible. Balance on-chain.")
: qsTr("Private balance and activity.")
font.pixelSize: Theme.typography.secondaryText
color: Theme.palette.textSecondary

View File

@ -107,7 +107,7 @@ Rectangle {
LogosTextField {
id: manualFromField
Layout.fillWidth: true
placeholderText: qsTr("Paste or type from address")
placeholderText: qsTr("Paste or type from account ID")
visible: fromFilterCount === 0
}
@ -142,7 +142,7 @@ Rectangle {
LogosTextField {
id: toField
Layout.fillWidth: true
placeholderText: (d.isPublicTab || d.isDeshieldedTab) ? qsTr("Recipient address") : qsTr("Recipient private keys (JSON)")
placeholderText: (d.isPublicTab || d.isDeshieldedTab) ? qsTr("Recipient account ID") : qsTr("Recipient public keys (JSON)")
visible: !d.useOwnedAccountForTo
}