From 3463d7a01fd30f2672f4985ce940cd01426a8766 Mon Sep 17 00:00:00 2001 From: Mikhail Rogachev Date: Tue, 22 Aug 2023 19:07:02 +0300 Subject: [PATCH] fix(Communities): show community tokens in token section (#11970) Close #11843 --- src/app/modules/main/communities/module.nim | 49 ++++++++++++--------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/src/app/modules/main/communities/module.nim b/src/app/modules/main/communities/module.nim index 47eefc0243..cdd9c25731 100644 --- a/src/app/modules/main/communities/module.nim +++ b/src/app/modules/main/communities/module.nim @@ -49,7 +49,7 @@ type method setCommunityTags*(self: Module, communityTags: string) method setAllCommunities*(self: Module, communities: seq[CommunityDto]) method setCuratedCommunities*(self: Module, curatedCommunities: seq[CommunityDto]) -proc buildTokenList(self: Module) +proc buildTokensAndCollectibles(self: Module) proc newModule*( delegate: delegate_interface.AccessInterface, @@ -103,7 +103,7 @@ method viewDidLoad*(self: Module) = method communityDataLoaded*(self: Module) = self.setCommunityTags(self.controller.getCommunityTags()) self.setAllCommunities(self.controller.getAllCommunities()) - self.buildTokenList() + self.buildTokensAndCollectibles() method onActivated*(self: Module) = self.controller.asyncLoadCuratedCommunities() @@ -422,25 +422,11 @@ proc createCommunityTokenItem(self: Module, token: CommunityTokensMetadataDto, c infiniteSupply, ) -proc buildTokenList(self: Module) = +proc buildTokensAndCollectibles(self: Module) = var tokenListItems: seq[TokenListItem] var collectiblesListItems: seq[TokenListItem] let communities = self.controller.getAllCommunities() - let erc20Tokens = self.controller.getTokenList() - - for token in erc20Tokens: - let tokenListItem = initTokenListItem( - key = token.symbol, - name = token.name, - symbol = token.symbol, - color = token.color, - image = "", - category = ord(TokenListItemCategory.General), - ) - - tokenListItems.add(tokenListItem) - for community in communities: let communityTokens = self.controller.getCommunityTokens(community.id) for tokenMetadata in community.communityTokensMetadata: @@ -452,21 +438,42 @@ proc buildTokenList(self: Module) = supply = communityToken.supply.toString(10) infiniteSupply = communityToken.infiniteSupply break - collectiblesListItems.add(self.createCommunityTokenItem( + + var communityTokenItem = self.createCommunityTokenItem( tokenMetadata, community.id, supply, infiniteSupply, - )) + ) + + if tokenMetadata.tokenType == community_dto.TokenType.ERC20: + # Community ERC20 tokens + tokenListItems.add(communityTokenItem, ) + else: + # Community collectibles (ERC721 and others) + collectiblesListItems.add(communityTokenItem) + + # Common ERC20 tokens + let erc20Tokens = self.controller.getTokenList() + for token in erc20Tokens: + let tokenListItem = initTokenListItem( + key = token.symbol, + name = token.name, + symbol = token.symbol, + color = token.color, + image = "", + category = ord(TokenListItemCategory.General), + ) + tokenListItems.add(tokenListItem) self.view.setTokenListItems(tokenListItems) self.view.setCollectiblesListItems(collectiblesListItems) method onWalletAccountTokensRebuilt*(self: Module) = - self.buildTokenList() + self.buildTokensAndCollectibles() method onOwnedCollectiblesUpdated*(self: Module) = - self.buildTokenList() + self.buildTokensAndCollectibles() method onCommunityTokenMetadataAdded*(self: Module, communityId: string, tokenMetadata: CommunityTokensMetadataDto) = let communityTokens = self.controller.getCommunityTokens(communityId)