chore(@dekstop/wallet): cleanup collectibles data types
This commit is contained in:
parent
74d3bedc11
commit
7e8cf4fa4d
|
@ -46,6 +46,7 @@ proc newModule*(
|
|||
result.collectiblesController = collectiblesc.newController(
|
||||
requestId = int32(backend_collectibles.CollectiblesRequestID.ProfileShowcase),
|
||||
autofetch = false,
|
||||
networkService = networkService,
|
||||
events = events
|
||||
)
|
||||
result.moduleLoaded = false
|
||||
|
|
|
@ -131,6 +131,7 @@ proc newModule*(
|
|||
let collectiblesController = collectiblesc.newController(
|
||||
requestId = int32(backend_collectibles.CollectiblesRequestID.WalletAccount),
|
||||
autofetch = false,
|
||||
networkService = networkService,
|
||||
events = events
|
||||
)
|
||||
result.collectiblesController = collectiblesController
|
||||
|
|
|
@ -77,6 +77,7 @@ proc newModule*(
|
|||
result.collectiblesController = collectiblesc.newController(
|
||||
requestId = int32(backend_collectibles.CollectiblesRequestID.WalletSend),
|
||||
autofetch = true,
|
||||
networkService = networkService,
|
||||
events = events
|
||||
)
|
||||
result.nestedCollectiblesModel = nested_collectibles.newModel(result.collectiblesController.getModel())
|
||||
|
|
|
@ -17,19 +17,19 @@ type
|
|||
# It is used to display a detailed collectibles entry in the QML UI
|
||||
QtObject:
|
||||
type
|
||||
CollectibleDetailsEntry* = ref object of QObject
|
||||
CollectiblesEntry* = ref object of QObject
|
||||
id: backend.CollectibleUniqueID
|
||||
data: backend.Collectible
|
||||
extradata: ExtraData
|
||||
traits: TraitModel
|
||||
|
||||
proc setup(self: CollectibleDetailsEntry) =
|
||||
proc setup(self: CollectiblesEntry) =
|
||||
self.QObject.setup
|
||||
|
||||
proc delete*(self: CollectibleDetailsEntry) =
|
||||
proc delete*(self: CollectiblesEntry) =
|
||||
self.QObject.delete
|
||||
|
||||
proc newCollectibleDetailsFullEntry*(data: backend.Collectible, extradata: ExtraData): CollectibleDetailsEntry =
|
||||
proc newCollectibleDetailsFullEntry*(data: backend.Collectible, extradata: ExtraData): CollectiblesEntry =
|
||||
new(result, delete)
|
||||
result.id = data.id
|
||||
result.data = data
|
||||
|
@ -40,14 +40,14 @@ QtObject:
|
|||
result.traits.setItems(traits)
|
||||
result.setup()
|
||||
|
||||
proc newCollectibleDetailsBasicEntry*(id: backend.CollectibleUniqueID, extradata: ExtraData): CollectibleDetailsEntry =
|
||||
proc newCollectibleDetailsBasicEntry*(id: backend.CollectibleUniqueID, extradata: ExtraData): CollectiblesEntry =
|
||||
new(result, delete)
|
||||
result.id = id
|
||||
result.extradata = extradata
|
||||
result.traits = newTraitModel()
|
||||
result.setup()
|
||||
|
||||
proc newCollectibleDetailsEmptyEntry*(): CollectibleDetailsEntry =
|
||||
proc newCollectibleDetailsEmptyEntry*(): CollectiblesEntry =
|
||||
let id = backend.CollectibleUniqueID(
|
||||
contractID: backend.ContractID(
|
||||
chainID: 0,
|
||||
|
@ -58,51 +58,62 @@ QtObject:
|
|||
let extradata = ExtraData()
|
||||
return newCollectibleDetailsBasicEntry(id, extradata)
|
||||
|
||||
proc `$`*(self: CollectibleDetailsEntry): string =
|
||||
return fmt"""CollectibleDetailsEntry(
|
||||
proc `$`*(self: CollectiblesEntry): string =
|
||||
return fmt"""CollectiblesEntry(
|
||||
id:{self.id},
|
||||
data:{self.data},
|
||||
extradata:{self.extradata},
|
||||
traits:{self.traits}
|
||||
)"""
|
||||
|
||||
proc hasCollectibleData(self: CollectibleDetailsEntry): bool =
|
||||
proc hasCollectibleData(self: CollectiblesEntry): bool =
|
||||
return self.data != nil and isSome(self.data.collectibleData)
|
||||
|
||||
proc getCollectibleData(self: CollectibleDetailsEntry): backend.CollectibleData =
|
||||
proc getCollectibleData(self: CollectiblesEntry): backend.CollectibleData =
|
||||
return self.data.collectibleData.get()
|
||||
|
||||
proc hasCollectionData(self: CollectibleDetailsEntry): bool =
|
||||
proc hasCollectionData(self: CollectiblesEntry): bool =
|
||||
return self.data != nil and isSome(self.data.collectionData)
|
||||
|
||||
proc getCollectionData(self: CollectibleDetailsEntry): backend.CollectionData =
|
||||
proc getCollectionData(self: CollectiblesEntry): backend.CollectionData =
|
||||
return self.data.collectionData.get()
|
||||
|
||||
proc hasCommunityData(self: CollectibleDetailsEntry): bool =
|
||||
proc hasCommunityData(self: CollectiblesEntry): bool =
|
||||
return self.data != nil and isSome(self.data.communityData)
|
||||
|
||||
proc getCommunityData(self: CollectibleDetailsEntry): backend.CommunityData =
|
||||
proc getCommunityData(self: CollectiblesEntry): backend.CommunityData =
|
||||
return self.data.communityData.get()
|
||||
|
||||
proc getChainID*(self: CollectibleDetailsEntry): int {.slot.} =
|
||||
proc getChainID*(self: CollectiblesEntry): int {.slot.} =
|
||||
return self.id.contractID.chainID
|
||||
|
||||
QtProperty[int] chainId:
|
||||
read = getChainID
|
||||
|
||||
proc getContractAddress*(self: CollectibleDetailsEntry): string {.slot.} =
|
||||
proc getContractAddress*(self: CollectiblesEntry): string {.slot.} =
|
||||
return self.id.contractID.address
|
||||
|
||||
QtProperty[string] contractAddress:
|
||||
read = getContractAddress
|
||||
|
||||
proc getTokenID*(self: CollectibleDetailsEntry): string {.slot.} =
|
||||
return self.id.tokenID.toString()
|
||||
proc getTokenID*(self: CollectiblesEntry): UInt256 =
|
||||
return self.id.tokenID
|
||||
|
||||
proc getTokenIDAsString*(self: CollectiblesEntry): string {.slot.} =
|
||||
return self.getTokenID().toString()
|
||||
|
||||
QtProperty[string] tokenId:
|
||||
read = getTokenID
|
||||
read = getTokenIDAsString
|
||||
|
||||
proc getName*(self: CollectibleDetailsEntry): string {.slot.} =
|
||||
# Unique ID to identify collectible, generated by us
|
||||
proc getID*(self: CollectiblesEntry): string =
|
||||
return fmt"{self.getChainId}+{self.getContractAddress}+{self.getTokenID}"
|
||||
|
||||
# Unique ID to identify collection, generated by us
|
||||
proc getCollectionID*(self: CollectiblesEntry): string =
|
||||
return fmt"{self.getChainId}+{self.getContractAddress}"
|
||||
|
||||
proc getName*(self: CollectiblesEntry): string {.slot.} =
|
||||
if not self.hasCollectibleData():
|
||||
return ""
|
||||
return self.data.collectibleData.get().name
|
||||
|
@ -110,7 +121,7 @@ QtObject:
|
|||
QtProperty[string] name:
|
||||
read = getName
|
||||
|
||||
proc getImageURL*(self: CollectibleDetailsEntry): string {.slot.} =
|
||||
proc getImageURL*(self: CollectiblesEntry): string {.slot.} =
|
||||
if not self.hasCollectibleData() or isNone(self.getCollectibleData().imageUrl):
|
||||
return ""
|
||||
return self.getCollectibleData().imageUrl.get()
|
||||
|
@ -118,23 +129,33 @@ QtObject:
|
|||
QtProperty[string] imageUrl:
|
||||
read = getImageURL
|
||||
|
||||
proc getMediaURL*(self: CollectibleDetailsEntry): string {.slot.} =
|
||||
proc getOriginalMediaURL(self: CollectiblesEntry): string =
|
||||
if not self.hasCollectibleData() or isNone(self.getCollectibleData().animationUrl):
|
||||
return ""
|
||||
return self.getCollectibleData().animationUrl.get()
|
||||
|
||||
proc getMediaURL*(self: CollectiblesEntry): string {.slot.} =
|
||||
result = self.getOriginalMediaURL()
|
||||
if result == "":
|
||||
result = self.getImageURL()
|
||||
|
||||
QtProperty[string] mediaUrl:
|
||||
read = getMediaURL
|
||||
|
||||
proc getMediaType*(self: CollectibleDetailsEntry): string {.slot.} =
|
||||
proc getOriginalMediaType(self: CollectiblesEntry): string =
|
||||
if not self.hasCollectibleData() or isNone(self.getCollectibleData().animationMediaType):
|
||||
return ""
|
||||
return self.getCollectibleData().animationMediaType.get()
|
||||
|
||||
proc getMediaType*(self: CollectiblesEntry): string {.slot.} =
|
||||
result = self.getOriginalMediaType()
|
||||
if result == "":
|
||||
result = "image"
|
||||
|
||||
QtProperty[string] mediaType:
|
||||
read = getMediaType
|
||||
|
||||
proc getBackgroundColor*(self: CollectibleDetailsEntry): string {.slot.} =
|
||||
proc getBackgroundColor*(self: CollectiblesEntry): string {.slot.} =
|
||||
var color = "transparent"
|
||||
if self.hasCollectibleData() and isSome(self.getCollectibleData().backgroundColor):
|
||||
let backgroundColor = self.getCollectibleData().backgroundColor.get()
|
||||
|
@ -145,7 +166,7 @@ QtObject:
|
|||
QtProperty[string] backgroundColor:
|
||||
read = getBackgroundColor
|
||||
|
||||
proc getDescription*(self: CollectibleDetailsEntry): string {.slot.} =
|
||||
proc getDescription*(self: CollectiblesEntry): string {.slot.} =
|
||||
if not self.hasCollectibleData() or isNone(self.getCollectibleData().description):
|
||||
return ""
|
||||
return self.getCollectibleData().description.get()
|
||||
|
@ -153,7 +174,15 @@ QtObject:
|
|||
QtProperty[string] description:
|
||||
read = getDescription
|
||||
|
||||
proc getCollectionName*(self: CollectibleDetailsEntry): string {.slot.} =
|
||||
proc getCollectionSlug*(self: CollectiblesEntry): string {.slot.} =
|
||||
if not self.hasCollectionData():
|
||||
return ""
|
||||
return self.getCollectionData().slug
|
||||
|
||||
QtProperty[string] collectionSlug:
|
||||
read = getCollectionSlug
|
||||
|
||||
proc getCollectionName*(self: CollectiblesEntry): string {.slot.} =
|
||||
if not self.hasCollectionData():
|
||||
return ""
|
||||
return self.getCollectionData().name
|
||||
|
@ -161,7 +190,7 @@ QtObject:
|
|||
QtProperty[string] collectionName:
|
||||
read = getCollectionName
|
||||
|
||||
proc getCollectionImageURL*(self: CollectibleDetailsEntry): string {.slot.} =
|
||||
proc getCollectionImageURL*(self: CollectiblesEntry): string {.slot.} =
|
||||
if not self.hasCollectionData():
|
||||
return ""
|
||||
return self.getCollectionData().imageUrl
|
||||
|
@ -169,19 +198,19 @@ QtObject:
|
|||
QtProperty[string] collectionImageUrl:
|
||||
read = getCollectionImageURL
|
||||
|
||||
proc getTraits*(self: CollectibleDetailsEntry): QVariant {.slot.} =
|
||||
proc getTraits*(self: CollectiblesEntry): QVariant {.slot.} =
|
||||
return newQVariant(self.traits)
|
||||
|
||||
QtProperty[QVariant] traits:
|
||||
read = getTraits
|
||||
|
||||
proc getNetworkShortName*(self: CollectibleDetailsEntry): string {.slot.} =
|
||||
proc getNetworkShortName*(self: CollectiblesEntry): string {.slot.} =
|
||||
return self.extradata.networkShortName
|
||||
|
||||
QtProperty[string] networkShortName:
|
||||
read = getNetworkShortName
|
||||
|
||||
proc getCommunityId*(self: CollectibleDetailsEntry): string {.slot.} =
|
||||
proc getCommunityID*(self: CollectiblesEntry): string {.slot.} =
|
||||
if not self.hasCommunityData():
|
||||
return ""
|
||||
return self.getCommunityData().id
|
||||
|
@ -189,7 +218,7 @@ QtObject:
|
|||
QtProperty[string] communityId:
|
||||
read = getCommunityId
|
||||
|
||||
proc getCommunityName*(self: CollectibleDetailsEntry): string {.slot.} =
|
||||
proc getCommunityName*(self: CollectiblesEntry): string {.slot.} =
|
||||
if not self.hasCommunityData():
|
||||
return ""
|
||||
return self.getCommunityData().name
|
||||
|
@ -197,7 +226,7 @@ QtObject:
|
|||
QtProperty[string] communityName:
|
||||
read = getCommunityName
|
||||
|
||||
proc getCommunityColor*(self: CollectibleDetailsEntry): string {.slot.} =
|
||||
proc getCommunityColor*(self: CollectiblesEntry): string {.slot.} =
|
||||
if not self.hasCommunityData():
|
||||
return ""
|
||||
return self.getCommunityData().color
|
||||
|
@ -205,7 +234,7 @@ QtObject:
|
|||
QtProperty[string] communityColor:
|
||||
read = getCommunityColor
|
||||
|
||||
proc getCommunityPrivilegesLevel*(self: CollectibleDetailsEntry): int {.slot.} =
|
||||
proc getCommunityPrivilegesLevel*(self: CollectiblesEntry): int {.slot.} =
|
||||
if not self.hasCommunityData():
|
||||
return PrivilegesLevel.Community.int
|
||||
return int(self.getCommunityData().privilegesLevel)
|
||||
|
@ -213,7 +242,7 @@ QtObject:
|
|||
QtProperty[int] communityPrivilegesLevel:
|
||||
read = getCommunityPrivilegesLevel
|
||||
|
||||
proc getCommunityImage*(self: CollectibleDetailsEntry): string {.slot.} =
|
||||
proc getCommunityImage*(self: CollectiblesEntry): string {.slot.} =
|
||||
if not self.hasCommunityData() or isNone(self.getCommunityData().imageUrl):
|
||||
return ""
|
||||
return self.getCommunityData().imageUrl.get()
|
||||
|
@ -221,13 +250,13 @@ QtObject:
|
|||
QtProperty[string] communityImage:
|
||||
read = getCommunityImage
|
||||
|
||||
proc getNetworkColor*(self: CollectibleDetailsEntry): string {.slot.} =
|
||||
proc getNetworkColor*(self: CollectiblesEntry): string {.slot.} =
|
||||
return self.extradata.networkColor
|
||||
|
||||
QtProperty[string] networkColor:
|
||||
read = getNetworkColor
|
||||
|
||||
proc getNetworkIconURL*(self: CollectibleDetailsEntry): string {.slot.} =
|
||||
proc getNetworkIconURL*(self: CollectiblesEntry): string {.slot.} =
|
||||
return self.extradata.networkIconURL
|
||||
|
||||
QtProperty[string] networkIconUrl:
|
|
@ -1,145 +0,0 @@
|
|||
import strformat, stint
|
||||
|
||||
type
|
||||
Item* = object
|
||||
chainId: int
|
||||
contractAddress: string
|
||||
tokenId: UInt256
|
||||
name: string
|
||||
mediaUrl: string
|
||||
mediaType: string
|
||||
imageUrl: string
|
||||
backgroundColor: string
|
||||
collectionName: string
|
||||
collectionSlug: string
|
||||
collectionImageUrl: string
|
||||
isLoading: bool
|
||||
isPinned: bool
|
||||
communityId: string
|
||||
communityName: string
|
||||
communityColor: string
|
||||
communityPrivilegesLevel: int
|
||||
|
||||
proc initItem*(
|
||||
chainId: int,
|
||||
contractAddress: string,
|
||||
tokenId: UInt256,
|
||||
name: string,
|
||||
mediaUrl: string,
|
||||
mediaType: string,
|
||||
imageUrl: string,
|
||||
backgroundColor: string,
|
||||
collectionName: string,
|
||||
collectionSlug: string,
|
||||
collectionImageUrl: string,
|
||||
isPinned: bool,
|
||||
communityId: string,
|
||||
communityName: string,
|
||||
communityColor: string,
|
||||
communityPrivilegesLevel: int
|
||||
|
||||
): Item =
|
||||
result.chainId = chainId
|
||||
result.contractAddress = contractAddress
|
||||
result.tokenId = tokenId
|
||||
result.name = if (name != ""): name else: ("#" & tokenId.toString())
|
||||
result.mediaUrl = mediaUrl
|
||||
result.mediaType = mediaType
|
||||
result.imageUrl = imageUrl
|
||||
result.backgroundColor = if (backgroundColor == ""): "transparent" else: ("#" & backgroundColor)
|
||||
result.collectionName = collectionName
|
||||
result.collectionSlug = collectionSlug
|
||||
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, "", "", "", 0)
|
||||
|
||||
proc initLoadingItem*: Item =
|
||||
result = initItem()
|
||||
result.isLoading = true
|
||||
|
||||
proc `$`*(self: Item): string =
|
||||
result = fmt"""Collectibles(
|
||||
chainId: {self.chainId},
|
||||
contractAddress: {self.contractAddress},
|
||||
tokenId: {self.tokenId},
|
||||
name: {self.name},
|
||||
mediaUrl: {self.mediaUrl},
|
||||
mediaType: {self.mediaType},
|
||||
imageUrl: {self.imageUrl},
|
||||
backgroundColor: {self.backgroundColor},
|
||||
collectionName: {self.collectionName},
|
||||
collectionSlug: {self.collectionSlug},
|
||||
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 =
|
||||
return self.chainId
|
||||
|
||||
proc getContractAddress*(self: Item): string =
|
||||
return self.contractAddress
|
||||
|
||||
proc getTokenId*(self: Item): UInt256 =
|
||||
return self.tokenId
|
||||
|
||||
# Unique ID to identify collectible, generated by us
|
||||
proc getId*(self: Item): string =
|
||||
return fmt"{self.getChainId}+{self.getContractAddress}+{self.getTokenID}"
|
||||
|
||||
proc getName*(self: Item): string =
|
||||
return self.name
|
||||
|
||||
proc getMediaUrl*(self: Item): string =
|
||||
return self.mediaUrl
|
||||
|
||||
proc getMediaType*(self: Item): string =
|
||||
return self.mediaType
|
||||
|
||||
proc getImageUrl*(self: Item): string =
|
||||
return self.imageUrl
|
||||
|
||||
proc getBackgroundColor*(self: Item): string =
|
||||
return self.backgroundColor
|
||||
|
||||
# Unique ID to identify collection, generated by us
|
||||
proc getCollectionId*(self: Item): string =
|
||||
return fmt"{self.getChainId}+{self.getContractAddress}"
|
||||
|
||||
proc getCollectionName*(self: Item): string =
|
||||
return self.collectionName
|
||||
|
||||
proc getCollectionSlug*(self: Item): string =
|
||||
return self.collectionSlug
|
||||
|
||||
proc getCollectionImageUrl*(self: Item): string =
|
||||
return self.collectionImageUrl
|
||||
|
||||
proc getIsLoading*(self: Item): bool =
|
||||
return self.isLoading
|
||||
|
||||
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
|
|
@ -1,7 +1,7 @@
|
|||
import NimQml, Tables, strutils, strformat, sequtils, stint, json
|
||||
import logging
|
||||
|
||||
import ./collectibles_item
|
||||
import ./collectibles_entry
|
||||
import web3/ethtypes as eth
|
||||
import backend/activity as backend_activity
|
||||
import app_service/common/utils as common_utils
|
||||
|
@ -22,7 +22,6 @@ type
|
|||
CollectionName
|
||||
CollectionSlug
|
||||
IsLoading
|
||||
IsPinned
|
||||
# Community-related roles
|
||||
CommunityId
|
||||
CommunityName
|
||||
|
@ -34,7 +33,7 @@ const loadingItemsCount = 10
|
|||
QtObject:
|
||||
type
|
||||
Model* = ref object of QAbstractListModel
|
||||
items: seq[Item]
|
||||
items: seq[CollectiblesEntry]
|
||||
hasMore: bool
|
||||
isFetching: bool
|
||||
isUpdating: bool
|
||||
|
@ -160,7 +159,6 @@ QtObject:
|
|||
CollectibleRole.CollectionName.int:"collectionName",
|
||||
CollectibleRole.CollectionSlug.int:"collectionSlug",
|
||||
CollectibleRole.IsLoading.int:"isLoading",
|
||||
CollectibleRole.IsPinned.int:"isPinned",
|
||||
CollectibleRole.CommunityId.int:"communityId",
|
||||
CollectibleRole.CommunityName.int:"communityName",
|
||||
CollectibleRole.CommunityColor.int:"communityColor",
|
||||
|
@ -180,33 +178,31 @@ QtObject:
|
|||
let item = self.items[index.row]
|
||||
case enumRole:
|
||||
of CollectibleRole.Uid:
|
||||
result = newQVariant(item.getId())
|
||||
result = newQVariant(item.getID())
|
||||
of CollectibleRole.ChainId:
|
||||
result = newQVariant(item.getChainId())
|
||||
result = newQVariant(item.getChainID())
|
||||
of CollectibleRole.ContractAddress:
|
||||
result = newQVariant(item.getContractAddress())
|
||||
of CollectibleRole.TokenId:
|
||||
result = newQVariant(item.getTokenId().toString())
|
||||
result = newQVariant(item.getTokenIDAsString())
|
||||
of CollectibleRole.Name:
|
||||
result = newQVariant(item.getName())
|
||||
of CollectibleRole.MediaUrl:
|
||||
result = newQVariant(item.getMediaUrl())
|
||||
result = newQVariant(item.getMediaURL())
|
||||
of CollectibleRole.MediaType:
|
||||
result = newQVariant(item.getMediaType())
|
||||
of CollectibleRole.ImageUrl:
|
||||
result = newQVariant(item.getImageUrl())
|
||||
result = newQVariant(item.getImageURL())
|
||||
of CollectibleRole.BackgroundColor:
|
||||
result = newQVariant(item.getBackgroundColor())
|
||||
of CollectibleRole.CollectionUid:
|
||||
result = newQVariant(item.getCollectionId())
|
||||
result = newQVariant(item.getCollectionID())
|
||||
of CollectibleRole.CollectionName:
|
||||
result = newQVariant(item.getCollectionName())
|
||||
of CollectibleRole.CollectionSlug:
|
||||
result = newQVariant(item.getCollectionSlug())
|
||||
of CollectibleRole.IsLoading:
|
||||
result = newQVariant(false)
|
||||
of CollectibleRole.IsPinned:
|
||||
result = newQVariant(item.getIsPinned())
|
||||
of CollectibleRole.CommunityId:
|
||||
result = newQVariant(item.getCommunityId())
|
||||
of CollectibleRole.CommunityName:
|
||||
|
@ -229,26 +225,25 @@ QtObject:
|
|||
return
|
||||
let item = self.items[index]
|
||||
case column:
|
||||
of "uid": result = item.getId()
|
||||
of "chainId": result = $item.getChainId()
|
||||
of "uid": result = item.getID()
|
||||
of "chainId": result = $item.getChainID()
|
||||
of "contractAddress": result = item.getContractAddress()
|
||||
of "tokenId": result = item.getTokenId().toString()
|
||||
of "tokenId": result = item.getTokenIDAsString()
|
||||
of "name": result = item.getName()
|
||||
of "mediaUrl": result = item.getMediaUrl()
|
||||
of "mediaUrl": result = item.getMediaURL()
|
||||
of "mediaType": result = item.getMediaType()
|
||||
of "imageUrl": result = item.getImageUrl()
|
||||
of "imageUrl": result = item.getImageURL()
|
||||
of "backgroundColor": result = item.getBackgroundColor()
|
||||
of "collectionUid": result = item.getCollectionId()
|
||||
of "collectionUid": result = item.getCollectionID()
|
||||
of "collectionName": result = item.getCollectionName()
|
||||
of "collectionSlug": result = item.getCollectionSlug()
|
||||
of "isLoading": result = $false
|
||||
of "isPinned": result = $item.getIsPinned()
|
||||
of "communityId": result = item.getCommunityId()
|
||||
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]) =
|
||||
proc appendCollectibleItems(self: Model, newItems: seq[CollectiblesEntry]) =
|
||||
if len(newItems) == 0:
|
||||
return
|
||||
|
||||
|
@ -324,10 +319,10 @@ QtObject:
|
|||
else:
|
||||
self.removeLoadingItems()
|
||||
|
||||
proc getItems*(self: Model): seq[Item] =
|
||||
proc getItems*(self: Model): seq[CollectiblesEntry] =
|
||||
return self.items
|
||||
|
||||
proc setItems*(self: Model, newItems: seq[Item], offset: int, hasMore: bool) =
|
||||
proc setItems*(self: Model, newItems: seq[CollectiblesEntry], offset: int, hasMore: bool) =
|
||||
if offset == 0:
|
||||
self.removeCollectibleItems()
|
||||
elif offset != self.getCollectiblesCount():
|
||||
|
@ -351,15 +346,15 @@ QtObject:
|
|||
|
||||
proc getActivityToken*(self: Model, id: string): backend_activity.Token =
|
||||
for item in self.items:
|
||||
if(cmpIgnoreCase(item.getId(), id) == 0):
|
||||
if(cmpIgnoreCase(item.getID(), id) == 0):
|
||||
result.tokenType = TokenType.ERC721
|
||||
result.chainId = backend_activity.ChainId(item.getChainId())
|
||||
result.chainId = backend_activity.ChainId(item.getChainID())
|
||||
var contract = item.getContractAddress()
|
||||
if len(contract) > 0:
|
||||
var address: eth.Address
|
||||
address = eth.fromHex(eth.Address, contract)
|
||||
result.address = some(address)
|
||||
var tokenId = item.getTokenId()
|
||||
var tokenId = item.getTokenID()
|
||||
if tokenId > 0:
|
||||
result.tokenId = some(backend_activity.TokenId("0x" & stint.toHex(tokenId)))
|
||||
return result
|
||||
|
@ -376,8 +371,8 @@ QtObject:
|
|||
|
||||
proc getUidForData*(self: Model, tokenId: string, tokenAddress: string, chainId: int): string {.slot.} =
|
||||
for item in self.items:
|
||||
if(cmpIgnoreCase(item.getTokenId().toString(), tokenId) == 0 and cmpIgnoreCase(item.getContractAddress(), tokenAddress) == 0):
|
||||
return item.getId()
|
||||
if(cmpIgnoreCase(item.getTokenIDAsString(), tokenId) == 0 and cmpIgnoreCase(item.getContractAddress(), tokenAddress) == 0):
|
||||
return item.getID()
|
||||
# Fallback, create uid from data, because it still might not be fetched
|
||||
if chainId > 0 and len(tokenAddress) > 0 and len(tokenId) > 0:
|
||||
return $chainId & "+" & tokenAddress & "+" & tokenId
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import NimQml, Tables, strutils, strformat, sequtils
|
||||
|
||||
import ./collectibles_model as flat_model
|
||||
import ./collectibles_item as flat_item
|
||||
import ./collectibles_entry as flat_item
|
||||
import ./collectibles_nested_item as nested_item
|
||||
|
||||
import ./collectibles_nested_utils
|
||||
|
@ -120,11 +120,11 @@ QtObject:
|
|||
of "collectionName": result = item.getCollectionName()
|
||||
of "isCollection": result = $item.getIsCollection()
|
||||
|
||||
proc getCollectiblesPerCollectionId(items: seq[flat_item.Item]): Table[string, seq[flat_item.Item]] =
|
||||
var collectiblesPerCollection = initTable[string, seq[flat_item.Item]]()
|
||||
proc getCollectiblesPerCollectionId(items: seq[flat_item.CollectiblesEntry]): Table[string, seq[flat_item.CollectiblesEntry]] =
|
||||
var collectiblesPerCollection = initTable[string, seq[flat_item.CollectiblesEntry]]()
|
||||
|
||||
for item in items:
|
||||
let collectionId = item.getCollectionId()
|
||||
let collectionId = item.getCollectionID()
|
||||
if not collectiblesPerCollection.hasKey(collectionId):
|
||||
collectiblesPerCollection[collectionId] = @[]
|
||||
collectiblesPerCollection[collectionId].add(item)
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
import collectibles_item as flat_item
|
||||
import collectibles_nested_item as nested_item
|
||||
import ./collectibles_entry as flat_item
|
||||
import ./collectibles_nested_item as nested_item
|
||||
|
||||
proc collectibleToCollectibleNestedItem*(flatItem: flat_item.Item): nested_item.Item =
|
||||
proc collectibleToCollectibleNestedItem*(flatItem: flat_item.CollectiblesEntry): nested_item.Item =
|
||||
return nested_item.initItem(
|
||||
flatItem.getId(),
|
||||
flatItem.getChainId(),
|
||||
flatItem.getID(),
|
||||
flatItem.getChainID(),
|
||||
flatItem.getName(),
|
||||
flatItem.getImageUrl(),
|
||||
flatItem.getCollectionId(),
|
||||
flatItem.getImageURL(),
|
||||
flatItem.getCollectionID(),
|
||||
flatItem.getCollectionName(),
|
||||
false
|
||||
)
|
||||
|
||||
proc collectibleToCollectionNestedItem*(flatItem: flat_item.Item): nested_item.Item =
|
||||
proc collectibleToCollectionNestedItem*(flatItem: flat_item.CollectiblesEntry): nested_item.Item =
|
||||
return nested_item.initItem(
|
||||
flatItem.getCollectionId(),
|
||||
flatItem.getChainId(),
|
||||
flatItem.getCollectionID(),
|
||||
flatItem.getChainID(),
|
||||
flatItem.getCollectionName(),
|
||||
flatItem.getCollectionImageUrl(),
|
||||
flatItem.getCollectionId(),
|
||||
flatItem.getCollectionImageURL(),
|
||||
flatItem.getCollectionID(),
|
||||
flatItem.getCollectionName(),
|
||||
true
|
||||
)
|
||||
|
|
|
@ -1,67 +1,9 @@
|
|||
import options
|
||||
import backend/collectibles as backend
|
||||
import collectibles_item
|
||||
import ../../../app_service/service/community_tokens/dto/community_token
|
||||
import app_service/service/network/dto as network_dto
|
||||
import ./collectibles_entry
|
||||
|
||||
proc collectibleToItem*(c: backend.Collectible, isPinned: bool = false) : Item =
|
||||
var collectibleName = ""
|
||||
var collectibleDescription = ""
|
||||
var collectibleMediaUrl = ""
|
||||
var collectibleMediaType = ""
|
||||
var collectibleImageUrl = ""
|
||||
var collectibleBackgroundColor = ""
|
||||
if isSome(c.collectibleData):
|
||||
let collectibleData = c.collectibleData.get()
|
||||
collectibleName = collectibleData.name
|
||||
if isSome(collectibleData.description):
|
||||
collectibleDescription = collectibleData.description.get()
|
||||
if isSome(collectibleData.animationUrl):
|
||||
collectibleMediaUrl = collectibleData.animationUrl.get()
|
||||
if isSome(collectibleData.animationMediaType):
|
||||
collectibleMediaType = collectibleData.animationMediaType.get()
|
||||
if isSome(collectibleData.imageUrl):
|
||||
collectibleImageUrl = collectibleData.imageUrl.get()
|
||||
if isSome(collectibleData.backgroundColor):
|
||||
collectibleBackgroundColor = collectibleData.backgroundColor.get()
|
||||
if collectibleMediaUrl == "":
|
||||
collectibleMediaUrl = collectibleImageUrl
|
||||
collectibleMediaType = "image"
|
||||
|
||||
var collectionName = ""
|
||||
var collectionSlug = ""
|
||||
var collectionImageUrl = ""
|
||||
if isSome(c.collectionData):
|
||||
let collectionData = c.collectionData.get()
|
||||
collectionName = collectionData.name
|
||||
collectionSlug = collectionData.slug
|
||||
collectionImageUrl = collectionData.imageUrl
|
||||
|
||||
var communityId = ""
|
||||
var communityName = ""
|
||||
var communityColor = ""
|
||||
var communityPrivilegesLevel = PrivilegesLevel.Community.int
|
||||
if isSome(c.communityData):
|
||||
let communityData = c.communityData.get()
|
||||
communityId = communityData.id
|
||||
communityName = communityData.name
|
||||
communityColor = communityData.color
|
||||
communityPrivilegesLevel = int(communityData.privilegesLevel)
|
||||
|
||||
return initItem(
|
||||
c.id.contractID.chainID,
|
||||
c.id.contractID.address,
|
||||
c.id.tokenID,
|
||||
collectibleName,
|
||||
collectibleMediaUrl,
|
||||
collectibleMediaType,
|
||||
collectibleImageUrl,
|
||||
collectibleBackgroundColor,
|
||||
collectionName,
|
||||
collectionSlug,
|
||||
collectionImageUrl,
|
||||
isPinned,
|
||||
communityId,
|
||||
communityName,
|
||||
communityColor,
|
||||
communityPrivilegesLevel
|
||||
)
|
||||
proc getExtraData*(network: network_dto.NetworkDto): ExtraData =
|
||||
return ExtraData(
|
||||
networkShortName: network.shortName,
|
||||
networkColor: network.chainColor,
|
||||
networkIconUrl: network.iconURL
|
||||
)
|
|
@ -1,7 +1,8 @@
|
|||
import NimQml, logging, std/json, sequtils, strutils
|
||||
import stint
|
||||
|
||||
import app/modules/shared_models/collectible_details_entry
|
||||
import app/modules/shared_models/collectibles_entry
|
||||
import app/modules/shared_models/collectibles_utils
|
||||
import events_handler
|
||||
|
||||
import app/core/eventemitter
|
||||
|
@ -15,7 +16,7 @@ QtObject:
|
|||
networkService: network_service.Service
|
||||
|
||||
isDetailedEntryLoading: bool
|
||||
detailedEntry: CollectibleDetailsEntry
|
||||
detailedEntry: CollectiblesEntry
|
||||
|
||||
eventsHandler: EventsHandler
|
||||
|
||||
|
@ -54,12 +55,7 @@ QtObject:
|
|||
|
||||
proc getExtraData(self: Controller, chainID: int): ExtraData =
|
||||
let network = self.networkService.getNetwork(chainID)
|
||||
|
||||
return ExtraData(
|
||||
networkShortName: network.shortName,
|
||||
networkColor: network.chainColor,
|
||||
networkIconUrl: network.iconURL
|
||||
)
|
||||
return getExtraData(network)
|
||||
|
||||
proc processGetCollectiblesDetailsResponse(self: Controller, response: JsonNode) =
|
||||
defer: self.setIsDetailedEntryLoading(false)
|
||||
|
@ -106,7 +102,8 @@ QtObject:
|
|||
self.processGetCollectiblesDetailsResponse(jsonObj)
|
||||
)
|
||||
|
||||
proc newController*(requestId: int32,
|
||||
proc newController*(
|
||||
requestId: int32,
|
||||
networkService: network_service.Service,
|
||||
events: EventEmitter,
|
||||
dataType: backend_collectibles.CollectibleDataType = backend_collectibles.CollectibleDataType.Details
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import NimQml, std/json, sequtils, sugar, strutils
|
||||
import stint, logging, Tables
|
||||
|
||||
import app/modules/shared_models/collectibles_entry
|
||||
import app/modules/shared_models/collectibles_model
|
||||
import app/modules/shared_models/collectibles_utils
|
||||
import events_handler
|
||||
|
@ -9,12 +10,15 @@ import app/core/eventemitter
|
|||
|
||||
import backend/collectibles as backend_collectibles
|
||||
import backend/activity as backend_activity
|
||||
import app_service/service/network/service as network_service
|
||||
|
||||
const FETCH_BATCH_COUNT_DEFAULT = 50
|
||||
|
||||
QtObject:
|
||||
type
|
||||
Controller* = ref object of QObject
|
||||
networkService: network_service.Service
|
||||
|
||||
model: Model
|
||||
fetchFromStart: bool
|
||||
|
||||
|
@ -122,6 +126,10 @@ QtObject:
|
|||
self.fetchFromStart = true
|
||||
error "error fetching collectibles entries: ", response.error
|
||||
|
||||
proc getExtraData(self: Controller, chainID: int): ExtraData =
|
||||
let network = self.networkService.getNetwork(chainID)
|
||||
return getExtraData(network)
|
||||
|
||||
proc processGetOwnedCollectiblesResponse(self: Controller, response: JsonNode) =
|
||||
defer: self.model.setIsFetching(false)
|
||||
|
||||
|
@ -135,7 +143,10 @@ QtObject:
|
|||
return
|
||||
|
||||
try:
|
||||
let items = res.collectibles.map(header => collectibleToItem(header))
|
||||
let items = res.collectibles.map(header => (block:
|
||||
let extradata = self.getExtraData(header.id.contractID.chainID)
|
||||
newCollectibleDetailsFullEntry(header, extradata)
|
||||
))
|
||||
self.model.setItems(items, res.offset, res.hasMore)
|
||||
except Exception as e:
|
||||
error "Error converting activity entries: ", e.msg
|
||||
|
@ -175,6 +186,7 @@ QtObject:
|
|||
)
|
||||
proc newController*(
|
||||
requestId: int32,
|
||||
networkService: network_service.Service,
|
||||
events: EventEmitter,
|
||||
autofetch: bool = true,
|
||||
dataType: backend_collectibles.CollectibleDataType = backend_collectibles.CollectibleDataType.Header,
|
||||
|
@ -188,6 +200,8 @@ QtObject:
|
|||
result.dataType = dataType
|
||||
result.fetchCriteria = fetchCriteria
|
||||
|
||||
result.networkService = networkService
|
||||
|
||||
result.model = newModel()
|
||||
result.fetchFromStart = true
|
||||
|
||||
|
|
Loading…
Reference in New Issue