parent
c61fd6057b
commit
18a50c6de5
|
@ -1,4 +1,5 @@
|
|||
import NimQml, json, strformat, sequtils, strutils, stint, strutils
|
||||
import options
|
||||
|
||||
import backend/collectibles as backend
|
||||
import collectible_trait_model
|
||||
|
@ -157,6 +158,46 @@ QtObject:
|
|||
QtProperty[string] networkShortName:
|
||||
read = getNetworkShortName
|
||||
|
||||
proc getCommunityId*(self: CollectibleDetailsEntry): string {.slot.} =
|
||||
if self.data == nil or isNone(self.data.communityInfo):
|
||||
return ""
|
||||
return self.data.communityInfo.get().communityId
|
||||
|
||||
QtProperty[string] communityId:
|
||||
read = getCommunityId
|
||||
|
||||
proc getCommunityName*(self: CollectibleDetailsEntry): string {.slot.} =
|
||||
if self.data == nil or isNone(self.data.communityInfo):
|
||||
return ""
|
||||
return self.data.communityInfo.get().communityName
|
||||
|
||||
QtProperty[string] communityName:
|
||||
read = getCommunityName
|
||||
|
||||
proc getCommunityColor*(self: CollectibleDetailsEntry): string {.slot.} =
|
||||
if self.data == nil or isNone(self.data.communityInfo):
|
||||
return ""
|
||||
return self.data.communityInfo.get().communityColor
|
||||
|
||||
QtProperty[string] communityColor:
|
||||
read = getCommunityColor
|
||||
|
||||
proc getCommunityImage*(self: CollectibleDetailsEntry): string {.slot.} =
|
||||
if self.data == nil or isNone(self.data.communityInfo):
|
||||
return ""
|
||||
return self.data.communityInfo.get().communityImage
|
||||
|
||||
QtProperty[string] communityImage:
|
||||
read = getCommunityImage
|
||||
|
||||
proc getCommunityPrivilegesLevel*(self: CollectibleDetailsEntry): int {.slot.} =
|
||||
if self.data == nil or isNone(self.data.communityInfo):
|
||||
return 0
|
||||
return int(self.data.communityInfo.get().privilegesLevel)
|
||||
|
||||
QtProperty[int] communityPrivilegesLevel:
|
||||
read = getCommunityPrivilegesLevel
|
||||
|
||||
proc getNetworkColor*(self: CollectibleDetailsEntry): string {.slot.} =
|
||||
return self.extradata.networkColor
|
||||
|
||||
|
|
|
@ -15,6 +15,10 @@ type
|
|||
collectionImageUrl: string
|
||||
isLoading: bool
|
||||
isPinned: bool
|
||||
communityId: string
|
||||
communityName: string
|
||||
communityColor: string
|
||||
communityPrivilegesLevel: int
|
||||
|
||||
proc initItem*(
|
||||
chainId: int,
|
||||
|
@ -28,7 +32,12 @@ proc initItem*(
|
|||
collectionName: string,
|
||||
collectionSlug: string,
|
||||
collectionImageUrl: string,
|
||||
isPinned: bool
|
||||
isPinned: bool,
|
||||
communityId: string,
|
||||
communityName: string,
|
||||
communityColor: string,
|
||||
communityPrivilegesLevel: int
|
||||
|
||||
): Item =
|
||||
result.chainId = chainId
|
||||
result.contractAddress = contractAddress
|
||||
|
@ -43,9 +52,13 @@ proc initItem*(
|
|||
result.collectionImageUrl = collectionImageUrl
|
||||
result.isLoading = false
|
||||
result.isPinned = isPinned
|
||||
result.communityId = communityId
|
||||
result.communityName = communityName
|
||||
result.communityColor = communityColor
|
||||
result.communityPrivilegesLevel = communityPrivilegesLevel
|
||||
|
||||
proc initItem*: Item =
|
||||
result = initItem(0, "", u256(0), "", "", "", "", "transparent", "Collectibles", "", "", false)
|
||||
result = initItem(0, "", u256(0), "", "", "", "", "transparent", "Collectibles", "", "", false, "", "", "", 0)
|
||||
|
||||
proc initLoadingItem*: Item =
|
||||
result = initItem()
|
||||
|
@ -66,6 +79,10 @@ proc `$`*(self: Item): string =
|
|||
collectionImageUrl: {self.collectionImageUrl},
|
||||
isLoading: {self.isLoading},
|
||||
isPinned: {self.isPinned},
|
||||
communityId: {self.communityId},
|
||||
communityName: {self.communityName},
|
||||
communityColor: {self.communityColor},
|
||||
communityPrivilegesLevel: {self.communityPrivilegesLevel},
|
||||
]"""
|
||||
|
||||
proc getChainId*(self: Item): int =
|
||||
|
@ -114,3 +131,15 @@ proc getIsLoading*(self: Item): bool =
|
|||
|
||||
proc getIsPinned*(self: Item): bool =
|
||||
return self.isPinned
|
||||
|
||||
proc getCommunityId*(self: Item): string =
|
||||
return self.communityId
|
||||
|
||||
proc getCommunityName*(self: Item): string =
|
||||
return self.communityName
|
||||
|
||||
proc getCommunityColor*(self: Item): string =
|
||||
return self.communityColor
|
||||
|
||||
proc getCommunityPrivilegesLevel*(self: Item): int =
|
||||
return self.communityPrivilegesLevel
|
||||
|
|
|
@ -21,6 +21,11 @@ type
|
|||
CollectionSlug
|
||||
IsLoading
|
||||
IsPinned
|
||||
# Community-related roles
|
||||
CommunityId
|
||||
CommunityName
|
||||
CommunityColor
|
||||
CommunityPrivilegesLevel
|
||||
|
||||
const loadingItemsCount = 10
|
||||
|
||||
|
@ -154,6 +159,10 @@ QtObject:
|
|||
CollectibleRole.CollectionSlug.int:"collectionSlug",
|
||||
CollectibleRole.IsLoading.int:"isLoading",
|
||||
CollectibleRole.IsPinned.int:"isPinned",
|
||||
CollectibleRole.CommunityId.int:"communityId",
|
||||
CollectibleRole.CommunityName.int:"communityName",
|
||||
CollectibleRole.CommunityColor.int:"communityColor",
|
||||
CollectibleRole.CommunityPrivilegesLevel.int:"communityPrivilegesLevel",
|
||||
}.toTable
|
||||
|
||||
method data(self: Model, index: QModelIndex, role: int): QVariant =
|
||||
|
@ -196,6 +205,14 @@ QtObject:
|
|||
result = newQVariant(false)
|
||||
of CollectibleRole.IsPinned:
|
||||
result = newQVariant(item.getIsPinned())
|
||||
of CollectibleRole.CommunityId:
|
||||
result = newQVariant(item.getCommunityId())
|
||||
of CollectibleRole.CommunityName:
|
||||
result = newQVariant(item.getCommunityName())
|
||||
of CollectibleRole.CommunityColor:
|
||||
result = newQVariant(item.getCommunityColor())
|
||||
of CollectibleRole.CommunityPrivilegesLevel:
|
||||
result = newQVariant(item.getCommunityPrivilegesLevel())
|
||||
else:
|
||||
# Loading item
|
||||
case enumRole:
|
||||
|
@ -224,6 +241,10 @@ QtObject:
|
|||
of "collectionSlug": result = item.getCollectionSlug()
|
||||
of "isLoading": result = $false
|
||||
of "isPinned": result = $item.getIsPinned()
|
||||
of "communityId": result = item.getCommunityId()
|
||||
of "communityName": result = item.getCommunityName()
|
||||
of "communityColor": result = item.getCommunityColor()
|
||||
of "communityPrivilegesLevel": result = $item.getCommunityPrivilegesLevel()
|
||||
|
||||
proc appendCollectibleItems(self: Model, newItems: seq[Item]) =
|
||||
if len(newItems) == 0:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import sequtils, sugar, times
|
||||
import sequtils, sugar, times, options
|
||||
import backend/collectibles as backend
|
||||
import collectibles_item
|
||||
|
||||
|
@ -9,6 +9,17 @@ proc collectibleToItem*(c: backend.CollectibleHeader, isPinned: bool = false) :
|
|||
mediaUrl = c.imageUrl
|
||||
mediaType = "image"
|
||||
|
||||
var communityId = ""
|
||||
var communityName = ""
|
||||
var communityColor = ""
|
||||
var communityPrivilegesLevel = 0
|
||||
if isSome(c.communityHeader):
|
||||
let communityHeader = c.communityHeader.get()
|
||||
communityId = communityHeader.communityId
|
||||
communityName = communityHeader.communityName
|
||||
communityColor = communityHeader.communityColor
|
||||
communityPrivilegesLevel = int(communityHeader.privilegesLevel)
|
||||
|
||||
return initItem(
|
||||
c.id.contractID.chainID,
|
||||
c.id.contractID.address,
|
||||
|
@ -21,5 +32,9 @@ proc collectibleToItem*(c: backend.CollectibleHeader, isPinned: bool = false) :
|
|||
c.collectionName,
|
||||
c.collectionSlug,
|
||||
c.collectionImageUrl,
|
||||
isPinned
|
||||
isPinned,
|
||||
communityId,
|
||||
communityName,
|
||||
communityColor,
|
||||
communityPrivilegesLevel
|
||||
)
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
import json, strformat
|
||||
import stint, Tables
|
||||
import stint, Tables, options
|
||||
import community_tokens_types
|
||||
|
||||
const communityHeaderField = "community_header"
|
||||
const communityInfoField = "community_info"
|
||||
|
||||
type
|
||||
# Mirrors services/wallet/thirdparty/collectible_types.go ContractID
|
||||
|
@ -34,6 +38,7 @@ type
|
|||
# Mirrors services/wallet/thirdparty/collectible_types.go CollectibleData
|
||||
CollectibleData* = ref object of RootObj
|
||||
id* : CollectibleUniqueID
|
||||
communityId*: string
|
||||
name*: string
|
||||
description*: string
|
||||
permalink*: string
|
||||
|
@ -45,6 +50,13 @@ type
|
|||
tokenUri*: string
|
||||
collectionData*: CollectionData
|
||||
|
||||
# Mirrors services/wallet/collectibles/types.go CommunityHeader
|
||||
CollectibleCommunityHeader* = ref object of RootObj
|
||||
communityId*: string
|
||||
communityName*: string
|
||||
communityColor*: string
|
||||
privilegesLevel*: PrivilegesLevel
|
||||
|
||||
# Mirrors services/wallet/collectibles/types.go CollectibleHeader
|
||||
CollectibleHeader* = ref object of RootObj
|
||||
id* : CollectibleUniqueID
|
||||
|
@ -56,6 +68,15 @@ type
|
|||
collectionName*: string
|
||||
collectionSlug*: string
|
||||
collectionImageUrl*: string
|
||||
communityHeader*: Option[CollectibleCommunityHeader]
|
||||
|
||||
# Mirrors services/wallet/thirdparty/collectible_types.go CollectiblesCommunityInfo
|
||||
CollectibleCommunityInfo* = ref object of RootObj
|
||||
communityId*: string
|
||||
communityName*: string
|
||||
communityColor*: string
|
||||
communityImage*: string
|
||||
privilegesLevel*: PrivilegesLevel
|
||||
|
||||
# Mirrors services/wallet/collectibles/types.go CollectibleDetails
|
||||
CollectibleDetails* = ref object of RootObj
|
||||
|
@ -71,6 +92,7 @@ type
|
|||
collectionName*: string
|
||||
collectionSlug*: string
|
||||
collectionImageUrl*: string
|
||||
communityInfo*: Option[CollectibleCommunityInfo]
|
||||
|
||||
# Mirrors services/wallet/thirdparty/collectible_types.go TokenBalance
|
||||
CollectibleBalance* = ref object
|
||||
|
@ -209,6 +231,7 @@ proc fromJson*(t: JsonNode, T: typedesc[ref CollectionData]): ref CollectionData
|
|||
proc `$`*(self: CollectibleData): string =
|
||||
return fmt"""CollectibleData(
|
||||
id:{self.id},
|
||||
communityId:{self.communityId},
|
||||
name:{self.name},
|
||||
description:{self.description},
|
||||
permalink:{self.permalink},
|
||||
|
@ -229,6 +252,7 @@ proc getCollectibleTraits*(t: JsonNode): seq[CollectibleTrait] =
|
|||
proc fromJson*(t: JsonNode, T: typedesc[CollectibleData]): CollectibleData {.inline.} =
|
||||
result = CollectibleData()
|
||||
result.id = fromJson(t["id"], CollectibleUniqueID)
|
||||
result.communityId = t["community_id"].getStr()
|
||||
result.name = t["name"].getStr()
|
||||
result.description = t["description"].getStr()
|
||||
result.permalink = t["permalink"].getStr()
|
||||
|
@ -243,6 +267,26 @@ proc fromJson*(t: JsonNode, T: typedesc[ref CollectibleData]): ref CollectibleDa
|
|||
result = new(CollectibleData)
|
||||
result[] = fromJson(t, CollectibleData)
|
||||
|
||||
# CollectibleCommunityHeader
|
||||
proc `$`*(self: CollectibleCommunityHeader): string =
|
||||
return fmt"""CollectibleCommunityHeader(
|
||||
communityId:{self.communityId},
|
||||
communityName:{self.communityName},
|
||||
communityColor:{self.communityColor},
|
||||
privilegesLevel:{self.privilegesLevel}
|
||||
)"""
|
||||
|
||||
proc fromJson*(t: JsonNode, T: typedesc[CollectibleCommunityHeader]): CollectibleCommunityHeader {.inline.} =
|
||||
result = CollectibleCommunityHeader()
|
||||
result.communityId = t["community_id"].getStr
|
||||
result.communityName = t["community_name"].getStr
|
||||
result.communityColor = t["community_color"].getStr
|
||||
result.privilegesLevel = PrivilegesLevel(t["privileges_level"].getInt)
|
||||
|
||||
proc fromJson*(t: JsonNode, T: typedesc[ref CollectibleCommunityHeader]): ref CollectibleCommunityHeader {.inline.} =
|
||||
result = new(CollectibleCommunityHeader)
|
||||
result[] = fromJson(t, CollectibleCommunityHeader)
|
||||
|
||||
# CollectibleHeader
|
||||
proc `$`*(self: CollectibleHeader): string =
|
||||
return fmt"""CollectibleHeader(
|
||||
|
@ -254,7 +298,8 @@ proc `$`*(self: CollectibleHeader): string =
|
|||
backgroundColor:{self.backgroundColor},
|
||||
collectionName:{self.collectionName},
|
||||
collectionSlug:{self.collectionSlug},
|
||||
collectionImageUrl:{self.collectionImageUrl}
|
||||
collectionImageUrl:{self.collectionImageUrl},
|
||||
communityHeader:{self.communityHeader}
|
||||
)"""
|
||||
|
||||
proc fromJson*(t: JsonNode, T: typedesc[CollectibleHeader]): CollectibleHeader {.inline.} =
|
||||
|
@ -268,6 +313,30 @@ proc fromJson*(t: JsonNode, T: typedesc[CollectibleHeader]): CollectibleHeader {
|
|||
result.collectionName = t["collection_name"].getStr()
|
||||
result.collectionSlug = t["collection_slug"].getStr()
|
||||
result.collectionImageUrl = t["collection_image_url"].getStr()
|
||||
if t.contains(communityHeaderField) and t[communityHeaderField].kind != JNull:
|
||||
result.communityHeader = some(fromJson(t[communityHeaderField], CollectibleCommunityHeader))
|
||||
|
||||
# CollectibleCommunityInfo
|
||||
proc `$`*(self: CollectibleCommunityInfo): string =
|
||||
return fmt"""CollectibleCommunityInfo(
|
||||
communityId:{self.communityId},
|
||||
communityName:{self.communityName},
|
||||
communityColor:{self.communityColor},
|
||||
communityImage:{self.communityImage},
|
||||
privilegesLevel:{self.privilegesLevel}
|
||||
)"""
|
||||
|
||||
proc fromJson*(t: JsonNode, T: typedesc[CollectibleCommunityInfo]): CollectibleCommunityInfo {.inline.} =
|
||||
result = CollectibleCommunityInfo()
|
||||
result.communityId = t["community_id"].getStr
|
||||
result.communityName = t["community_name"].getStr
|
||||
result.communityColor = t["community_color"].getStr
|
||||
result.communityImage = t["community_image"].getStr
|
||||
result.privilegesLevel = PrivilegesLevel(t["privileges_level"].getInt)
|
||||
|
||||
proc fromJson*(t: JsonNode, T: typedesc[ref CollectibleCommunityInfo]): ref CollectibleCommunityInfo {.inline.} =
|
||||
result = new(CollectibleCommunityInfo)
|
||||
result[] = fromJson(t, CollectibleCommunityInfo)
|
||||
|
||||
# CollectibleDetails
|
||||
proc `$`*(self: CollectibleDetails): string =
|
||||
|
@ -282,7 +351,8 @@ proc `$`*(self: CollectibleDetails): string =
|
|||
backgroundColor:{self.backgroundColor},
|
||||
collectionName:{self.collectionName},
|
||||
collectionSlug:{self.collectionSlug},
|
||||
collectionImageUrl:{self.collectionImageUrl}
|
||||
collectionImageUrl:{self.collectionImageUrl},
|
||||
communityInfo:{self.communityInfo}
|
||||
)"""
|
||||
|
||||
proc fromJson*(t: JsonNode, T: typedesc[CollectibleDetails]): CollectibleDetails {.inline.} =
|
||||
|
@ -298,6 +368,8 @@ proc fromJson*(t: JsonNode, T: typedesc[CollectibleDetails]): CollectibleDetails
|
|||
result.collectionName = t["collection_name"].getStr()
|
||||
result.collectionSlug = t["collection_slug"].getStr()
|
||||
result.collectionImageUrl = t["collection_image_url"].getStr()
|
||||
if t.contains(communityInfoField) and t[communityInfoField].kind != JNull:
|
||||
result.communityInfo = some(fromJson(t[communityInfoField], CollectibleCommunityInfo))
|
||||
|
||||
proc fromJson*(t: JsonNode, T: typedesc[ref CollectibleDetails]): ref CollectibleDetails {.inline.} =
|
||||
result = new(CollectibleDetails)
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
type
|
||||
# see protocol/communities/token/community_token.go PrivilegesLevel
|
||||
PrivilegesLevel* {.pure.} = enum
|
||||
Owner, Master, Community
|
|
@ -1 +1 @@
|
|||
Subproject commit 0f065a9f07aebcb25fdad8ff6a153cc3444ecf0d
|
||||
Subproject commit ba5cd9c1a462ef57431dd69ccfd88b9dafd7d744
|
Loading…
Reference in New Issue