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
|
discard
|
||||||
|
|
||||||
proc init*(self: Controller) =
|
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.delegate.communityDataLoaded()
|
||||||
|
|
||||||
self.events.on(SIGNAL_COMMUNITY_CREATED) do(e:Args):
|
self.events.on(SIGNAL_COMMUNITY_CREATED) do(e:Args):
|
||||||
|
@ -191,12 +191,6 @@ proc init*(self: Controller) =
|
||||||
)
|
)
|
||||||
self.tmpCommunityIdForRevealedAccounts = ""
|
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.events.on(SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT) do(e: Args):
|
||||||
self.delegate.onWalletAccountTokensRebuilt()
|
self.delegate.onWalletAccountTokensRebuilt()
|
||||||
|
|
||||||
|
|
|
@ -161,9 +161,6 @@ method communityInfoAlreadyRequested*(self: AccessInterface) {.base.} =
|
||||||
method onCommunityTokenMetadataAdded*(self: AccessInterface, communityId: string, tokenMetadata: CommunityTokensMetadataDto) {.base.} =
|
method onCommunityTokenMetadataAdded*(self: AccessInterface, communityId: string, tokenMetadata: CommunityTokensMetadataDto) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method onOwnedCollectiblesUpdated*(self: AccessInterface) {.base.} =
|
|
||||||
raise newException(ValueError, "No implementation available")
|
|
||||||
|
|
||||||
method onWalletAccountTokensRebuilt*(self: AccessInterface) {.base.} =
|
method onWalletAccountTokensRebuilt*(self: AccessInterface) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ type
|
||||||
method setCommunityTags*(self: Module, communityTags: string)
|
method setCommunityTags*(self: Module, communityTags: string)
|
||||||
method setAllCommunities*(self: Module, communities: seq[CommunityDto])
|
method setAllCommunities*(self: Module, communities: seq[CommunityDto])
|
||||||
method setCuratedCommunities*(self: Module, curatedCommunities: seq[CommunityDto])
|
method setCuratedCommunities*(self: Module, curatedCommunities: seq[CommunityDto])
|
||||||
proc buildTokensAndCollectibles(self: Module)
|
proc buildTokensAndCollectiblesFromCommunities(self: Module)
|
||||||
|
|
||||||
proc newModule*(
|
proc newModule*(
|
||||||
delegate: delegate_interface.AccessInterface,
|
delegate: delegate_interface.AccessInterface,
|
||||||
|
@ -107,7 +107,7 @@ method viewDidLoad*(self: Module) =
|
||||||
method communityDataLoaded*(self: Module) =
|
method communityDataLoaded*(self: Module) =
|
||||||
self.setCommunityTags(self.controller.getCommunityTags())
|
self.setCommunityTags(self.controller.getCommunityTags())
|
||||||
self.setAllCommunities(self.controller.getAllCommunities())
|
self.setAllCommunities(self.controller.getAllCommunities())
|
||||||
self.buildTokensAndCollectibles()
|
self.buildTokensAndCollectiblesFromCommunities()
|
||||||
|
|
||||||
method onActivated*(self: Module) =
|
method onActivated*(self: Module) =
|
||||||
self.controller.asyncLoadCuratedCommunities()
|
self.controller.asyncLoadCuratedCommunities()
|
||||||
|
@ -420,12 +420,16 @@ proc createCommunityTokenItem(self: Module, token: CommunityTokensMetadataDto, c
|
||||||
infiniteSupply,
|
infiniteSupply,
|
||||||
)
|
)
|
||||||
|
|
||||||
proc buildTokensAndCollectibles(self: Module) =
|
proc buildTokensAndCollectiblesFromCommunities(self: Module) =
|
||||||
var tokenListItems: seq[TokenListItem]
|
var tokenListItems: seq[TokenListItem]
|
||||||
var collectiblesListItems: seq[TokenListItem]
|
var collectiblesListItems: seq[TokenListItem]
|
||||||
|
|
||||||
let communities = self.controller.getAllCommunities()
|
let communities = self.controller.getAllCommunities()
|
||||||
for community in communities:
|
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)
|
let communityTokens = self.controller.getCommunityTokens(community.id)
|
||||||
for tokenMetadata in community.communityTokensMetadata:
|
for tokenMetadata in community.communityTokensMetadata:
|
||||||
# Set fallback supply to infinite in case we don't have it
|
# 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:
|
if tokenMetadata.tokenType == community_dto.TokenType.ERC20:
|
||||||
# Community ERC20 tokens
|
# Community ERC20 tokens
|
||||||
tokenListItems.add(communityTokenItem, )
|
tokenListItems.add(communityTokenItem)
|
||||||
else:
|
else:
|
||||||
# Community collectibles (ERC721 and others)
|
# Community collectibles (ERC721 and others)
|
||||||
collectiblesListItems.add(communityTokenItem)
|
collectiblesListItems.add(communityTokenItem)
|
||||||
|
|
||||||
|
self.view.tokenListModel.addItems(tokenListItems)
|
||||||
|
self.view.collectiblesListModel.addItems(collectiblesListItems)
|
||||||
|
|
||||||
|
proc buildTokensAndCollectiblesFromWallet(self: Module) =
|
||||||
|
var tokenListItems: seq[TokenListItem]
|
||||||
|
|
||||||
# Common ERC20 tokens
|
# Common ERC20 tokens
|
||||||
let erc20Tokens = self.controller.getTokenList()
|
let erc20Tokens = self.controller.getTokenList()
|
||||||
for token in erc20Tokens:
|
for token in erc20Tokens:
|
||||||
|
@ -464,14 +474,10 @@ proc buildTokensAndCollectibles(self: Module) =
|
||||||
)
|
)
|
||||||
tokenListItems.add(tokenListItem)
|
tokenListItems.add(tokenListItem)
|
||||||
|
|
||||||
self.view.setTokenListItems(tokenListItems)
|
self.view.tokenListModel.setWalletTokenItems(tokenListItems)
|
||||||
self.view.setCollectiblesListItems(collectiblesListItems)
|
|
||||||
|
|
||||||
method onWalletAccountTokensRebuilt*(self: Module) =
|
method onWalletAccountTokensRebuilt*(self: Module) =
|
||||||
self.buildTokensAndCollectibles()
|
self.buildTokensAndCollectiblesFromWallet()
|
||||||
|
|
||||||
method onOwnedCollectiblesUpdated*(self: Module) =
|
|
||||||
self.buildTokensAndCollectibles()
|
|
||||||
|
|
||||||
method onCommunityTokenMetadataAdded*(self: Module, communityId: string, tokenMetadata: CommunityTokensMetadataDto) =
|
method onCommunityTokenMetadataAdded*(self: Module, communityId: string, tokenMetadata: CommunityTokensMetadataDto) =
|
||||||
let communityTokens = self.controller.getCommunityTokens(communityId)
|
let communityTokens = self.controller.getCommunityTokens(communityId)
|
||||||
|
|
|
@ -302,10 +302,11 @@ proc createChannelGroupItem[T](self: Module[T], channelGroup: ChannelGroupDto):
|
||||||
var communityTokensItems: seq[TokenItem]
|
var communityTokensItems: seq[TokenItem]
|
||||||
if (isCommunity):
|
if (isCommunity):
|
||||||
communityDetails = self.controller.getCommunityById(channelGroup.id)
|
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:
|
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)
|
self.controller.asyncGetRevealedAccountsForAllMembers(channelGroup.id)
|
||||||
|
|
||||||
let unviewedCount = channelGroup.unviewedMessagesCount
|
let unviewedCount = channelGroup.unviewedMessagesCount
|
||||||
|
|
|
@ -44,6 +44,17 @@ QtObject:
|
||||||
self.endResetModel()
|
self.endResetModel()
|
||||||
self.countChanged()
|
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 =
|
proc hasItem*(self: TokenListModel, symbol: string): bool =
|
||||||
for item in self.items:
|
for item in self.items:
|
||||||
if item.getSymbol() == symbol:
|
if item.getSymbol() == symbol:
|
||||||
|
|
Loading…
Reference in New Issue