fix(Permissions): tokenOwner is present in the list of collectibles when adding a permission
fixes #13561
This commit is contained in:
parent
e3028ffd28
commit
4ce61f7ab1
|
@ -554,7 +554,7 @@ method requestCancelDiscordChannelImport*(self: Module, discordChannelId: string
|
|||
self.controller.requestCancelDiscordChannelImport(discordChannelId)
|
||||
|
||||
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
|
||||
result = initTokenListItem(
|
||||
key = token.symbol,
|
||||
|
@ -566,9 +566,24 @@ proc createCommunityTokenItem(self: Module, token: CommunityTokensMetadataDto, c
|
|||
communityId = communityId,
|
||||
supply,
|
||||
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]) =
|
||||
var tokenListItems: seq[TokenListItem]
|
||||
var collectiblesListItems: seq[TokenListItem]
|
||||
|
@ -576,21 +591,7 @@ proc buildTokensAndCollectiblesFromCommunities(self: Module, communities: seq[Co
|
|||
let communityTokens = self.controller.getAllCommunityTokens()
|
||||
for community in communities:
|
||||
for tokenMetadata in community.communityTokensMetadata:
|
||||
# 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
|
||||
|
||||
var communityTokenItem = self.createCommunityTokenItem(
|
||||
tokenMetadata,
|
||||
community.id,
|
||||
supply,
|
||||
infiniteSupply,
|
||||
)
|
||||
var communityTokenItem = self.buildCommunityTokenItemFallback(communityTokens, tokenMetadata, community.id)
|
||||
|
||||
if tokenMetadata.tokenType == TokenType.ERC20 and
|
||||
not self.view.tokenListModel().hasItem(tokenMetadata.symbol, community.id):
|
||||
|
@ -619,6 +620,13 @@ proc buildTokensAndCollectiblesFromWallet(self: Module) =
|
|||
return filteredChains.len != 0
|
||||
))
|
||||
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(
|
||||
key = token.symbol,
|
||||
name = token.name,
|
||||
|
@ -627,7 +635,8 @@ proc buildTokensAndCollectiblesFromWallet(self: Module) =
|
|||
communityId = token.communityId,
|
||||
image = "",
|
||||
category = ord(TokenListItemCategory.General),
|
||||
decimals = token.decimals
|
||||
decimals = token.decimals,
|
||||
privilegesLevel = privilegesLevel
|
||||
)
|
||||
tokenListItems.add(tokenListItem)
|
||||
|
||||
|
@ -638,21 +647,7 @@ method onWalletAccountTokensRebuilt*(self: Module) =
|
|||
|
||||
method onCommunityTokenMetadataAdded*(self: Module, communityId: string, tokenMetadata: CommunityTokensMetadataDto) =
|
||||
let communityTokens = self.controller.getCommunityTokens(communityId)
|
||||
var tokenListItem: TokenListItem
|
||||
# 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,
|
||||
)
|
||||
var tokenListItem = self.buildCommunityTokenItemFallback(communityTokens, tokenMetadata, communityId)
|
||||
|
||||
if tokenMetadata.tokenType == TokenType.ERC721 and
|
||||
not self.view.collectiblesListModel().hasItem(tokenMetadata.symbol, communityId):
|
||||
|
|
|
@ -17,6 +17,7 @@ type
|
|||
supply*: string
|
||||
infiniteSupply*: bool
|
||||
decimals*: int
|
||||
privilegesLevel*: int
|
||||
|
||||
proc initTokenListItem*(
|
||||
key: string,
|
||||
|
@ -28,7 +29,8 @@ proc initTokenListItem*(
|
|||
communityId: string = "",
|
||||
supply: string = "1",
|
||||
infiniteSupply: bool = true,
|
||||
decimals: int
|
||||
decimals: int,
|
||||
privilegesLevel: int
|
||||
): TokenListItem =
|
||||
result.key = key
|
||||
result.symbol = symbol
|
||||
|
@ -40,6 +42,7 @@ proc initTokenListItem*(
|
|||
result.supply = supply
|
||||
result.infiniteSupply = infiniteSupply
|
||||
result.decimals = decimals
|
||||
result.privilegesLevel = privilegesLevel
|
||||
|
||||
proc `$`*(self: TokenListItem): string =
|
||||
result = fmt"""TokenListItem(
|
||||
|
@ -52,6 +55,7 @@ proc `$`*(self: TokenListItem): string =
|
|||
supply: {self.supply},
|
||||
infiniteSupply: {self.infiniteSupply},
|
||||
decimals: {self.decimals},
|
||||
privilegesLevel: {self.privilegesLevel}
|
||||
]"""
|
||||
|
||||
proc getKey*(self: TokenListItem): string =
|
||||
|
@ -83,3 +87,6 @@ proc getInfiniteSupply*(self: TokenListItem): bool =
|
|||
|
||||
proc getDecimals*(self: TokenListItem): int =
|
||||
return self.decimals
|
||||
|
||||
proc getPrivilegesLevel*(self: TokenListItem): int =
|
||||
return self.privilegesLevel
|
|
@ -14,6 +14,7 @@ type
|
|||
Supply
|
||||
InfiniteSupply
|
||||
Decimals
|
||||
PrivilegesLevel
|
||||
|
||||
QtObject:
|
||||
type TokenListModel* = ref object of QAbstractListModel
|
||||
|
@ -93,6 +94,7 @@ QtObject:
|
|||
ModelRole.Supply.int:"supply",
|
||||
ModelRole.InfiniteSupply.int:"infiniteSupply",
|
||||
ModelRole.Decimals.int:"decimals",
|
||||
ModelRole.PrivilegesLevel.int:"privilegesLevel",
|
||||
}.toTable
|
||||
|
||||
method rowCount(self: TokenlistModel, index: QModelIndex = nil): int =
|
||||
|
@ -128,3 +130,5 @@ QtObject:
|
|||
result = newQVariant(item.getInfiniteSupply())
|
||||
of ModelRole.Decimals:
|
||||
result = newQVariant(item.getDecimals())
|
||||
of ModelRole.PrivilegesLevel:
|
||||
result = newQVariant(item.getPrivilegesLevel())
|
|
@ -300,7 +300,19 @@ StatusSectionLayout {
|
|||
// solution soon.
|
||||
|
||||
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
|
||||
|
||||
communityDetails: d.communityDetails
|
||||
|
|
Loading…
Reference in New Issue