chore: adapt to new collectibles api

This commit is contained in:
Dario Gabriel Lipicar 2023-07-31 16:41:53 -03:00 committed by dlipicar
parent 570f312617
commit 06f8ef2186
7 changed files with 152 additions and 71 deletions

View File

@ -57,10 +57,10 @@ QtObject:
networkIconUrl: network.iconURL
)
proc processGetCollectiblesDataResponse(self: Controller, response: JsonNode) =
proc processGetCollectiblesDetailsResponse(self: Controller, response: JsonNode) =
defer: self.setIsDetailedEntryLoading(false)
let res = fromJson(response, backend_collectibles.GetCollectiblesDataResponse)
let res = fromJson(response, backend_collectibles.GetCollectiblesDetailsResponse)
if res.errorCode != ErrorCodeSuccess:
error "error fetching collectible details: ", res.errorCode
@ -71,7 +71,7 @@ QtObject:
return
let collectible = res.collectibles[0]
let extradata = self.getExtraData(collectible.id.chainID)
let extradata = self.getExtraData(collectible.id.contractID.chainID)
self.detailedEntry = newCollectibleDetailsFullEntry(collectible, extradata)
self.detailedEntryChanged()
@ -80,8 +80,10 @@ QtObject:
self.setIsDetailedEntryLoading(true)
let id = backend_collectibles.CollectibleUniqueID(
chainID: chainId,
contractAddress: contractAddress,
contractID: backend_collectibles.ContractID(
chainID: chainId,
address: contractAddress
),
tokenID: stint.u256(tokenId)
)
let extradata = self.getExtraData(chainId)
@ -89,15 +91,15 @@ QtObject:
self.detailedEntry = newCollectibleDetailsBasicEntry(id, extradata)
self.detailedEntryChanged()
let response = backend_collectibles.getCollectiblesDataAsync(@[id])
let response = backend_collectibles.getCollectiblesDetailsAsync(@[id])
if response.error != nil:
self.setIsDetailedEntryLoading(false)
error "error fetching collectible details: ", response.error
return
proc setupEventHandlers(self: Controller) =
self.eventsHandler.onGetCollectiblesDataDone(proc (jsonObj: JsonNode) =
self.processGetCollectiblesDataResponse(jsonObj)
self.eventsHandler.onGetCollectiblesDetailsDone(proc (jsonObj: JsonNode) =
self.processGetCollectiblesDetailsResponse(jsonObj)
)
proc newController*(networkService: network_service.Service,

View File

@ -21,8 +21,8 @@ QtObject:
proc delete*(self: EventsHandler) =
self.QObject.delete
proc onGetCollectiblesDataDone*(self: EventsHandler, handler: EventCallbackProc) =
self.eventHandlers[backend_collectibles.eventGetCollectiblesDataDone] = handler
proc onGetCollectiblesDetailsDone*(self: EventsHandler, handler: EventCallbackProc) =
self.eventHandlers[backend_collectibles.eventGetCollectiblesDetailsDone] = handler
proc handleApiEvents(self: EventsHandler, e: Args) =
var data = WalletSignal(e)

View File

@ -17,7 +17,7 @@ QtObject:
type
CollectibleDetailsEntry* = ref object of QObject
id: backend.CollectibleUniqueID
data: backend.CollectibleData
data: backend.CollectibleDetails
extradata: ExtraData
traits: TraitModel
@ -27,7 +27,7 @@ QtObject:
proc delete*(self: CollectibleDetailsEntry) =
self.QObject.delete
proc newCollectibleDetailsFullEntry*(data: backend.CollectibleData, extradata: ExtraData): CollectibleDetailsEntry =
proc newCollectibleDetailsFullEntry*(data: backend.CollectibleDetails, extradata: ExtraData): CollectibleDetailsEntry =
new(result, delete)
result.id = data.id
result.data = data
@ -45,6 +45,10 @@ QtObject:
proc newCollectibleDetailsEmptyEntry*(): CollectibleDetailsEntry =
let id = backend.CollectibleUniqueID(
contractID: backend.ContractID(
chainID: 0,
address: ""
),
tokenID: stint.u256(0)
)
let extradata = ExtraData()
@ -59,13 +63,13 @@ QtObject:
)"""
proc getChainID*(self: CollectibleDetailsEntry): int {.slot.} =
return self.id.chainID
return self.id.contractID.chainID
QtProperty[int] chainId:
read = getChainID
proc getContractAddress*(self: CollectibleDetailsEntry): string {.slot.} =
return self.id.contractAddress
return self.id.contractID.address
QtProperty[string] contractAddress:
read = getContractAddress
@ -119,7 +123,7 @@ QtObject:
proc getCollectionName*(self: CollectibleDetailsEntry): string {.slot.} =
if self.data == nil:
return ""
return self.data.collectionData.name
return self.data.collectionName
QtProperty[string] collectionName:
read = getCollectionName
@ -135,7 +139,7 @@ QtObject:
proc getCollectionImageURL*(self: CollectibleDetailsEntry): string {.slot.} =
if self.data == nil:
return ""
return self.data.collectionData.imageUrl
return self.data.collectionImageUrl
QtProperty[string] collectionImageUrl:
read = getCollectionImageURL

View File

@ -10,8 +10,8 @@ proc collectibleToItem*(c: backend.CollectibleHeader, isPinned: bool = false) :
mediaType = "image"
return initItem(
c.id.chainID,
c.id.contractAddress,
c.id.contractID.chainID,
c.id.contractID.address,
c.id.tokenID,
c.name,
mediaUrl,

View File

@ -14,7 +14,7 @@ const eventCollectiblesOwnershipUpdateFinished*: string = "wallet-collectibles-o
const eventCollectiblesOwnershipUpdateFinishedWithError*: string = "wallet-collectibles-ownership-update-finished-with-error"
const eventOwnedCollectiblesFilteringDone*: string = "wallet-owned-collectibles-filtering-done"
const eventGetCollectiblesDataDone*: string = "wallet-get-collectibles-data-done"
const eventGetCollectiblesDetailsDone*: string = "wallet-get-collectibles-details-done"
type
# Mirrors services/wallet/collectibles/service.go ErrorCode
@ -30,9 +30,9 @@ type
hasMore*: bool
errorCode*: ErrorCode
# Mirrors services/wallet/collectibles/service.go GetCollectiblesDataResponse
GetCollectiblesDataResponse* = object
collectibles*: seq[CollectibleData]
# Mirrors services/wallet/collectibles/service.go GetCollectiblesDetailsResponse
GetCollectiblesDetailsResponse* = object
collectibles*: seq[CollectibleDetails]
errorCode*: ErrorCode
@ -53,12 +53,12 @@ proc fromJson*(e: JsonNode, T: typedesc[FilterOwnedCollectiblesResponse]): Filte
errorCode: ErrorCode(e["errorCode"].getInt())
)
proc fromJson*(e: JsonNode, T: typedesc[GetCollectiblesDataResponse]): GetCollectiblesDataResponse {.inline.} =
var collectibles: seq[CollectibleData] = @[]
proc fromJson*(e: JsonNode, T: typedesc[GetCollectiblesDetailsResponse]): GetCollectiblesDetailsResponse {.inline.} =
var collectibles: seq[CollectibleDetails] = @[]
if e.hasKey("collectibles"):
let jsonCollectibles = e["collectibles"]
for item in jsonCollectibles.getElems():
collectibles.add(fromJson(item, CollectibleData))
collectibles.add(fromJson(item, CollectibleDetails))
result = T(
collectibles: collectibles,
@ -91,5 +91,5 @@ rpc(filterOwnedCollectiblesAsync, "wallet"):
offset: int
limit: int
rpc(getCollectiblesDataAsync, "wallet"):
rpc(getCollectiblesDetailsAsync, "wallet"):
uniqueIds: seq[CollectibleUniqueID]

View File

@ -2,22 +2,16 @@ import json, strformat
import stint, Tables
type
# Mirrors services/wallet/thirdparty/collectible_types.go ContractID
ContractID* = ref object of RootObj
chainID*: int
address*: string
# Mirrors services/wallet/thirdparty/collectible_types.go CollectibleUniqueID
CollectibleUniqueID* = ref object of RootObj
chainID*: int
contractAddress*: string
contractID*: ContractID
tokenID*: UInt256
# Mirrors services/wallet/thirdparty/collectible_types.go CollectibleHeader
CollectibleHeader* = ref object of RootObj
id* : CollectibleUniqueID
name*: string
imageUrl*: string
animationUrl*: string
animationMediaType*: string
backgroundColor*: string
collectionName*: string
# Mirrors services/wallet/thirdparty/collectible_types.go CollectibleTrait
CollectibleTrait* = ref object of RootObj
trait_type*: string
@ -51,6 +45,31 @@ type
tokenUri*: string
collectionData*: CollectionData
# Mirrors services/wallet/collectibles/types.go CollectibleHeader
CollectibleHeader* = ref object of RootObj
id* : CollectibleUniqueID
name*: string
imageUrl*: string
animationUrl*: string
animationMediaType*: string
backgroundColor*: string
collectionName*: string
# Mirrors services/wallet/collectibles/types.go CollectibleDetails
CollectibleDetails* = ref object of RootObj
id* : CollectibleUniqueID
name*: string
description*: string
imageUrl*: string
animationUrl*: string
animationMediaType*: string
traits*: seq[CollectibleTrait]
backgroundColor*: string
tokenUri*: string
collectionName*: string
collectionSlug*: string
collectionImageUrl*: string
# Mirrors services/wallet/thirdparty/collectible_types.go TokenBalance
CollectibleBalance* = ref object
tokenId*: UInt256
@ -66,23 +85,48 @@ type
contractAddress*: string
owners*: seq[CollectibleOwner]
# ContractID
proc `$`*(self: ContractID): string =
return fmt"""ContractID(
chainID:{self.chainID},
address:{self.address}
)"""
proc `==`*(a, b: ContractID): bool =
result = a.chainID == b.chainID and
a.address == b.address
proc `%`*(t: ContractID): JsonNode {.inline.} =
result = newJObject()
result["chainID"] = %(t.chainID)
result["address"] = %(t.address)
proc `%`*(t: ref ContractID): JsonNode {.inline.} =
return %(t[])
proc fromJson*(t: JsonNode, T: typedesc[ContractID]): ContractID {.inline.} =
result = ContractID()
result.chainID = t["chainID"].getInt()
result.address = t["address"].getStr()
proc fromJson*(t: JsonNode, T: typedesc[ref ContractID]): ref ContractID {.inline.} =
result = new(ContractID)
result[] = fromJson(t, ContractID)
# CollectibleUniqueID
proc `$`*(self: CollectibleUniqueID): string =
return fmt"""CollectibleUniqueID(
chainID:{self.chainID},
contractAddress:{self.contractAddress},
contractID:{self.contractID},
tokenID:{self.tokenID}
)"""
proc `==`*(a, b: CollectibleUniqueID): bool =
result = a.chainID == b.chainID and
a.contractAddress == b.contractAddress and
result = a.contractID == b.contractID and
a.tokenID == b.tokenID
proc `%`*(t: CollectibleUniqueID): JsonNode {.inline.} =
result = newJObject()
result["chainID"] = %(t.chainID)
result["contractAddress"] = %(t.contractAddress)
result["contractID"] = %(t.contractID)
result["tokenID"] = %(t.tokenID.toString())
proc `%`*(t: ref CollectibleUniqueID): JsonNode {.inline.} =
@ -90,36 +134,13 @@ proc `%`*(t: ref CollectibleUniqueID): JsonNode {.inline.} =
proc fromJson*(t: JsonNode, T: typedesc[CollectibleUniqueID]): CollectibleUniqueID {.inline.} =
result = CollectibleUniqueID()
result.chainID = t["chainID"].getInt()
result.contractAddress = t["contractAddress"].getStr()
result.contractID = fromJson(t["contractID"], ContractID)
result.tokenID = stint.parse(t["tokenID"].getStr(), UInt256)
proc fromJson*(t: JsonNode, T: typedesc[ref CollectibleUniqueID]): ref CollectibleUniqueID {.inline.} =
result = new(CollectibleUniqueID)
result[] = fromJson(t, CollectibleUniqueID)
# CollectibleHeader
proc `$`*(self: CollectibleHeader): string =
return fmt"""CollectibleHeader(
id:{self.id},
name:{self.name},
imageUrl:{self.imageUrl},
animationUrl:{self.animationUrl},
animationMediaType:{self.animationMediaType},
backgroundColor:{self.backgroundColor},
collectionName:{self.collectionName}
)"""
proc fromJson*(t: JsonNode, T: typedesc[CollectibleHeader]): CollectibleHeader {.inline.} =
result = CollectibleHeader()
result.id = fromJson(t["id"], CollectibleUniqueID)
result.name = t["name"].getStr()
result.imageUrl = t["image_url"].getStr()
result.animationUrl = t["animation_url"].getStr()
result.animationMediaType = t["animation_media_type"].getStr()
result.backgroundColor = t["background_color"].getStr()
result.collectionName = t["collection_name"].getStr()
# CollectibleTrait
proc `$`*(self: CollectibleTrait): string =
return fmt"""CollectibleTrait(
@ -195,7 +216,6 @@ proc `$`*(self: CollectibleData): string =
traits:{self.traits},
backgroundColor:{self.backgroundColor},
tokenUri:{self.tokenUri},
collectionData:{self.collectionData}
)"""
proc getCollectibleTraits*(t: JsonNode): seq[CollectibleTrait] =
@ -216,12 +236,67 @@ proc fromJson*(t: JsonNode, T: typedesc[CollectibleData]): CollectibleData {.inl
result.traits = getCollectibleTraits(t["traits"])
result.backgroundColor = t["background_color"].getStr()
result.tokenUri = t["token_uri"].getStr()
result.collectionData = fromJson(t["collection_data"], CollectionData)
proc fromJson*(t: JsonNode, T: typedesc[ref CollectibleData]): ref CollectibleData {.inline.} =
result = new(CollectibleData)
result[] = fromJson(t, CollectibleData)
# CollectibleHeader
proc `$`*(self: CollectibleHeader): string =
return fmt"""CollectibleHeader(
id:{self.id},
name:{self.name},
imageUrl:{self.imageUrl},
animationUrl:{self.animationUrl},
animationMediaType:{self.animationMediaType},
backgroundColor:{self.backgroundColor},
collectionName:{self.collectionName}
)"""
proc fromJson*(t: JsonNode, T: typedesc[CollectibleHeader]): CollectibleHeader {.inline.} =
result = CollectibleHeader()
result.id = fromJson(t["id"], CollectibleUniqueID)
result.name = t["name"].getStr()
result.imageUrl = t["image_url"].getStr()
result.animationUrl = t["animation_url"].getStr()
result.animationMediaType = t["animation_media_type"].getStr()
result.backgroundColor = t["background_color"].getStr()
result.collectionName = t["collection_name"].getStr()
# CollectibleDetails
proc `$`*(self: CollectibleDetails): string =
return fmt"""CollectibleDetails(
id:{self.id},
name:{self.name},
description:{self.description},
imageUrl:{self.imageUrl},
animationUrl:{self.animationUrl},
animationMediaType:{self.animationMediaType},
traits:{self.traits},
backgroundColor:{self.backgroundColor},
collectionName:{self.collectionName},
collectionSlug:{self.collectionSlug},
collectionImageUrl:{self.collectionImageUrl},
)"""
proc fromJson*(t: JsonNode, T: typedesc[CollectibleDetails]): CollectibleDetails {.inline.} =
result = CollectibleDetails()
result.id = fromJson(t["id"], CollectibleUniqueID)
result.name = t["name"].getStr()
result.description = t["description"].getStr()
result.imageUrl = t["image_url"].getStr()
result.animationUrl = t["animation_url"].getStr()
result.animationMediaType = t["animation_media_type"].getStr()
result.traits = getCollectibleTraits(t["traits"])
result.backgroundColor = t["background_color"].getStr()
result.collectionName = t["collection_name"].getStr()
result.collectionSlug = t["collection_slug"].getStr()
result.collectionImageUrl = t["collection_image_url"].getStr()
proc fromJson*(t: JsonNode, T: typedesc[ref CollectibleDetails]): ref CollectibleDetails {.inline.} =
result = new(CollectibleDetails)
result[] = fromJson(t, CollectibleDetails)
# CollectibleBalance
proc `$`*(self: CollectibleBalance): string =
return fmt"""CollectibleBalance(

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit 9267e581436db4e6c761f9600243bc4f14aec36e
Subproject commit 078f71a23582e4ffe5e52f75317db0b1ad756542