From 224dd5e58d9fbd886cf16aceb6e1fec9d5693993 Mon Sep 17 00:00:00 2001 From: Cuteivist Date: Tue, 20 Aug 2024 06:02:14 +0200 Subject: [PATCH] fix(wallet): Filter collectibles filter options (#16125) --- .../src/wallet/managetokenscontroller.cpp | 8 ++++ .../Wallet/controls/FilterComboBox.qml | 38 +++++++++++++++++-- .../Wallet/views/CollectiblesView.qml | 34 +++++++++++++++-- 3 files changed, 73 insertions(+), 7 deletions(-) diff --git a/ui/StatusQ/src/wallet/managetokenscontroller.cpp b/ui/StatusQ/src/wallet/managetokenscontroller.cpp index a87b992ca4..bc3f167593 100644 --- a/ui/StatusQ/src/wallet/managetokenscontroller.cpp +++ b/ui/StatusQ/src/wallet/managetokenscontroller.cpp @@ -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; diff --git a/ui/app/AppLayouts/Wallet/controls/FilterComboBox.qml b/ui/app/AppLayouts/Wallet/controls/FilterComboBox.qml index d3ed69ab94..0a85b2c05c 100644 --- a/ui/app/AppLayouts/Wallet/controls/FilterComboBox.qml +++ b/ui/app/AppLayouts/Wallet/controls/FilterComboBox.qml @@ -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"] } ] } diff --git a/ui/app/AppLayouts/Wallet/views/CollectiblesView.qml b/ui/app/AppLayouts/Wallet/views/CollectiblesView.qml index 2439ef0812..e5f7c650a3 100644 --- a/ui/app/AppLayouts/Wallet/views/CollectiblesView.qml +++ b/ui/app/AppLayouts/Wallet/views/CollectiblesView.qml @@ -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