feat: add id to the collectible
This commit is contained in:
parent
3e152e5d35
commit
98d4c7ef1e
|
@ -6,6 +6,7 @@ type
|
|||
CollectiblesRoles {.pure.} = enum
|
||||
Name = UserRole + 1,
|
||||
Image = UserRole + 2
|
||||
CollectibleId = UserRole + 3
|
||||
|
||||
QtObject:
|
||||
type CollectiblesList* = ref object of QAbstractListModel
|
||||
|
@ -35,10 +36,12 @@ QtObject:
|
|||
case collectibleRole:
|
||||
of CollectiblesRoles.Name: result = newQVariant(collectible.name)
|
||||
of CollectiblesRoles.Image: result = newQVariant(collectible.image)
|
||||
of CollectiblesRoles.CollectibleId: result = newQVariant(collectible.id)
|
||||
|
||||
method roleNames(self: CollectiblesList): Table[int, string] =
|
||||
{ CollectiblesRoles.Name.int:"name",
|
||||
CollectiblesRoles.Image.int:"image" }.toTable
|
||||
CollectiblesRoles.Image.int:"image",
|
||||
CollectiblesRoles.CollectibleId.int:"collectibleId" }.toTable
|
||||
|
||||
proc addCollectibleToList*(self: CollectiblesList, colelctible: Collectible) =
|
||||
self.beginInsertRows(newQModelIndex(), self.collectibles.len, self.collectibles.len)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import eventemitter
|
||||
|
||||
type Collectible* = ref object
|
||||
name*, image*: string
|
||||
name*, image*, id*: string
|
||||
|
||||
type CurrencyArgs* = ref object of Args
|
||||
currency*: string
|
||||
|
|
|
@ -57,7 +57,7 @@ proc getCryptoKitties*(address: EthAddress): seq[Collectible] =
|
|||
let response = client.request(url)
|
||||
let kitties = parseJson(response.body)["kitties"]
|
||||
for kitty in kitties:
|
||||
result.add(Collectible(name: kitty["name"].str, image: kitty["image_url"].str))
|
||||
result.add(Collectible(id: kitty["id"].str, name: kitty["name"].str, image: kitty["image_url"].str))
|
||||
except Exception as e:
|
||||
error "Error getting Cryptokitties", msg = e.msg
|
||||
|
||||
|
@ -79,7 +79,7 @@ proc getEthermons*(address: EthAddress): seq[Collectible] =
|
|||
let monsters = parseJson(response.body)["data"]
|
||||
for monsterKey in json.keys(monsters):
|
||||
let monster = monsters[monsterKey]
|
||||
result.add(Collectible(name: monster["class_name"].str, image: monster["image"].str))
|
||||
result.add(Collectible(id: monster["monster_id"].str, name: monster["class_name"].str, image: monster["image"].str))
|
||||
except Exception as e:
|
||||
error "Error getting Ethermons", msg = e.msg
|
||||
|
||||
|
@ -104,7 +104,7 @@ proc getKudos*(address: EthAddress): seq[Collectible] =
|
|||
let response = client.request(url)
|
||||
let kudo = parseJson(response.body)
|
||||
|
||||
result.add(Collectible(name: kudo["name"].str, image: kudo["image"].str))
|
||||
result.add(Collectible(id: $token, name: kudo["name"].str, image: kudo["image"].str))
|
||||
except Exception as e:
|
||||
error "Error getting Kudos", msg = e.msg
|
||||
|
||||
|
|
|
@ -34,6 +34,15 @@ Item {
|
|||
anchors.leftMargin: Theme.padding
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: collectibleImage.right
|
||||
font.pixelSize: 15
|
||||
}
|
||||
|
||||
Text {
|
||||
id: collectibleIdText
|
||||
text: collectibleId
|
||||
anchors.leftMargin: Theme.padding
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: collectibleName.right
|
||||
color: Theme.darkGrey
|
||||
font.pixelSize: 15
|
||||
}
|
||||
|
@ -46,6 +55,7 @@ Item {
|
|||
ListElement {
|
||||
name: "Kitty cat"
|
||||
image: "../../img/token-icons/eth.svg"
|
||||
collectibleId: "1337"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue