From 2565c8a135c975b63dc2e5fe6427081591b403ae Mon Sep 17 00:00:00 2001 From: Cuteivist Date: Wed, 15 May 2024 11:14:46 +0200 Subject: [PATCH] fix(wallet): Show community name in tag (#14622) --- .../shared_models/collectibles_model.nim | 15 ------- .../AppLayouts/Profile/stores/WalletStore.qml | 39 +++++++++++++++++- .../controls/ManageTokensCommunityTag.qml | 3 +- .../Wallet/stores/CollectiblesStore.qml | 41 ++++++++++++++++++- .../views/collectibles/CollectibleView.qml | 1 - 5 files changed, 79 insertions(+), 20 deletions(-) diff --git a/src/app/modules/shared_models/collectibles_model.nim b/src/app/modules/shared_models/collectibles_model.nim index 6139f0a491..7232c6d71a 100644 --- a/src/app/modules/shared_models/collectibles_model.nim +++ b/src/app/modules/shared_models/collectibles_model.nim @@ -22,10 +22,7 @@ type Ownership # Community-related roles CommunityId - CommunityName - CommunityColor CommunityPrivilegesLevel - CommunityImage TokenType Soulbound @@ -145,10 +142,7 @@ QtObject: CollectibleRole.IsLoading.int:"isLoading", CollectibleRole.Ownership.int:"ownership", CollectibleRole.CommunityId.int:"communityId", - CollectibleRole.CommunityName.int:"communityName", - CollectibleRole.CommunityColor.int:"communityColor", CollectibleRole.CommunityPrivilegesLevel.int:"communityPrivilegesLevel", - CollectibleRole.CommunityImage.int:"communityImage", CollectibleRole.TokenType.int:"tokenType", CollectibleRole.Soulbound.int:"soulbound" }.toTable @@ -195,14 +189,8 @@ QtObject: result = item.getOwnershipModelAsVariant() of CollectibleRole.CommunityId: result = newQVariant(item.getCommunityId()) - of CollectibleRole.CommunityName: - result = newQVariant(item.getCommunityName()) - of CollectibleRole.CommunityColor: - result = newQVariant(item.getCommunityColor()) of CollectibleRole.CommunityPrivilegesLevel: result = newQVariant(item.getCommunityPrivilegesLevel()) - of CollectibleRole.CommunityImage: - result = newQVariant(item.getCommunityImage()) of CollectibleRole.TokenType: result = newQVariant(item.getTokenType()) of CollectibleRole.Soulbound: @@ -227,10 +215,7 @@ QtObject: of "collectionSlug": result = item.getCollectionSlug() of "isLoading": result = $false of "communityId": result = item.getCommunityID() - of "communityName": result = item.getCommunityName() - of "communityColor": result = item.getCommunityColor() of "communityPrivilegesLevel": result = $item.getCommunityPrivilegesLevel() - of "communityImage": result = item.getCommunityImage() proc resetCollectibleItems(self: Model, newItems: seq[CollectiblesEntry] = @[]) = self.beginResetModel() diff --git a/ui/app/AppLayouts/Profile/stores/WalletStore.qml b/ui/app/AppLayouts/Profile/stores/WalletStore.qml index 7d309d2ba5..488583ec85 100644 --- a/ui/app/AppLayouts/Profile/stores/WalletStore.qml +++ b/ui/app/AppLayouts/Profile/stores/WalletStore.qml @@ -3,6 +3,7 @@ import QtQuick 2.13 import utils 1.0 import StatusQ 0.1 +import StatusQ.Models 0.1 import StatusQ.Core.Utils 0.1 import SortFilterProxyModel 0.2 @@ -13,7 +14,7 @@ QtObject { property var walletModule property var accountsModule: root.walletModule.accountsModule property var networksModuleInst: networksModule - property var collectibles: root.walletModule.collectiblesModel + property var collectibles: _jointCollectiblesBySymbolModel property var accountSensitiveSettings: Global.appIsReady? localAccountSensitiveSettings : null property var dappList: Global.appIsReady? dappPermissionsModule.dapps : null @@ -56,6 +57,42 @@ QtObject { } } + /* PRIVATE: This model renames the roles + 1. "id" to "communityId" + 2. "name" to "communityName" + 3. "image" to "communityImage" + 4. "description" to "communityDescription" + in communitiesModule.model so that it can be easily + joined with the Collectibles model */ + readonly property var _renamedCommunitiesModel: RolesRenamingModel { + sourceModel: communitiesModule.model + mapping: [ + RoleRename { + from: "id" + to: "communityId" + }, + RoleRename { + from: "name" + to: "communityName" + }, + RoleRename { + from: "image" + to: "communityImage" + }, + RoleRename { + from: "description" + to: "communityDescription" + } + ] + } + + /* PRIVATE: This model joins the "Tokens By Symbol Model" and "Communities Model" by communityId */ + property LeftJoinModel _jointCollectiblesBySymbolModel: LeftJoinModel { + leftModel: root.walletModule.collectiblesModel + rightModel: _renamedCommunitiesModel + joinRole: "communityId" + } + property string userProfilePublicKey: userProfile.pubKey function deleteAccount(address) { diff --git a/ui/app/AppLayouts/Wallet/controls/ManageTokensCommunityTag.qml b/ui/app/AppLayouts/Wallet/controls/ManageTokensCommunityTag.qml index 1b313dd8b2..306a840e4b 100644 --- a/ui/app/AppLayouts/Wallet/controls/ManageTokensCommunityTag.qml +++ b/ui/app/AppLayouts/Wallet/controls/ManageTokensCommunityTag.qml @@ -19,7 +19,6 @@ Control { property string communityId property var communityImage property bool loading - property bool useLongTextDescription: true property Component customBackground: Component { Rectangle { @@ -53,7 +52,7 @@ Control { Layout.preferredHeight: visible ? asset.width : 0 asset.width: 16 asset.height: 16 - visible: root.useLongTextDescription && !!asset.source + visible: !d.unknownCommunityName && !!asset.source Component.onCompleted: { updateCommunityImage() diff --git a/ui/app/AppLayouts/Wallet/stores/CollectiblesStore.qml b/ui/app/AppLayouts/Wallet/stores/CollectiblesStore.qml index 71c3394737..ca98cd584f 100644 --- a/ui/app/AppLayouts/Wallet/stores/CollectiblesStore.qml +++ b/ui/app/AppLayouts/Wallet/stores/CollectiblesStore.qml @@ -5,6 +5,8 @@ import StatusQ.Models 0.1 import utils 1.0 +import SortFilterProxyModel 0.2 + QtObject { id: root @@ -27,7 +29,7 @@ QtObject { } readonly property var collectiblesController: ManageTokensController { - sourceModel: allCollectiblesModel + sourceModel: _jointCollectiblesBySymbolModel settingsKey: "WalletCollectibles" serializeAsCollectibles: true @@ -51,6 +53,43 @@ QtObject { qsTr("%1 community collectibles are now visible").arg(communityName), "", "checkmark-circle", false, Constants.ephemeralNotificationType.success, "") } + + /* PRIVATE: This model renames the roles + 1. "id" to "communityId" + 2. "name" to "communityName" + 3. "image" to "communityImage" + 4. "description" to "communityDescription" + in communitiesModule.model so that it can be easily + joined with the Collectibles model */ + readonly property var _renamedCommunitiesModel: RolesRenamingModel { + sourceModel: communitiesModule.model + mapping: [ + RoleRename { + from: "id" + to: "communityId" + }, + RoleRename { + from: "name" + to: "communityName" + }, + RoleRename { + from: "image" + to: "communityImage" + }, + RoleRename { + from: "description" + to: "communityDescription" + } + ] + } + + /* PRIVATE: This model joins the "Tokens By Symbol Model" and "Communities Model" by communityId */ + property LeftJoinModel _jointCollectiblesBySymbolModel: LeftJoinModel { + leftModel: allCollectiblesModel + rightModel: _renamedCommunitiesModel + joinRole: "communityId" + } + readonly property bool areCollectiblesFetching: !!root._allCollectiblesModel ? root._allCollectiblesModel.isFetching : true readonly property bool areCollectiblesUpdating: !!root._allCollectiblesModel ? root._allCollectiblesModel.isUpdating : false readonly property bool areCollectiblesError: !!root._allCollectiblesModel ? root._allCollectiblesModel.isError : false diff --git a/ui/app/AppLayouts/Wallet/views/collectibles/CollectibleView.qml b/ui/app/AppLayouts/Wallet/views/collectibles/CollectibleView.qml index 4faa0da4ec..0d70b8ec3e 100644 --- a/ui/app/AppLayouts/Wallet/views/collectibles/CollectibleView.qml +++ b/ui/app/AppLayouts/Wallet/views/collectibles/CollectibleView.qml @@ -189,7 +189,6 @@ Control { communityImage: root.communityImage visible: root.isCommunityCollectible enabled: !root.isLoading - useLongTextDescription: false TapHandler { enabled: !d.unknownCommunityName