mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-09 13:56:10 +00:00
parent
5bd2d8dcfd
commit
9d78e23b68
@ -1,4 +1,4 @@
|
||||
import NimQml, sequtils, tables
|
||||
import NimQml, sequtils, tables, stint
|
||||
|
||||
import ./io_interface
|
||||
import ../io_interface as delegate_interface
|
||||
@ -407,6 +407,20 @@ method requestCancelDiscordCommunityImport*(self: Module, id: string) =
|
||||
method communityInfoAlreadyRequested*(self: Module) =
|
||||
self.view.communityInfoAlreadyRequested()
|
||||
|
||||
proc createCommunityTokenItem(self: Module, token: CommunityTokensMetadataDto, communityId: string, supply: string,
|
||||
infiniteSupply: bool): TokenListItem =
|
||||
result = initTokenListItem(
|
||||
key = token.symbol,
|
||||
name = token.name,
|
||||
symbol = token.symbol,
|
||||
color = "", # community tokens don't have `color`
|
||||
image = token.image,
|
||||
category = ord(TokenListItemCategory.Community),
|
||||
communityId = communityId,
|
||||
supply,
|
||||
infiniteSupply,
|
||||
)
|
||||
|
||||
proc buildTokenList(self: Module) =
|
||||
var tokenListItems: seq[TokenListItem]
|
||||
var collectiblesListItems: seq[TokenListItem]
|
||||
@ -421,23 +435,28 @@ proc buildTokenList(self: Module) =
|
||||
symbol = token.symbol,
|
||||
color = token.color,
|
||||
image = "",
|
||||
category = ord(TokenListItemCategory.General)
|
||||
category = ord(TokenListItemCategory.General),
|
||||
)
|
||||
|
||||
tokenListItems.add(tokenListItem)
|
||||
|
||||
for community in communities:
|
||||
for token in community.communityTokensMetadata:
|
||||
let tokenListItem = initTokenListItem(
|
||||
key = token.symbol,
|
||||
name = token.name,
|
||||
symbol = token.symbol,
|
||||
color = "", # community tokens don't have `color`
|
||||
image = token.image,
|
||||
category = ord(TokenListItemCategory.Community),
|
||||
communityId = community.id,
|
||||
)
|
||||
collectiblesListItems.add(tokenListItem)
|
||||
let communityTokens = self.controller.getCommunityTokens(community.id)
|
||||
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
|
||||
collectiblesListItems.add(self.createCommunityTokenItem(
|
||||
tokenMetadata,
|
||||
community.id,
|
||||
supply,
|
||||
infiniteSupply,
|
||||
))
|
||||
|
||||
self.view.setTokenListItems(tokenListItems)
|
||||
self.view.setCollectiblesListItems(collectiblesListItems)
|
||||
@ -449,14 +468,21 @@ method onOwnedCollectiblesUpdated*(self: Module) =
|
||||
self.buildTokenList()
|
||||
|
||||
method onCommunityTokenMetadataAdded*(self: Module, communityId: string, tokenMetadata: CommunityTokensMetadataDto) =
|
||||
let tokenListItem = initTokenListItem(
|
||||
key = tokenMetadata.symbol,
|
||||
name = tokenMetadata.name,
|
||||
symbol = tokenMetadata.symbol,
|
||||
color = "", # tokenMetadata doesn't provide a color
|
||||
image = tokenMetadata.image,
|
||||
category = ord(TokenListItemCategory.Community),
|
||||
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,
|
||||
)
|
||||
|
||||
if tokenMetadata.tokenType == community_dto.TokenType.ERC721 and
|
||||
|
@ -14,6 +14,8 @@ type
|
||||
image*: string
|
||||
category*: int
|
||||
communityId*: string
|
||||
supply*: string
|
||||
infiniteSupply*: bool
|
||||
|
||||
proc initTokenListItem*(
|
||||
key: string,
|
||||
@ -22,7 +24,9 @@ proc initTokenListItem*(
|
||||
color: string,
|
||||
image: string,
|
||||
category: int,
|
||||
communityId: string = ""
|
||||
communityId: string = "",
|
||||
supply: string = "1",
|
||||
infiniteSupply: bool = true,
|
||||
): TokenListItem =
|
||||
result.key = key
|
||||
result.symbol = symbol
|
||||
@ -31,6 +35,8 @@ proc initTokenListItem*(
|
||||
result.image = image
|
||||
result.category = category
|
||||
result.communityId = communityId
|
||||
result.supply = supply
|
||||
result.infiniteSupply = infiniteSupply
|
||||
|
||||
proc `$`*(self: TokenListItem): string =
|
||||
result = fmt"""TokenListItem(
|
||||
@ -40,6 +46,8 @@ proc `$`*(self: TokenListItem): string =
|
||||
symbol: {self.symbol},
|
||||
category: {self.category},
|
||||
communityId: {self.communityId},
|
||||
supply: {self.supply},
|
||||
infiniteSupply: {self.infiniteSupply},
|
||||
]"""
|
||||
|
||||
proc getKey*(self: TokenListItem): string =
|
||||
@ -62,3 +70,9 @@ proc getCategory*(self: TokenListItem): int =
|
||||
|
||||
proc getCommunityId*(self: TokenListItem): string =
|
||||
return self.communityId
|
||||
|
||||
proc getSupply*(self: TokenListItem): string =
|
||||
return self.supply
|
||||
|
||||
proc getInfiniteSupply*(self: TokenListItem): bool =
|
||||
return self.infiniteSupply
|
||||
|
@ -11,6 +11,8 @@ type
|
||||
Image
|
||||
Category
|
||||
CommunityId
|
||||
Supply
|
||||
InfiniteSupply
|
||||
|
||||
QtObject:
|
||||
type TokenListModel* = ref object of QAbstractListModel
|
||||
@ -76,6 +78,8 @@ QtObject:
|
||||
ModelRole.Image.int:"icon",
|
||||
ModelRole.Category.int:"category",
|
||||
ModelRole.CommunityId.int:"communityId",
|
||||
ModelRole.Supply.int:"supply",
|
||||
ModelRole.InfiniteSupply.int:"infiniteSupply",
|
||||
}.toTable
|
||||
|
||||
method rowCount(self: TokenlistModel, index: QModelIndex = nil): int =
|
||||
@ -105,3 +109,7 @@ QtObject:
|
||||
result = newQVariant(item.getCategory())
|
||||
of ModelRole.CommunityId:
|
||||
result = newQVariant(item.getCommunityId())
|
||||
of ModelRole.Supply:
|
||||
result = newQVariant(item.getSupply())
|
||||
of ModelRole.InfiniteSupply:
|
||||
result = newQVariant(item.getInfiniteSupply())
|
||||
|
Loading…
x
Reference in New Issue
Block a user