fix(wallet): Filter collectibles filter options (#16125)

This commit is contained in:
Cuteivist 2024-08-20 06:02:14 +02:00 committed by GitHub
parent 3bef20401f
commit 224dd5e58d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 73 additions and 7 deletions

View File

@ -494,9 +494,13 @@ void ManageTokensController::rebuildCommunityTokenGroupsModel()
if (!communityIds.contains(communityId)) { // insert into groups
communityIds.append(communityId);
const auto collectionName =
!communityToken.collectionName.isEmpty() ? communityToken.collectionName : communityToken.name;
TokenData tokenGroup;
tokenGroup.symbol = communityId;
tokenGroup.communityId = communityId;
tokenGroup.collectionName = collectionName;
tokenGroup.communityName = communityToken.communityName;
tokenGroup.communityImage = communityToken.communityImage;
tokenGroup.backgroundColor = communityToken.backgroundColor;
@ -551,9 +555,13 @@ void ManageTokensController::rebuildHiddenCommunityTokenGroupsModel()
m_hiddenCommunityGroups.contains(communityId)) { // insert into groups
communityIds.append(communityId);
const auto collectionName =
!communityToken.collectionName.isEmpty() ? communityToken.collectionName : communityToken.name;
TokenData tokenGroup;
tokenGroup.symbol = communityId;
tokenGroup.communityId = communityId;
tokenGroup.collectionName = collectionName;
tokenGroup.communityName = communityToken.communityName;
tokenGroup.communityImage = communityToken.communityImage;
tokenGroup.backgroundColor = communityToken.backgroundColor;

View File

@ -5,6 +5,7 @@ import QtGraphicalEffects 1.15
import StatusQ 0.1
import StatusQ.Core 0.1
import StatusQ.Core.Utils 0.1 as SQUtils
import StatusQ.Controls 0.1
import StatusQ.Components 0.1
import StatusQ.Components.private 0.1 as SQP
@ -19,6 +20,7 @@ import SortFilterProxyModel 0.2
ComboBox {
id: root
required property var sourceModel // filtered source model
required property var regularTokensModel // "uncategorized" collectibles (not grouped)
required property var collectionGroupsModel // collection groups
required property var communityTokenGroupsModel // community groups
@ -51,6 +53,10 @@ ComboBox {
readonly property string searchTextLowerCase: searchBox.input.text.toLowerCase()
readonly property SQUtils.ModelChangeTracker sourceModelTracker: SQUtils.ModelChangeTracker {
model: root.sourceModel
}
readonly property var combinedModel: ConcatModel {
sources: [
SourceModel {
@ -68,18 +74,34 @@ ComboBox {
}
readonly property var combinedProxyModel: SortFilterProxyModel {
id: combinedProxyModel
sourceModel: d.combinedModel
readonly property var containsCollectible: (groupId) => SQUtils.ModelUtils.indexOf(root.sourceModel, "communityId", groupId) >= 0
|| SQUtils.ModelUtils.indexOf(root.sourceModel, "collectionUid", groupId) >= 0
proxyRoles: [
JoinRole {
FastExpressionRole {
name: "groupName"
roleNames: ["collectionName", "communityName"]
separator: ""
expression: {
if (!!model.communityId) {
if (model.communityName === model.communityId && !!model.collectionName)
return model.collectionName
return model.communityName
}
return model.collectionName
}
expectedRoles: ["communityId", "collectionName", "communityName"]
},
FastExpressionRole {
name: "groupKey"
expression: !!model.communityId ? model.communityName : model.collectionName
expectedRoles: ["communityId", "collectionName", "communityName"]
},
JoinRole {
name: "groupId"
roleNames: ["collectionUid", "communityId"]
separator: ""
}
]
filters: [
FastExpressionFilter {
@ -87,8 +109,9 @@ ComboBox {
expression: {
d.searchTextLowerCase // ensure expression is reevaluated when searchString changes
return model.groupName.toLowerCase().includes(d.searchTextLowerCase) || model.groupId.toLowerCase().includes(d.searchTextLowerCase)
|| model.groupKey.toLowerCase().includes(d.searchTextLowerCase)
}
expectedRoles: ["groupName", "groupId"]
expectedRoles: ["groupName", "groupId", "groupKey"]
},
FastExpressionFilter {
expression: {
@ -97,6 +120,13 @@ ComboBox {
return true
}
expectedRoles: ["sourceGroup", "isSelfCollection"]
},
FastExpressionFilter {
expression: {
d.sourceModelTracker.revision
return combinedProxyModel.containsCollectible(model.groupId)
}
expectedRoles: ["groupId"]
}
]
}

View File

@ -234,9 +234,10 @@ ColumnLayout {
sourceModel: d.sourceModel
proxyRoles: [
JoinRole {
FastExpressionRole {
name: "groupName"
roleNames: ["collectionName", "communityName"]
expression: !!model.communityId ? model.communityName : model.collectionName
expectedRoles: ["communityId", "collectionName", "communityName"]
},
FastExpressionRole {
name: "balance"
@ -306,7 +307,7 @@ ColumnLayout {
Settings {
id: settings
category: "CollectiblesViewSortSettings"
category: "CollectiblesViewSortSettings-" + root.addressFilters
property int currentSortValue: SortOrderComboBox.TokenOrderDateAdded
property alias currentSortOrder: cmbTokenOrder.currentSortOrder
property alias selectedFilterGroupIds: cmbFilter.selectedFilterGroupIds
@ -336,6 +337,33 @@ ColumnLayout {
FilterComboBox {
id: cmbFilter
sourceModel: SortFilterProxyModel {
sourceModel: d.sourceModel
proxyRoles: [
FastExpressionRole {
name: "balance"
expression: {
d.addrFilters
return d.getBalance(model.ownership, d.addrFilters)
}
expectedRoles: ["ownership"]
}
]
filters: [
FastExpressionFilter {
expression: {
return d.nwFilters.includes(model.chainId+"")
}
expectedRoles: ["chainId"]
},
ValueFilter {
roleName: "balance"
value: 0
inverted: true
}
]
}
regularTokensModel: root.controller.regularTokensModel
collectionGroupsModel: root.controller.collectionGroupsModel
communityTokenGroupsModel: root.controller.communityTokenGroupsModel