From aa2b90ec4cbd27c9e924428990e26e441237438c Mon Sep 17 00:00:00 2001 From: Mikhail Rogachev Date: Wed, 3 Apr 2024 11:51:15 +0200 Subject: [PATCH] fix(Profile): Fix crashing when showcase collectible having disabled chainIds (#14252) Close #14243 (cherry picked from commit d86be3a970892391280e1e93ea07ca7fc6ba0a04) --- .../main/profile_section/contacts/controller.nim | 4 ++-- .../main/profile_section/contacts/module.nim | 13 ++++++++----- src/app_service/common/utils.nim | 7 +++++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/app/modules/main/profile_section/contacts/controller.nim b/src/app/modules/main/profile_section/contacts/controller.nim index ddf548d6c3..3c6f7093cd 100644 --- a/src/app/modules/main/profile_section/contacts/controller.nim +++ b/src/app/modules/main/profile_section/contacts/controller.nim @@ -204,5 +204,5 @@ proc requestProfileShowcaseForContact*(self: Controller, contactId: string, vali proc fetchProfileShowcaseAccountsByAddress*(self: Controller, address: string) = self.contactsService.fetchProfileShowcaseAccountsByAddress(address) -proc getChainIds*(self: Controller): seq[int] = - self.networkService.getNetworks().map(n => n.chainId) \ No newline at end of file +proc getEnabledChainIds*(self: Controller): seq[int] = + return self.networkService.getNetworks().filter(n => n.enabled).map(n => n.chainId) diff --git a/src/app/modules/main/profile_section/contacts/module.nim b/src/app/modules/main/profile_section/contacts/module.nim index 4edb12a47f..1417cff846 100644 --- a/src/app/modules/main/profile_section/contacts/module.nim +++ b/src/app/modules/main/profile_section/contacts/module.nim @@ -8,6 +8,7 @@ import ../../../../global/global_singleton import ../../../../core/eventemitter import app_service/common/types +import app_service/common/utils as utils import app_service/service/contacts/dto/contacts as contacts_dto import app_service/service/contacts/service as contacts_service import app_service/service/chat/service as chat_service @@ -380,7 +381,8 @@ method loadProfileShowcase(self: Module, profileShowcase: ProfileShowcaseDto, va showcaseKey: collectible.toCombinedCollectibleId(), showcasePosition: collectible.order )) - collectibleChainIds.add(collectible.chainId) + if not collectibleChainIds.contains(collectible.chainId): + collectibleChainIds.add(collectible.chainId) self.view.loadProfileShowcaseContactCollectibles(collectibleItems) var assetItems: seq[ShowcaseContactGenericItem] = @[] @@ -409,9 +411,10 @@ method loadProfileShowcase(self: Module, profileShowcase: ProfileShowcaseDto, va self.showcaseForAContactLoading = false self.view.emitShowcaseForAContactLoadingChangedSignal() else: - # NOTE: this implementation does not respect testnet setting - # to fix use SIGNAL_WALLET_ACCOUNT_NETWORK_ENABLED_UPDATED and getChainIds() to intersect with collectibleChainIds - self.collectiblesController.setFilterAddressesAndChains(accountAddresses, collectibleChainIds) + let enabledChainIds = self.controller.getEnabledChainIds() + + let combinedNetworks = utils.intersectSeqs(collectibleChainIds, enabledChainIds) + self.collectiblesController.setFilterAddressesAndChains(accountAddresses, combinedNetworks) self.controller.requestProfileShowcaseForContact(self.showcasePublicKey, true) method fetchProfileShowcaseAccountsByAddress*(self: Module, address: string) = @@ -425,4 +428,4 @@ method getShowcaseCollectiblesModel*(self: Module): QVariant = return self.collectiblesController.getModelAsVariant() method isShowcaseForAContactLoading*(self: Module): bool = - return self.showcaseForAContactLoading \ No newline at end of file + return self.showcaseForAContactLoading diff --git a/src/app_service/common/utils.nim b/src/app_service/common/utils.nim index 7e46e4b1dd..e06a01adc4 100644 --- a/src/app_service/common/utils.nim +++ b/src/app_service/common/utils.nim @@ -87,3 +87,10 @@ proc isPathOutOfTheDefaultStatusDerivationTree*(path: string): bool = proc contractUniqueKey*(chainId: int, contractAddress: string): string = return $chainId & "_" & contractAddress + +proc intersectSeqs*[T](seq1, seq2: seq[T]): seq[T] = + var result: seq[T] = @[] + for item in seq1: + if item in seq2: + result.add(item) + return result \ No newline at end of file