Skip to content

Commit

Permalink
fix(wallet): Filter collectibles filter options (#16125)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuteivist authored Aug 20, 2024
1 parent 3bef204 commit 224dd5e
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 7 deletions.
8 changes: 8 additions & 0 deletions ui/StatusQ/src/wallet/managetokenscontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
38 changes: 34 additions & 4 deletions ui/app/AppLayouts/Wallet/controls/FilterComboBox.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -68,27 +74,44 @@ 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 {
enabled: d.searchTextLowerCase !== ""
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: {
Expand All @@ -97,6 +120,13 @@ ComboBox {
return true
}
expectedRoles: ["sourceGroup", "isSelfCollection"]
},
FastExpressionFilter {
expression: {
d.sourceModelTracker.revision
return combinedProxyModel.containsCollectible(model.groupId)
}
expectedRoles: ["groupId"]
}
]
}
Expand Down
34 changes: 31 additions & 3 deletions ui/app/AppLayouts/Wallet/views/CollectiblesView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 224dd5e

Please sign in to comment.