mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-16 16:47:24 +00:00
fix: fake collections shouldn't be visible in a filtering combo
teach the model about the special cased self-collections containing just one single collectible item; we need that for the "Arrange by collection" token mgmt feature but in all other cases it shouldn't be treated as a collection/group Fixes #13281
This commit is contained in:
parent
3b99bcb29a
commit
f2482ab003
@ -344,6 +344,12 @@ void ManageTokensController::settingsHideGroupTokens(const QString& groupId, con
|
||||
m_settingsData.insert(symbol, {0, false, groupId});
|
||||
}
|
||||
|
||||
if (!m_hiddenCommunityGroups.contains(groupId)) {
|
||||
m_hiddenCommunityGroups.insert(groupId);
|
||||
emit hiddenCommunityGroupsChanged();
|
||||
rebuildHiddenCommunityTokenGroupsModel();
|
||||
}
|
||||
|
||||
saveSettings(true);
|
||||
}
|
||||
|
||||
@ -491,6 +497,7 @@ void ManageTokensController::addItem(int index)
|
||||
token.communityName = !communityName.isEmpty() ? communityName : communityId;
|
||||
token.communityImage = dataForIndex(srcIndex, kCommunityImageRoleName).toString();
|
||||
token.collectionUid = !collectionUid.isEmpty() ? collectionUid : symbol;
|
||||
token.isSelfCollection = collectionUid.isEmpty();
|
||||
token.collectionName = dataForIndex(srcIndex, kCollectionNameRoleName).toString();
|
||||
token.balance = dataForIndex(srcIndex, kEnabledNetworkBalanceRoleName);
|
||||
token.currencyBalance = dataForIndex(srcIndex, kEnabledNetworkCurrencyBalanceRoleName);
|
||||
@ -647,7 +654,8 @@ void ManageTokensController::rebuildCollectionGroupsModel()
|
||||
const auto count = m_regularTokensModel->count();
|
||||
for (auto i = 0; i < count; i++) {
|
||||
const auto& collectionToken = m_regularTokensModel->itemAt(i);
|
||||
auto collectionId = collectionToken.collectionUid;
|
||||
const auto collectionId = collectionToken.collectionUid;
|
||||
const auto isSelfCollection = collectionToken.isSelfCollection;
|
||||
if (!collectionIds.contains(collectionId)) { // insert into groups
|
||||
collectionIds.append(collectionId);
|
||||
|
||||
@ -655,11 +663,12 @@ void ManageTokensController::rebuildCollectionGroupsModel()
|
||||
|
||||
TokenData tokenGroup;
|
||||
tokenGroup.collectionUid = collectionId;
|
||||
tokenGroup.isSelfCollection = isSelfCollection;
|
||||
tokenGroup.collectionName = collectionName;
|
||||
tokenGroup.image = collectionToken.image;
|
||||
tokenGroup.balance = 1;
|
||||
result.append(tokenGroup);
|
||||
} else { // update group's childCount
|
||||
} else if (!isSelfCollection) { // update group's childCount
|
||||
const auto tokenGroup = std::find_if(result.cbegin(), result.cend(), [collectionId](const auto& item) {
|
||||
return collectionId == item.collectionUid;
|
||||
});
|
||||
@ -686,7 +695,8 @@ void ManageTokensController::rebuildHiddenCollectionGroupsModel()
|
||||
const auto count = m_hiddenTokensModel->count();
|
||||
for (auto i = 0; i < count; i++) {
|
||||
const auto& collectionToken = m_hiddenTokensModel->itemAt(i);
|
||||
auto collectionId = collectionToken.collectionUid;
|
||||
const auto collectionId = collectionToken.collectionUid;
|
||||
const auto isSelfCollection = collectionToken.isSelfCollection;
|
||||
if (!collectionIds.contains(collectionId) && m_hiddenCollectionGroups.contains(collectionId)) { // insert into groups
|
||||
collectionIds.append(collectionId);
|
||||
|
||||
@ -694,11 +704,12 @@ void ManageTokensController::rebuildHiddenCollectionGroupsModel()
|
||||
|
||||
TokenData tokenGroup;
|
||||
tokenGroup.collectionUid = collectionId;
|
||||
tokenGroup.isSelfCollection = isSelfCollection;
|
||||
tokenGroup.collectionName = collectionName;
|
||||
tokenGroup.image = collectionToken.image;
|
||||
tokenGroup.balance = 1;
|
||||
result.append(tokenGroup);
|
||||
} else { // update group's childCount
|
||||
} else if (!isSelfCollection) { // update group's childCount
|
||||
const auto tokenGroup = std::find_if(result.cbegin(), result.cend(), [collectionId](const auto& item) {
|
||||
return collectionId == item.collectionUid;
|
||||
});
|
||||
|
@ -122,7 +122,8 @@ QHash<int, QByteArray> ManageTokensModel::roleNames() const
|
||||
{TokenBackgroundColorRole, kBackgroundColorRoleName},
|
||||
{TokenBalancesRole, kBalancesRoleName},
|
||||
{TokenDecimalsRole, kDecimalsRoleName},
|
||||
{TokenMarketDetailsRole, kMarketDetailsRoleName}
|
||||
{TokenMarketDetailsRole, kMarketDetailsRoleName},
|
||||
{IsSelfCollectionRole, kIsSelfCollectionRoleName},
|
||||
};
|
||||
|
||||
return roles;
|
||||
@ -152,6 +153,7 @@ QVariant ManageTokensModel::data(const QModelIndex& index, int role) const
|
||||
case TokenBalancesRole: return token.balances;
|
||||
case TokenDecimalsRole: return token.decimals;
|
||||
case TokenMarketDetailsRole: return token.marketDetails;
|
||||
case IsSelfCollectionRole: return token.isSelfCollection;
|
||||
}
|
||||
|
||||
return {};
|
||||
|
@ -26,6 +26,7 @@ const auto kBackgroundColorRoleName = QByteArrayLiteral("backgroundColor");
|
||||
const auto kBalancesRoleName = QByteArrayLiteral("balances");
|
||||
const auto kDecimalsRoleName = QByteArrayLiteral("decimals");
|
||||
const auto kMarketDetailsRoleName = QByteArrayLiteral("marketDetails");
|
||||
const auto kIsSelfCollectionRoleName = QByteArrayLiteral("isSelfCollection");
|
||||
// TODO add communityPrivilegesLevel for collectibles
|
||||
} // namespace
|
||||
|
||||
@ -35,6 +36,7 @@ struct TokenData {
|
||||
QVariant balance, currencyBalance;
|
||||
QVariant balances, marketDetails, decimals;
|
||||
int customSortOrderNo{INT_MAX};
|
||||
bool isSelfCollection{false};
|
||||
};
|
||||
|
||||
// symbol -> {sortOrder, visible, groupId}
|
||||
@ -63,6 +65,7 @@ public:
|
||||
TokenBalancesRole,
|
||||
TokenDecimalsRole,
|
||||
TokenMarketDetailsRole,
|
||||
IsSelfCollectionRole,
|
||||
};
|
||||
Q_ENUM(TokenDataRoles)
|
||||
|
||||
|
@ -88,6 +88,14 @@ ComboBox {
|
||||
return model.groupName.toLowerCase().includes(d.searchTextLowerCase) || model.groupId.toLowerCase().includes(d.searchTextLowerCase)
|
||||
}
|
||||
expectedRoles: ["groupName", "groupId"]
|
||||
},
|
||||
FastExpressionFilter {
|
||||
expression: {
|
||||
if (model.sourceGroup === "collection")
|
||||
return !model.isSelfCollection
|
||||
return true
|
||||
}
|
||||
expectedRoles: ["sourceGroup", "isSelfCollection"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -95,8 +103,8 @@ ComboBox {
|
||||
readonly property var uncategorizedModel: SortFilterProxyModel { // regular collectibles with no collection
|
||||
sourceModel: root.regularTokensModel
|
||||
filters: ValueFilter {
|
||||
roleName: "collectionUid"
|
||||
value: ""
|
||||
roleName: "isSelfCollection"
|
||||
value: true
|
||||
}
|
||||
onCountChanged: if (!count) d.removeFilter("") // different underlying model -> uncheck
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ StatusFlatButton {
|
||||
// any token
|
||||
StatusAction {
|
||||
objectName: "miHideToken"
|
||||
enabled: !root.inHidden && root.hideEnabled && !root.isGroup && !root.isCommunityToken && !root.isCollectible
|
||||
enabled: !root.inHidden && root.hideEnabled && !root.isGroup && !root.isCommunityToken && !root.groupId
|
||||
type: StatusAction.Type.Danger
|
||||
icon.name: "hide"
|
||||
text: root.isCollectible ? qsTr("Hide collectible") : qsTr("Hide asset")
|
||||
@ -122,7 +122,7 @@ StatusFlatButton {
|
||||
// (hide) collection tokens
|
||||
StatusMenu {
|
||||
id: collectionSubmenu
|
||||
enabled: !root.inHidden && root.isCollectible && !root.isCommunityToken && !root.isGroup
|
||||
enabled: !root.inHidden && root.isCollectible && !root.isCommunityToken && !root.isGroup && root.groupId
|
||||
title: qsTr("Hide")
|
||||
assetSettings.name: "hide"
|
||||
type: StatusAction.Type.Danger
|
||||
|
@ -99,9 +99,10 @@ DropArea {
|
||||
currentIndex: root.visualIndex
|
||||
count: root.count
|
||||
inHidden: root.isHidden
|
||||
groupId: model.communityId || model.collectionUid
|
||||
groupId: isCollection ? model.collectionUid : model.communityId
|
||||
isCommunityToken: root.isCommunityToken
|
||||
isCollectible: root.isCollectible
|
||||
isCollection: isCollectible && !model.isSelfCollection
|
||||
onMoveRequested: (from, to) => root.ListView.view.model.moveItem(from, to)
|
||||
onShowHideRequested: function(symbol, flag) {
|
||||
if (isCommunityToken)
|
||||
|
Loading…
x
Reference in New Issue
Block a user