fix(Profile): Fix crashing when showcase collectible having disabled chainIds (#14252)

Close #14243

(cherry picked from commit d86be3a970)
This commit is contained in:
Mikhail Rogachev 2024-04-03 11:51:15 +02:00 committed by Jonathan Rainville
parent 5ffad9cb78
commit aa2b90ec4c
3 changed files with 17 additions and 7 deletions

View File

@ -204,5 +204,5 @@ proc requestProfileShowcaseForContact*(self: Controller, contactId: string, vali
proc fetchProfileShowcaseAccountsByAddress*(self: Controller, address: string) = proc fetchProfileShowcaseAccountsByAddress*(self: Controller, address: string) =
self.contactsService.fetchProfileShowcaseAccountsByAddress(address) self.contactsService.fetchProfileShowcaseAccountsByAddress(address)
proc getChainIds*(self: Controller): seq[int] = proc getEnabledChainIds*(self: Controller): seq[int] =
self.networkService.getNetworks().map(n => n.chainId) return self.networkService.getNetworks().filter(n => n.enabled).map(n => n.chainId)

View File

@ -8,6 +8,7 @@ import ../../../../global/global_singleton
import ../../../../core/eventemitter import ../../../../core/eventemitter
import app_service/common/types 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/dto/contacts as contacts_dto
import app_service/service/contacts/service as contacts_service import app_service/service/contacts/service as contacts_service
import app_service/service/chat/service as chat_service import app_service/service/chat/service as chat_service
@ -380,6 +381,7 @@ method loadProfileShowcase(self: Module, profileShowcase: ProfileShowcaseDto, va
showcaseKey: collectible.toCombinedCollectibleId(), showcaseKey: collectible.toCombinedCollectibleId(),
showcasePosition: collectible.order showcasePosition: collectible.order
)) ))
if not collectibleChainIds.contains(collectible.chainId):
collectibleChainIds.add(collectible.chainId) collectibleChainIds.add(collectible.chainId)
self.view.loadProfileShowcaseContactCollectibles(collectibleItems) self.view.loadProfileShowcaseContactCollectibles(collectibleItems)
@ -409,9 +411,10 @@ method loadProfileShowcase(self: Module, profileShowcase: ProfileShowcaseDto, va
self.showcaseForAContactLoading = false self.showcaseForAContactLoading = false
self.view.emitShowcaseForAContactLoadingChangedSignal() self.view.emitShowcaseForAContactLoadingChangedSignal()
else: else:
# NOTE: this implementation does not respect testnet setting let enabledChainIds = self.controller.getEnabledChainIds()
# to fix use SIGNAL_WALLET_ACCOUNT_NETWORK_ENABLED_UPDATED and getChainIds() to intersect with collectibleChainIds
self.collectiblesController.setFilterAddressesAndChains(accountAddresses, collectibleChainIds) let combinedNetworks = utils.intersectSeqs(collectibleChainIds, enabledChainIds)
self.collectiblesController.setFilterAddressesAndChains(accountAddresses, combinedNetworks)
self.controller.requestProfileShowcaseForContact(self.showcasePublicKey, true) self.controller.requestProfileShowcaseForContact(self.showcasePublicKey, true)
method fetchProfileShowcaseAccountsByAddress*(self: Module, address: string) = method fetchProfileShowcaseAccountsByAddress*(self: Module, address: string) =

View File

@ -87,3 +87,10 @@ proc isPathOutOfTheDefaultStatusDerivationTree*(path: string): bool =
proc contractUniqueKey*(chainId: int, contractAddress: string): string = proc contractUniqueKey*(chainId: int, contractAddress: string): string =
return $chainId & "_" & contractAddress 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