mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-10 22:36:24 +00:00
feat(communities): only call getCommunityTokens once per community
Fixes #12032
This commit is contained in:
parent
bf223ce83c
commit
34dfa00c57
@ -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()
|
||||
|
||||
|
@ -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")
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user