Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.getCurrentNetworks().map(n => n.chainId)
proc getEnabledChainIds*(self: Controller): seq[int] =
return self.networkService.getCurrentNetworks().filter(n => n.isEnabled).map(n => n.chainId)
13 changes: 8 additions & 5 deletions src/app/modules/main/profile_section/contacts/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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] = @[]
Expand Down Expand Up @@ -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) =
Expand All @@ -425,4 +428,4 @@ method getShowcaseCollectiblesModel*(self: Module): QVariant =
return self.collectiblesController.getModelAsVariant()

method isShowcaseForAContactLoading*(self: Module): bool =
return self.showcaseForAContactLoading
return self.showcaseForAContactLoading
7 changes: 7 additions & 0 deletions src/app_service/common/utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MishkaRogachev you provided a new compilation warning in this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var result: seq[T] = @[]
for item in seq1:
if item in seq2:
result.add(item)
return result