From 98d4c7ef1e9f47c1581afb73c01d9e0bc91daf44 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 18 Jun 2020 11:24:44 -0400 Subject: [PATCH] feat: add id to the collectible --- src/app/wallet/views/collectibles_list.nim | 5 ++++- src/status/wallet/account.nim | 2 +- src/status/wallet/collectibles.nim | 6 +++--- ui/app/AppLayouts/Wallet/CollectiblesTab.qml | 10 ++++++++++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/app/wallet/views/collectibles_list.nim b/src/app/wallet/views/collectibles_list.nim index 04c799c9e9..99a1d5f611 100644 --- a/src/app/wallet/views/collectibles_list.nim +++ b/src/app/wallet/views/collectibles_list.nim @@ -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) diff --git a/src/status/wallet/account.nim b/src/status/wallet/account.nim index 5a76ef0220..23635a821d 100644 --- a/src/status/wallet/account.nim +++ b/src/status/wallet/account.nim @@ -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 diff --git a/src/status/wallet/collectibles.nim b/src/status/wallet/collectibles.nim index 5cbac23fab..57ff157c57 100644 --- a/src/status/wallet/collectibles.nim +++ b/src/status/wallet/collectibles.nim @@ -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 diff --git a/ui/app/AppLayouts/Wallet/CollectiblesTab.qml b/ui/app/AppLayouts/Wallet/CollectiblesTab.qml index 9554092d93..3553b3197d 100644 --- a/ui/app/AppLayouts/Wallet/CollectiblesTab.qml +++ b/ui/app/AppLayouts/Wallet/CollectiblesTab.qml @@ -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" } }