fix(Permissions): tokenOwner is present in the list of collectibles when adding a permission (#14236)

fixes #13561
This commit is contained in:
Andrey Bocharnikov 2024-04-02 17:38:08 +07:00 committed by GitHub
parent b91cf08066
commit accd4da214
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 53 additions and 35 deletions

View File

@ -554,7 +554,7 @@ method requestCancelDiscordChannelImport*(self: Module, discordChannelId: string
self.controller.requestCancelDiscordChannelImport(discordChannelId) self.controller.requestCancelDiscordChannelImport(discordChannelId)
proc createCommunityTokenItem(self: Module, token: CommunityTokensMetadataDto, communityId: string, supply: string, proc createCommunityTokenItem(self: Module, token: CommunityTokensMetadataDto, communityId: string, supply: string,
infiniteSupply: bool): TokenListItem = infiniteSupply: bool, privilegesLevel: int): TokenListItem =
let communityTokenDecimals = if token.tokenType == TokenType.ERC20: 18 else: 0 let communityTokenDecimals = if token.tokenType == TokenType.ERC20: 18 else: 0
result = initTokenListItem( result = initTokenListItem(
key = token.symbol, key = token.symbol,
@ -566,9 +566,24 @@ proc createCommunityTokenItem(self: Module, token: CommunityTokensMetadataDto, c
communityId = communityId, communityId = communityId,
supply, supply,
infiniteSupply, infiniteSupply,
communityTokenDecimals communityTokenDecimals,
privilegesLevel
) )
proc buildCommunityTokenItemFallback(self: Module, communityTokens: seq[CommunityTokenDto],
token: CommunityTokensMetadataDto, communityId: string): TokenListItem =
# Set fallback supply to infinite in case we don't have it
var supply = "1"
var infiniteSupply = true
var privilegesLevel = PrivilegesLevel.Community.int
for communityToken in communityTokens:
if communityToken.symbol == token.symbol:
supply = communityToken.supply.toString(10)
infiniteSupply = communityToken.infiniteSupply
privilegesLevel = communityToken.privilegesLevel.int
break
return self.createCommunityTokenItem(token, communityId, supply, infiniteSupply, privilegesLevel)
proc buildTokensAndCollectiblesFromCommunities(self: Module, communities: seq[CommunityDto]) = proc buildTokensAndCollectiblesFromCommunities(self: Module, communities: seq[CommunityDto]) =
var tokenListItems: seq[TokenListItem] var tokenListItems: seq[TokenListItem]
var collectiblesListItems: seq[TokenListItem] var collectiblesListItems: seq[TokenListItem]
@ -576,21 +591,7 @@ proc buildTokensAndCollectiblesFromCommunities(self: Module, communities: seq[Co
let communityTokens = self.controller.getAllCommunityTokens() let communityTokens = self.controller.getAllCommunityTokens()
for community in communities: for community in communities:
for tokenMetadata in community.communityTokensMetadata: for tokenMetadata in community.communityTokensMetadata:
# Set fallback supply to infinite in case we don't have it var communityTokenItem = self.buildCommunityTokenItemFallback(communityTokens, tokenMetadata, community.id)
var supply = "1"
var infiniteSupply = true
for communityToken in communityTokens:
if communityToken.symbol == tokenMetadata.symbol:
supply = communityToken.supply.toString(10)
infiniteSupply = communityToken.infiniteSupply
break
var communityTokenItem = self.createCommunityTokenItem(
tokenMetadata,
community.id,
supply,
infiniteSupply,
)
if tokenMetadata.tokenType == TokenType.ERC20 and if tokenMetadata.tokenType == TokenType.ERC20 and
not self.view.tokenListModel().hasItem(tokenMetadata.symbol, community.id): not self.view.tokenListModel().hasItem(tokenMetadata.symbol, community.id):
@ -619,6 +620,13 @@ proc buildTokensAndCollectiblesFromWallet(self: Module) =
return filteredChains.len != 0 return filteredChains.len != 0
)) ))
for token in erc20Tokens: for token in erc20Tokens:
let communityTokens = self.controller.getCommunityTokens(token.communityId)
var privilegesLevel = PrivilegesLevel.Community.int
for communityToken in communityTokens:
if communityToken.symbol == token.symbol:
privilegesLevel = communityToken.privilegesLevel.int
break
let tokenListItem = initTokenListItem( let tokenListItem = initTokenListItem(
key = token.symbol, key = token.symbol,
name = token.name, name = token.name,
@ -627,7 +635,8 @@ proc buildTokensAndCollectiblesFromWallet(self: Module) =
communityId = token.communityId, communityId = token.communityId,
image = "", image = "",
category = ord(TokenListItemCategory.General), category = ord(TokenListItemCategory.General),
decimals = token.decimals decimals = token.decimals,
privilegesLevel = privilegesLevel
) )
tokenListItems.add(tokenListItem) tokenListItems.add(tokenListItem)
@ -638,21 +647,7 @@ method onWalletAccountTokensRebuilt*(self: Module) =
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)
var tokenListItem: TokenListItem var tokenListItem = self.buildCommunityTokenItemFallback(communityTokens, tokenMetadata, communityId)
# Set fallback supply to infinite in case we don't have it
var supply = "1"
var infiniteSupply = true
for communityToken in communityTokens:
if communityToken.symbol == tokenMetadata.symbol:
supply = communityToken.supply.toString(10)
infiniteSupply = communityToken.infiniteSupply
break
tokenListItem = self.createCommunityTokenItem(
tokenMetadata,
communityId,
supply,
infiniteSupply,
)
if tokenMetadata.tokenType == TokenType.ERC721 and if tokenMetadata.tokenType == TokenType.ERC721 and
not self.view.collectiblesListModel().hasItem(tokenMetadata.symbol, communityId): not self.view.collectiblesListModel().hasItem(tokenMetadata.symbol, communityId):

View File

@ -17,6 +17,7 @@ type
supply*: string supply*: string
infiniteSupply*: bool infiniteSupply*: bool
decimals*: int decimals*: int
privilegesLevel*: int
proc initTokenListItem*( proc initTokenListItem*(
key: string, key: string,
@ -28,7 +29,8 @@ proc initTokenListItem*(
communityId: string = "", communityId: string = "",
supply: string = "1", supply: string = "1",
infiniteSupply: bool = true, infiniteSupply: bool = true,
decimals: int decimals: int,
privilegesLevel: int
): TokenListItem = ): TokenListItem =
result.key = key result.key = key
result.symbol = symbol result.symbol = symbol
@ -40,6 +42,7 @@ proc initTokenListItem*(
result.supply = supply result.supply = supply
result.infiniteSupply = infiniteSupply result.infiniteSupply = infiniteSupply
result.decimals = decimals result.decimals = decimals
result.privilegesLevel = privilegesLevel
proc `$`*(self: TokenListItem): string = proc `$`*(self: TokenListItem): string =
result = fmt"""TokenListItem( result = fmt"""TokenListItem(
@ -52,6 +55,7 @@ proc `$`*(self: TokenListItem): string =
supply: {self.supply}, supply: {self.supply},
infiniteSupply: {self.infiniteSupply}, infiniteSupply: {self.infiniteSupply},
decimals: {self.decimals}, decimals: {self.decimals},
privilegesLevel: {self.privilegesLevel}
]""" ]"""
proc getKey*(self: TokenListItem): string = proc getKey*(self: TokenListItem): string =
@ -83,3 +87,6 @@ proc getInfiniteSupply*(self: TokenListItem): bool =
proc getDecimals*(self: TokenListItem): int = proc getDecimals*(self: TokenListItem): int =
return self.decimals return self.decimals
proc getPrivilegesLevel*(self: TokenListItem): int =
return self.privilegesLevel

View File

@ -14,6 +14,7 @@ type
Supply Supply
InfiniteSupply InfiniteSupply
Decimals Decimals
PrivilegesLevel
QtObject: QtObject:
type TokenListModel* = ref object of QAbstractListModel type TokenListModel* = ref object of QAbstractListModel
@ -93,6 +94,7 @@ QtObject:
ModelRole.Supply.int:"supply", ModelRole.Supply.int:"supply",
ModelRole.InfiniteSupply.int:"infiniteSupply", ModelRole.InfiniteSupply.int:"infiniteSupply",
ModelRole.Decimals.int:"decimals", ModelRole.Decimals.int:"decimals",
ModelRole.PrivilegesLevel.int:"privilegesLevel",
}.toTable }.toTable
method rowCount(self: TokenlistModel, index: QModelIndex = nil): int = method rowCount(self: TokenlistModel, index: QModelIndex = nil): int =
@ -128,3 +130,5 @@ QtObject:
result = newQVariant(item.getInfiniteSupply()) result = newQVariant(item.getInfiniteSupply())
of ModelRole.Decimals: of ModelRole.Decimals:
result = newQVariant(item.getDecimals()) result = newQVariant(item.getDecimals())
of ModelRole.PrivilegesLevel:
result = newQVariant(item.getPrivilegesLevel())

View File

@ -300,7 +300,19 @@ StatusSectionLayout {
// solution soon. // solution soon.
assetsModel: rootStore.assetsModel assetsModel: rootStore.assetsModel
collectiblesModel: rootStore.collectiblesModel
SortFilterProxyModel {
id: nonOwnerCollectibles
sourceModel: rootStore.collectiblesModel
filters: [
ValueFilter {
roleName: "privilegesLevel"
value: Constants.TokenPrivilegesLevel.Owner
inverted: true
}
]
}
collectiblesModel: nonOwnerCollectibles
channelsModel: rootStore.chatCommunitySectionModule.model channelsModel: rootStore.chatCommunitySectionModule.model
communityDetails: d.communityDetails communityDetails: d.communityDetails