diff --git a/src/app/modules/main/communities/controller.nim b/src/app/modules/main/communities/controller.nim index 1e698b2a7e..272c8cfbf8 100644 --- a/src/app/modules/main/communities/controller.nim +++ b/src/app/modules/main/communities/controller.nim @@ -72,7 +72,7 @@ proc delete*(self: Controller) = discard proc init*(self: Controller) = - self.events.on(SIGNAL_COMMUNITY_DATA_LOADED) do(e:Args): + self.events.once(SIGNAL_COMMUNITY_DATA_LOADED) do(e:Args): self.delegate.communityDataLoaded() self.events.on(SIGNAL_COMMUNITY_CREATED) do(e:Args): @@ -191,12 +191,6 @@ proc init*(self: Controller) = ) self.tmpCommunityIdForRevealedAccounts = "" - self.events.on(SignalType.Wallet.event, proc(e: Args) = - var data = WalletSignal(e) - if data.eventType == backend_collectibles.eventCollectiblesOwnershipUpdateFinished: - self.delegate.onOwnedCollectiblesUpdated() - ) - self.events.on(SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT) do(e: Args): self.delegate.onWalletAccountTokensRebuilt() diff --git a/src/app/modules/main/communities/io_interface.nim b/src/app/modules/main/communities/io_interface.nim index ba72edd769..696511d119 100644 --- a/src/app/modules/main/communities/io_interface.nim +++ b/src/app/modules/main/communities/io_interface.nim @@ -161,9 +161,6 @@ method communityInfoAlreadyRequested*(self: AccessInterface) {.base.} = method onCommunityTokenMetadataAdded*(self: AccessInterface, communityId: string, tokenMetadata: CommunityTokensMetadataDto) {.base.} = raise newException(ValueError, "No implementation available") -method onOwnedCollectiblesUpdated*(self: AccessInterface) {.base.} = - raise newException(ValueError, "No implementation available") - method onWalletAccountTokensRebuilt*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/communities/module.nim b/src/app/modules/main/communities/module.nim index b1b2461496..1523c7163e 100644 --- a/src/app/modules/main/communities/module.nim +++ b/src/app/modules/main/communities/module.nim @@ -51,7 +51,7 @@ type method setCommunityTags*(self: Module, communityTags: string) method setAllCommunities*(self: Module, communities: seq[CommunityDto]) method setCuratedCommunities*(self: Module, curatedCommunities: seq[CommunityDto]) -proc buildTokensAndCollectibles(self: Module) +proc buildTokensAndCollectiblesFromCommunities(self: Module) proc newModule*( delegate: delegate_interface.AccessInterface, @@ -107,7 +107,7 @@ method viewDidLoad*(self: Module) = method communityDataLoaded*(self: Module) = self.setCommunityTags(self.controller.getCommunityTags()) self.setAllCommunities(self.controller.getAllCommunities()) - self.buildTokensAndCollectibles() + self.buildTokensAndCollectiblesFromCommunities() method onActivated*(self: Module) = self.controller.asyncLoadCuratedCommunities() @@ -420,12 +420,16 @@ proc createCommunityTokenItem(self: Module, token: CommunityTokensMetadataDto, c infiniteSupply, ) -proc buildTokensAndCollectibles(self: Module) = +proc buildTokensAndCollectiblesFromCommunities(self: Module) = var tokenListItems: seq[TokenListItem] var collectiblesListItems: seq[TokenListItem] let communities = self.controller.getAllCommunities() for community in communities: + if not community.isOwner or not community.isTokenMaster: + # No need to include those tokens, we do not manage that community + continue + let communityTokens = self.controller.getCommunityTokens(community.id) for tokenMetadata in community.communityTokensMetadata: # Set fallback supply to infinite in case we don't have it @@ -446,11 +450,17 @@ proc buildTokensAndCollectibles(self: Module) = if tokenMetadata.tokenType == community_dto.TokenType.ERC20: # Community ERC20 tokens - tokenListItems.add(communityTokenItem, ) + tokenListItems.add(communityTokenItem) else: # Community collectibles (ERC721 and others) collectiblesListItems.add(communityTokenItem) + self.view.tokenListModel.addItems(tokenListItems) + self.view.collectiblesListModel.addItems(collectiblesListItems) + +proc buildTokensAndCollectiblesFromWallet(self: Module) = + var tokenListItems: seq[TokenListItem] + # Common ERC20 tokens let erc20Tokens = self.controller.getTokenList() for token in erc20Tokens: @@ -464,14 +474,10 @@ proc buildTokensAndCollectibles(self: Module) = ) tokenListItems.add(tokenListItem) - self.view.setTokenListItems(tokenListItems) - self.view.setCollectiblesListItems(collectiblesListItems) + self.view.tokenListModel.setWalletTokenItems(tokenListItems) method onWalletAccountTokensRebuilt*(self: Module) = - self.buildTokensAndCollectibles() - -method onOwnedCollectiblesUpdated*(self: Module) = - self.buildTokensAndCollectibles() + self.buildTokensAndCollectiblesFromWallet() method onCommunityTokenMetadataAdded*(self: Module, communityId: string, tokenMetadata: CommunityTokensMetadataDto) = let communityTokens = self.controller.getCommunityTokens(communityId) diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index 26f200ed46..b1fdcfca82 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -302,10 +302,11 @@ proc createChannelGroupItem[T](self: Module[T], channelGroup: ChannelGroupDto): var communityTokensItems: seq[TokenItem] if (isCommunity): communityDetails = self.controller.getCommunityById(channelGroup.id) - self.controller.getCommunityTokensDetailsAsync(channelGroup.id) - # Get community members' revealed accounts - # We will update the model later when we finish loading the accounts if communityDetails.memberRole == MemberRole.Owner or communityDetails.memberRole == MemberRole.TokenMaster: + self.controller.getCommunityTokensDetailsAsync(channelGroup.id) + + # Get community members' revealed accounts + # We will update the model later when we finish loading the accounts self.controller.asyncGetRevealedAccountsForAllMembers(channelGroup.id) let unviewedCount = channelGroup.unviewedMessagesCount diff --git a/src/app/modules/shared_models/token_list_model.nim b/src/app/modules/shared_models/token_list_model.nim index b3d91edd4c..0252079b43 100644 --- a/src/app/modules/shared_models/token_list_model.nim +++ b/src/app/modules/shared_models/token_list_model.nim @@ -44,6 +44,17 @@ QtObject: self.endResetModel() self.countChanged() + proc setWalletTokenItems*(self: TokenListModel, items: seq[TokenListItem]) = + var newItems = items + for item in self.items: + # Add back the community tokens + if item.communityId != "": + newItems.add(item) + self.beginResetModel() + self.items = newItems + self.endResetModel() + self.countChanged() + proc hasItem*(self: TokenListModel, symbol: string): bool = for item in self.items: if item.getSymbol() == symbol: