From 99c113c82901c94e662953f3c5c0d821d1ef2003 Mon Sep 17 00:00:00 2001 From: Dario Gabriel Lipicar Date: Wed, 1 Nov 2023 16:13:50 -0300 Subject: [PATCH] feat: implement generalized collectibles filter Closes #12520 --- .../wallet/accounts/module.nim | 2 +- .../modules/main/wallet_section/module.nim | 2 +- .../main/wallet_section/send/module.nim | 2 +- .../collectibles/controller.nim | 15 +++++-- src/backend/collectibles.nim | 42 +++++++++++++++++++ vendor/status-go | 2 +- 6 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/app/modules/main/profile_section/wallet/accounts/module.nim b/src/app/modules/main/profile_section/wallet/accounts/module.nim index 2da9862242..dda0190d5b 100644 --- a/src/app/modules/main/profile_section/wallet/accounts/module.nim +++ b/src/app/modules/main/profile_section/wallet/accounts/module.nim @@ -128,7 +128,7 @@ method refreshWalletAccounts*(self: Module) = let ownedWalletAccounts = walletAccounts.filter(a => a.walletType != WalletTypeWatch) let ownedWalletAccountAddresses = ownedWalletAccounts.map(a => a.address) let enabledNetworks = self.controller.getEnabledChainIds() - self.collectiblesController.globalFilterChanged(ownedWalletAccountAddresses, enabledNetworks) + self.collectiblesController.setFilterAddressesAndChains(ownedWalletAccountAddresses, enabledNetworks) method load*(self: Module) = self.events.on(SIGNAL_KEYPAIR_SYNCED) do(e: Args): diff --git a/src/app/modules/main/wallet_section/module.nim b/src/app/modules/main/wallet_section/module.nim index 238632118c..cab75374d3 100644 --- a/src/app/modules/main/wallet_section/module.nim +++ b/src/app/modules/main/wallet_section/module.nim @@ -175,7 +175,7 @@ method notifyFilterChanged(self: Module) = self.accountsModule.filterChanged(self.filter.addresses, self.filter.chainIds) self.sendModule.filterChanged(self.filter.addresses, self.filter.chainIds) self.activityController.globalFilterChanged(self.filter.addresses, self.filter.allAddresses, self.filter.chainIds, self.filter.allChainsEnabled) - self.collectiblesController.globalFilterChanged(self.filter.addresses, self.filter.chainIds) + self.collectiblesController.setFilterAddressesAndChains(self.filter.addresses, self.filter.chainIds) if self.filter.addresses.len > 0: self.view.filterChanged(self.filter.addresses[0], self.filter.allAddresses) diff --git a/src/app/modules/main/wallet_section/send/module.nim b/src/app/modules/main/wallet_section/send/module.nim index b67b81addd..9e90e17ab4 100644 --- a/src/app/modules/main/wallet_section/send/module.nim +++ b/src/app/modules/main/wallet_section/send/module.nim @@ -356,7 +356,7 @@ method filterChanged*(self: Module, addresses: seq[string], chainIds: seq[int]) proc updateCollectiblesFilter*(self: Module) = let addresses = @[self.view.getSenderAddressByIndex(self.senderCurrentAccountIndex)] let chainIds = self.controller.getChainIds() - self.collectiblesController.globalFilterChanged(addresses, chainIds) + self.collectiblesController.setFilterAddressesAndChains(addresses, chainIds) method setSelectedSenderAccountIndex*(self: Module, index: int) = self.senderCurrentAccountIndex = index diff --git a/src/app/modules/shared_modules/collectibles/controller.nim b/src/app/modules/shared_modules/collectibles/controller.nim index a8a27c1d86..131e70ed70 100644 --- a/src/app/modules/shared_modules/collectibles/controller.nim +++ b/src/app/modules/shared_modules/collectibles/controller.nim @@ -22,6 +22,7 @@ QtObject: addresses: seq[string] chainIds: seq[int] + filter: backend_collectibles.CollectibleFilter ownershipStatus: Table[string, Table[int, OwnershipStatus]] # Table[address][chainID] -> OwnershipStatus @@ -43,7 +44,6 @@ QtObject: QtProperty[QVariant] model: read = getModelAsVariant - proc checkModelState(self: Controller) = var overallState = OwnershipStateIdle @@ -112,7 +112,7 @@ QtObject: offset = self.model.getCollectiblesCount() self.fetchFromStart = false - let response = backend_collectibles.filterOwnedCollectiblesAsync(self.requestId, self.chainIds, self.addresses, offset, FETCH_BATCH_COUNT_DEFAULT) + let response = backend_collectibles.filterOwnedCollectiblesAsync(self.requestId, self.chainIds, self.addresses, self.filter, offset, FETCH_BATCH_COUNT_DEFAULT) if response.error != nil: self.model.setIsFetching(false) self.model.setIsError(true) @@ -184,6 +184,7 @@ QtObject: result.addresses = @[] result.chainIds = @[] + result.filter = backend_collectibles.newCollectibleFilterAllEntries() result.setup() @@ -191,7 +192,7 @@ QtObject: signalConnect(result.model, "loadMoreItems()", result, "loadMoreItems()") - proc globalFilterChanged*(self: Controller, addresses: seq[string], chainIds: seq[int]) = + proc setFilterAddressesAndChains*(self: Controller, addresses: seq[string], chainIds: seq[int]) = if chainIds == self.chainIds and addresses == self.addresses: return @@ -204,6 +205,14 @@ QtObject: self.eventsHandler.updateSubscribedChainIDs(self.chainIds) self.resetModel() + + proc setFilter*(self: Controller, filter: backend_collectibles.CollectibleFilter) = + if filter == self.filter: + return + + self.filter = filter + + self.resetModel() proc getActivityToken*(self: Controller, id: string): backend_activity.Token = return self.model.getActivityToken(id) \ No newline at end of file diff --git a/src/backend/collectibles.nim b/src/backend/collectibles.nim index 59d01e4690..68c75ec1ea 100644 --- a/src/backend/collectibles.nim +++ b/src/backend/collectibles.nim @@ -61,6 +61,17 @@ type CommunityCollectiblesReceivedPayload* = object collectibles*: seq[CommunityCollectibleHeader] + # see status-go/services/wallet/collectibles/filter.go FilterCommunityType + FilterCommunityType* {.pure.} = enum + All, OnlyNonCommunity, OnlyCommunity + + # see status-go/services/wallet/collectibles/filter.go Filter + # All empty sequences mean include all + CollectibleFilter* = object + communityIds*: seq[string] + communityPrivilegesLevels*: seq[int] + filterCommunity*: FilterCommunityType + # CollectibleOwnershipState proc `$`*(self: OwnershipStatus): string = return fmt"""OwnershipStatus( @@ -74,6 +85,36 @@ proc fromJson*(t: JsonNode, T: typedesc[OwnershipStatus]): OwnershipStatus {.inl timestamp: t{"timestamp"}.getInt ) +# CollectibleFilter +proc newCollectibleFilterAllCommunityIds*(): seq[string] {.inline.} = + return @[] + +proc newCollectibleFilterAllCommunityPrivilegesLevels*(): seq[int] {.inline.} = + return @[] + +proc newCollectibleFilterAllEntries*(): CollectibleFilter {.inline.} = + return CollectibleFilter( + communityIds: newCollectibleFilterAllCommunityIds(), + communityPrivilegesLevels: newCollectibleFilterAllCommunityPrivilegesLevels(), + filterCommunity: FilterCommunityType.All + ) + +proc `$`*(self: CollectibleFilter): string = + return fmt"""CollectibleFilter( + communityIds:{self.communityIds}, + communityPrivilegesLevels:{self.communityPrivilegesLevels}, + filterCommunity:{self.filterCommunity} + """ + +proc `%`*(t: CollectibleFilter): JsonNode {.inline.} = + result = newJObject() + result["community_ids"] = %(t.communityIds) + result["community_privileges_levels"] = %(t.communityPrivilegesLevels) + result["filter_community"] = %(t.filterCommunity.int) + +proc `%`*(t: ref CollectibleFilter): JsonNode {.inline.} = + return %(t[]) + # Responses proc fromJson*(e: JsonNode, T: typedesc[FilterOwnedCollectiblesResponse]): FilterOwnedCollectiblesResponse {.inline.} = var collectibles: seq[CollectibleHeader] @@ -146,6 +187,7 @@ rpc(filterOwnedCollectiblesAsync, "wallet"): requestId: int32 chainIDs: seq[int] addresses: seq[string] + filter: CollectibleFilter offset: int limit: int diff --git a/vendor/status-go b/vendor/status-go index eb437e9d8d..9f69c32593 160000 --- a/vendor/status-go +++ b/vendor/status-go @@ -1 +1 @@ -Subproject commit eb437e9d8dd5bd1ca3b18fa05c4853d6ae8f4956 +Subproject commit 9f69c3259397821483bad722ab92eb52470185de