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
|
||||||
import ../io_interface as delegate_interface
|
import ../io_interface as delegate_interface
|
||||||
@ -407,6 +407,20 @@ method requestCancelDiscordCommunityImport*(self: Module, id: string) =
|
|||||||
method communityInfoAlreadyRequested*(self: Module) =
|
method communityInfoAlreadyRequested*(self: Module) =
|
||||||
self.view.communityInfoAlreadyRequested()
|
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) =
|
proc buildTokenList(self: Module) =
|
||||||
var tokenListItems: seq[TokenListItem]
|
var tokenListItems: seq[TokenListItem]
|
||||||
var collectiblesListItems: seq[TokenListItem]
|
var collectiblesListItems: seq[TokenListItem]
|
||||||
@ -421,23 +435,28 @@ proc buildTokenList(self: Module) =
|
|||||||
symbol = token.symbol,
|
symbol = token.symbol,
|
||||||
color = token.color,
|
color = token.color,
|
||||||
image = "",
|
image = "",
|
||||||
category = ord(TokenListItemCategory.General)
|
category = ord(TokenListItemCategory.General),
|
||||||
)
|
)
|
||||||
|
|
||||||
tokenListItems.add(tokenListItem)
|
tokenListItems.add(tokenListItem)
|
||||||
|
|
||||||
for community in communities:
|
for community in communities:
|
||||||
for token in community.communityTokensMetadata:
|
let communityTokens = self.controller.getCommunityTokens(community.id)
|
||||||
let tokenListItem = initTokenListItem(
|
for tokenMetadata in community.communityTokensMetadata:
|
||||||
key = token.symbol,
|
# Set fallback supply to infinite in case we don't have it
|
||||||
name = token.name,
|
var supply = "1"
|
||||||
symbol = token.symbol,
|
var infiniteSupply = true
|
||||||
color = "", # community tokens don't have `color`
|
for communityToken in communityTokens:
|
||||||
image = token.image,
|
if communityToken.symbol == tokenMetadata.symbol:
|
||||||
category = ord(TokenListItemCategory.Community),
|
supply = communityToken.supply.toString(10)
|
||||||
communityId = community.id,
|
infiniteSupply = communityToken.infiniteSupply
|
||||||
)
|
break
|
||||||
collectiblesListItems.add(tokenListItem)
|
collectiblesListItems.add(self.createCommunityTokenItem(
|
||||||
|
tokenMetadata,
|
||||||
|
community.id,
|
||||||
|
supply,
|
||||||
|
infiniteSupply,
|
||||||
|
))
|
||||||
|
|
||||||
self.view.setTokenListItems(tokenListItems)
|
self.view.setTokenListItems(tokenListItems)
|
||||||
self.view.setCollectiblesListItems(collectiblesListItems)
|
self.view.setCollectiblesListItems(collectiblesListItems)
|
||||||
@ -449,14 +468,21 @@ method onOwnedCollectiblesUpdated*(self: Module) =
|
|||||||
self.buildTokenList()
|
self.buildTokenList()
|
||||||
|
|
||||||
method onCommunityTokenMetadataAdded*(self: Module, communityId: string, tokenMetadata: CommunityTokensMetadataDto) =
|
method onCommunityTokenMetadataAdded*(self: Module, communityId: string, tokenMetadata: CommunityTokensMetadataDto) =
|
||||||
let tokenListItem = initTokenListItem(
|
let communityTokens = self.controller.getCommunityTokens(communityId)
|
||||||
key = tokenMetadata.symbol,
|
var tokenListItem: TokenListItem
|
||||||
name = tokenMetadata.name,
|
# Set fallback supply to infinite in case we don't have it
|
||||||
symbol = tokenMetadata.symbol,
|
var supply = "1"
|
||||||
color = "", # tokenMetadata doesn't provide a color
|
var infiniteSupply = true
|
||||||
image = tokenMetadata.image,
|
for communityToken in communityTokens:
|
||||||
category = ord(TokenListItemCategory.Community),
|
if communityToken.symbol == tokenMetadata.symbol:
|
||||||
|
supply = communityToken.supply.toString(10)
|
||||||
|
infiniteSupply = communityToken.infiniteSupply
|
||||||
|
break
|
||||||
|
tokenListItem = self.createCommunityTokenItem(
|
||||||
|
tokenMetadata,
|
||||||
communityId,
|
communityId,
|
||||||
|
supply,
|
||||||
|
infiniteSupply,
|
||||||
)
|
)
|
||||||
|
|
||||||
if tokenMetadata.tokenType == community_dto.TokenType.ERC721 and
|
if tokenMetadata.tokenType == community_dto.TokenType.ERC721 and
|
||||||
|
@ -14,6 +14,8 @@ type
|
|||||||
image*: string
|
image*: string
|
||||||
category*: int
|
category*: int
|
||||||
communityId*: string
|
communityId*: string
|
||||||
|
supply*: string
|
||||||
|
infiniteSupply*: bool
|
||||||
|
|
||||||
proc initTokenListItem*(
|
proc initTokenListItem*(
|
||||||
key: string,
|
key: string,
|
||||||
@ -22,7 +24,9 @@ proc initTokenListItem*(
|
|||||||
color: string,
|
color: string,
|
||||||
image: string,
|
image: string,
|
||||||
category: int,
|
category: int,
|
||||||
communityId: string = ""
|
communityId: string = "",
|
||||||
|
supply: string = "1",
|
||||||
|
infiniteSupply: bool = true,
|
||||||
): TokenListItem =
|
): TokenListItem =
|
||||||
result.key = key
|
result.key = key
|
||||||
result.symbol = symbol
|
result.symbol = symbol
|
||||||
@ -31,6 +35,8 @@ proc initTokenListItem*(
|
|||||||
result.image = image
|
result.image = image
|
||||||
result.category = category
|
result.category = category
|
||||||
result.communityId = communityId
|
result.communityId = communityId
|
||||||
|
result.supply = supply
|
||||||
|
result.infiniteSupply = infiniteSupply
|
||||||
|
|
||||||
proc `$`*(self: TokenListItem): string =
|
proc `$`*(self: TokenListItem): string =
|
||||||
result = fmt"""TokenListItem(
|
result = fmt"""TokenListItem(
|
||||||
@ -40,6 +46,8 @@ proc `$`*(self: TokenListItem): string =
|
|||||||
symbol: {self.symbol},
|
symbol: {self.symbol},
|
||||||
category: {self.category},
|
category: {self.category},
|
||||||
communityId: {self.communityId},
|
communityId: {self.communityId},
|
||||||
|
supply: {self.supply},
|
||||||
|
infiniteSupply: {self.infiniteSupply},
|
||||||
]"""
|
]"""
|
||||||
|
|
||||||
proc getKey*(self: TokenListItem): string =
|
proc getKey*(self: TokenListItem): string =
|
||||||
@ -62,3 +70,9 @@ proc getCategory*(self: TokenListItem): int =
|
|||||||
|
|
||||||
proc getCommunityId*(self: TokenListItem): string =
|
proc getCommunityId*(self: TokenListItem): string =
|
||||||
return self.communityId
|
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
|
Image
|
||||||
Category
|
Category
|
||||||
CommunityId
|
CommunityId
|
||||||
|
Supply
|
||||||
|
InfiniteSupply
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type TokenListModel* = ref object of QAbstractListModel
|
type TokenListModel* = ref object of QAbstractListModel
|
||||||
@ -76,6 +78,8 @@ QtObject:
|
|||||||
ModelRole.Image.int:"icon",
|
ModelRole.Image.int:"icon",
|
||||||
ModelRole.Category.int:"category",
|
ModelRole.Category.int:"category",
|
||||||
ModelRole.CommunityId.int:"communityId",
|
ModelRole.CommunityId.int:"communityId",
|
||||||
|
ModelRole.Supply.int:"supply",
|
||||||
|
ModelRole.InfiniteSupply.int:"infiniteSupply",
|
||||||
}.toTable
|
}.toTable
|
||||||
|
|
||||||
method rowCount(self: TokenlistModel, index: QModelIndex = nil): int =
|
method rowCount(self: TokenlistModel, index: QModelIndex = nil): int =
|
||||||
@ -105,3 +109,7 @@ QtObject:
|
|||||||
result = newQVariant(item.getCategory())
|
result = newQVariant(item.getCategory())
|
||||||
of ModelRole.CommunityId:
|
of ModelRole.CommunityId:
|
||||||
result = newQVariant(item.getCommunityId())
|
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