mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-20 11:29:20 +00:00
feat: make all collectibles work and fix Cryptokitties
This commit is contained in:
parent
ed88cf2a7e
commit
f083310193
@ -6,6 +6,7 @@ type
|
|||||||
Name = UserRole + 1,
|
Name = UserRole + 1,
|
||||||
Image = UserRole + 2
|
Image = UserRole + 2
|
||||||
CollectibleId = UserRole + 3
|
CollectibleId = UserRole + 3
|
||||||
|
CollectibleType = UserRole + 4
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type CollectiblesList* = ref object of QAbstractListModel
|
type CollectiblesList* = ref object of QAbstractListModel
|
||||||
@ -36,11 +37,13 @@ QtObject:
|
|||||||
of CollectiblesRoles.Name: result = newQVariant(collectible.name)
|
of CollectiblesRoles.Name: result = newQVariant(collectible.name)
|
||||||
of CollectiblesRoles.Image: result = newQVariant(collectible.image)
|
of CollectiblesRoles.Image: result = newQVariant(collectible.image)
|
||||||
of CollectiblesRoles.CollectibleId: result = newQVariant(collectible.id)
|
of CollectiblesRoles.CollectibleId: result = newQVariant(collectible.id)
|
||||||
|
of CollectiblesRoles.CollectibleType: result = newQVariant(collectible.collectibleType)
|
||||||
|
|
||||||
method roleNames(self: CollectiblesList): Table[int, string] =
|
method roleNames(self: CollectiblesList): Table[int, string] =
|
||||||
{ CollectiblesRoles.Name.int:"name",
|
{ CollectiblesRoles.Name.int:"name",
|
||||||
CollectiblesRoles.Image.int:"image",
|
CollectiblesRoles.Image.int:"image",
|
||||||
CollectiblesRoles.CollectibleId.int:"collectibleId" }.toTable
|
CollectiblesRoles.CollectibleId.int:"collectibleId",
|
||||||
|
CollectiblesRoles.CollectibleType.int:"collectibleType" }.toTable
|
||||||
|
|
||||||
proc addCollectibleToList*(self: CollectiblesList, colelctible: Collectible) =
|
proc addCollectibleToList*(self: CollectiblesList, colelctible: Collectible) =
|
||||||
self.beginInsertRows(newQModelIndex(), self.collectibles.len, self.collectibles.len)
|
self.beginInsertRows(newQModelIndex(), self.collectibles.len, self.collectibles.len)
|
||||||
|
@ -2,7 +2,7 @@ from eventemitter import Args
|
|||||||
import ../libstatus/types
|
import ../libstatus/types
|
||||||
|
|
||||||
type Collectible* = ref object
|
type Collectible* = ref object
|
||||||
name*, image*, id*: string
|
name*, image*, id*, collectibleType*: string
|
||||||
|
|
||||||
type CurrencyArgs* = ref object of Args
|
type CurrencyArgs* = ref object of Args
|
||||||
currency*: string
|
currency*: string
|
||||||
|
@ -7,6 +7,10 @@ import eth/common/eth_types
|
|||||||
import ../libstatus/types
|
import ../libstatus/types
|
||||||
import account
|
import account
|
||||||
|
|
||||||
|
const CRYPTOKITTY = "cryptokitty"
|
||||||
|
const KUDO = "kudo"
|
||||||
|
const ETHERMON = "ethermon"
|
||||||
|
|
||||||
proc getTokenUri(contract: Contract, tokenId: Stuint[256]): string =
|
proc getTokenUri(contract: Contract, tokenId: Stuint[256]): string =
|
||||||
try:
|
try:
|
||||||
let
|
let
|
||||||
@ -65,11 +69,18 @@ proc getCryptoKitties*(address: EthAddress): seq[Collectible] =
|
|||||||
let response = client.request(url)
|
let response = client.request(url)
|
||||||
let kitties = parseJson(response.body)["kitties"]
|
let kitties = parseJson(response.body)["kitties"]
|
||||||
for kitty in kitties:
|
for kitty in kitties:
|
||||||
|
try:
|
||||||
var id = kitty["id"]
|
var id = kitty["id"]
|
||||||
|
var name = kitty["name"]
|
||||||
var finalId = ""
|
var finalId = ""
|
||||||
|
var finalName = ""
|
||||||
if (not (id.kind == JNull)):
|
if (not (id.kind == JNull)):
|
||||||
finalId = $id
|
finalId = $id
|
||||||
result.add(Collectible(id: finalId, name: kitty["name"].str, image: kitty["image_url"].str))
|
if (not (name.kind == JNull)):
|
||||||
|
finalName = $name
|
||||||
|
result.add(Collectible(id: finalId, name: finalName, image: kitty["image_url_png"].str, collectibleType: CRYPTOKITTY))
|
||||||
|
except Exception as e2:
|
||||||
|
error "Error with this individual cat", msg = e2.msg, cat = kitty
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "Error getting Cryptokitties", msg = e.msg
|
error "Error getting Cryptokitties", msg = e.msg
|
||||||
|
|
||||||
@ -94,7 +105,7 @@ proc getEthermons*(address: EthAddress): seq[Collectible] =
|
|||||||
var i = 0
|
var i = 0
|
||||||
for monsterKey in json.keys(monsters):
|
for monsterKey in json.keys(monsters):
|
||||||
let monster = monsters[monsterKey]
|
let monster = monsters[monsterKey]
|
||||||
result.add(Collectible(id: $tokens[i], name: monster["class_name"].str, image: monster["image"].str))
|
result.add(Collectible(id: $tokens[i], name: monster["class_name"].str, image: monster["image"].str, collectibleType: ETHERMON))
|
||||||
i = i + 1
|
i = i + 1
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "Error getting Ethermons", msg = e.msg
|
error "Error getting Ethermons", msg = e.msg
|
||||||
@ -122,7 +133,7 @@ proc getKudos*(address: EthAddress): seq[Collectible] =
|
|||||||
let response = client.request(url)
|
let response = client.request(url)
|
||||||
let kudo = parseJson(response.body)
|
let kudo = parseJson(response.body)
|
||||||
|
|
||||||
result.add(Collectible(id: $token, name: kudo["name"].str, image: kudo["image"].str))
|
result.add(Collectible(id: $token, name: kudo["name"].str, image: kudo["image"].str, collectibleType: KUDO))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "Error getting Kudos", msg = e.msg
|
error "Error getting Kudos", msg = e.msg
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ Item {
|
|||||||
|
|
||||||
Loader {
|
Loader {
|
||||||
active: true
|
active: true
|
||||||
sourceComponent: true || root.isLoading || walletModel.collectibles.rowCount() > 0 ? collectiblesListComponent
|
sourceComponent: root.isLoading || walletModel.collectibles.rowCount() > 0 ? collectiblesListComponent
|
||||||
: noCollectiblesComponent
|
: noCollectiblesComponent
|
||||||
width: parent.width
|
width: parent.width
|
||||||
}
|
}
|
||||||
@ -42,6 +42,7 @@ Item {
|
|||||||
|
|
||||||
CollectiblesContainer {
|
CollectiblesContainer {
|
||||||
collectibleName: "CryptoKitties"
|
collectibleName: "CryptoKitties"
|
||||||
|
collectibleType: Constants.cryptokitty
|
||||||
collectibleIconSource: "../../img/collectibles/CryptoKitties.png"
|
collectibleIconSource: "../../img/collectibles/CryptoKitties.png"
|
||||||
isLoading: root.isLoading
|
isLoading: root.isLoading
|
||||||
collectiblesModal: collectiblesModalComponent
|
collectiblesModal: collectiblesModalComponent
|
||||||
@ -53,6 +54,7 @@ Item {
|
|||||||
|
|
||||||
CollectiblesContainer {
|
CollectiblesContainer {
|
||||||
collectibleName: "Ethermons"
|
collectibleName: "Ethermons"
|
||||||
|
collectibleType: Constants.ethermon
|
||||||
collectibleIconSource: "../../img/collectibles/ethermons.png"
|
collectibleIconSource: "../../img/collectibles/ethermons.png"
|
||||||
isLoading: root.isLoading
|
isLoading: root.isLoading
|
||||||
collectiblesModal: collectiblesModalComponent
|
collectiblesModal: collectiblesModalComponent
|
||||||
@ -64,6 +66,7 @@ Item {
|
|||||||
|
|
||||||
CollectiblesContainer {
|
CollectiblesContainer {
|
||||||
collectibleName: "Kudos"
|
collectibleName: "Kudos"
|
||||||
|
collectibleType: Constants.kudo
|
||||||
collectibleIconSource: "../../img/collectibles/kudos.png"
|
collectibleIconSource: "../../img/collectibles/kudos.png"
|
||||||
isLoading: root.isLoading
|
isLoading: root.isLoading
|
||||||
collectiblesModal: collectiblesModalComponent
|
collectiblesModal: collectiblesModalComponent
|
||||||
@ -81,68 +84,6 @@ Item {
|
|||||||
root.isLoading= isLoading
|
root.isLoading= isLoading
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Component {
|
|
||||||
id: collectiblesViewDelegate
|
|
||||||
|
|
||||||
Item {
|
|
||||||
id: element
|
|
||||||
anchors.right: parent.right
|
|
||||||
anchors.rightMargin: 0
|
|
||||||
anchors.left: parent.left
|
|
||||||
anchors.leftMargin: 0
|
|
||||||
height: 132
|
|
||||||
|
|
||||||
SVGImage {
|
|
||||||
id: collectibleImage
|
|
||||||
width: 128
|
|
||||||
height: 128
|
|
||||||
source: image
|
|
||||||
anchors.left: parent.left
|
|
||||||
anchors.leftMargin: 0
|
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
|
||||||
}
|
|
||||||
|
|
||||||
StyledText {
|
|
||||||
id: collectibleName
|
|
||||||
text: name
|
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
|
||||||
anchors.left: collectibleImage.right
|
|
||||||
anchors.leftMargin: Style.current.padding
|
|
||||||
font.pixelSize: 15
|
|
||||||
}
|
|
||||||
|
|
||||||
StyledText {
|
|
||||||
id: collectibleIdText
|
|
||||||
text: collectibleId
|
|
||||||
anchors.leftMargin: Style.current.padding
|
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
|
||||||
anchors.left: collectibleName.right
|
|
||||||
color: Style.current.darkGrey
|
|
||||||
font.pixelSize: 15
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ListModel {
|
|
||||||
id: exampleModel
|
|
||||||
|
|
||||||
ListElement {
|
|
||||||
name: "Kitty cat"
|
|
||||||
image: "../../img/token-icons/eth.svg"
|
|
||||||
collectibleId: "1337"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListView {
|
|
||||||
// id: assetListView
|
|
||||||
// spacing: Style.current.smallPadding
|
|
||||||
// anchors.topMargin: Style.current.bigPadding
|
|
||||||
// anchors.fill: parent
|
|
||||||
//// model: exampleModel
|
|
||||||
// model: walletModel.collectibles
|
|
||||||
// delegate: collectiblesViewDelegate
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*##^##
|
/*##^##
|
||||||
|
@ -6,6 +6,7 @@ import "../../../../../shared"
|
|||||||
Item {
|
Item {
|
||||||
property url collectibleIconSource: "../../../../img/collectibles/CryptoKitties.png"
|
property url collectibleIconSource: "../../../../img/collectibles/CryptoKitties.png"
|
||||||
property string collectibleName: "CryptoKitties"
|
property string collectibleName: "CryptoKitties"
|
||||||
|
property string collectibleType: "cryptokitty"
|
||||||
property bool isLoading: true
|
property bool isLoading: true
|
||||||
property bool collectiblesOpened: false
|
property bool collectiblesOpened: false
|
||||||
property var collectiblesModal
|
property var collectiblesModal
|
||||||
@ -13,35 +14,30 @@ Item {
|
|||||||
property var getLink: function () {}
|
property var getLink: function () {}
|
||||||
|
|
||||||
id: root
|
id: root
|
||||||
|
visible: isLoading || collectiblesContent.collectiblesQty > 0
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: childrenRect.height
|
height: visible ? collectiblesHeader.height + collectiblesContent.height : 0
|
||||||
|
|
||||||
CollectiblesHeader {
|
CollectiblesHeader {
|
||||||
id: collectiblesHeader
|
id: collectiblesHeader
|
||||||
collectibleName: root.collectibleName
|
collectibleName: root.collectibleName
|
||||||
collectibleIconSource: root.collectibleIconSource
|
collectibleIconSource: root.collectibleIconSource
|
||||||
|
collectiblesQty: collectiblesContent.collectiblesQty
|
||||||
isLoading: root.isLoading
|
isLoading: root.isLoading
|
||||||
toggleCollectible: function () {
|
toggleCollectible: function () {
|
||||||
root.collectiblesOpened = !root.collectiblesOpened
|
root.collectiblesOpened = !root.collectiblesOpened
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Loader {
|
|
||||||
active: root.collectiblesOpened
|
|
||||||
sourceComponent: contentComponent
|
|
||||||
anchors.top: collectiblesHeader.bottom
|
|
||||||
anchors.topMargin: Style.current.halfPadding
|
|
||||||
width: parent.width
|
|
||||||
}
|
|
||||||
|
|
||||||
Component {
|
|
||||||
id: contentComponent
|
|
||||||
|
|
||||||
CollectiblesContent {
|
CollectiblesContent {
|
||||||
|
id: collectiblesContent
|
||||||
|
visible: root.collectiblesOpened
|
||||||
collectiblesModal: root.collectiblesModal
|
collectiblesModal: root.collectiblesModal
|
||||||
|
collectibleType: root.collectibleType
|
||||||
buttonText: root.buttonText
|
buttonText: root.buttonText
|
||||||
getLink: root.getLink
|
getLink: root.getLink
|
||||||
}
|
anchors.top: collectiblesHeader.bottom
|
||||||
|
anchors.topMargin: Style.current.halfPadding
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import QtQuick 2.13
|
import QtQuick 2.13
|
||||||
import QtQuick.Controls 2.13
|
import QtQuick.Controls 2.13
|
||||||
import QtGraphicalEffects 1.13
|
import QtGraphicalEffects 1.13
|
||||||
|
import QtQml.Models 2.13
|
||||||
import "../../../../../imports"
|
import "../../../../../imports"
|
||||||
import "../../../../../shared"
|
import "../../../../../shared"
|
||||||
|
|
||||||
@ -24,12 +25,14 @@ ScrollView {
|
|||||||
description: "Avast ye! I'm the dread pirate Furbeard, and I'll most likely sleep"
|
description: "Avast ye! I'm the dread pirate Furbeard, and I'll most likely sleep"
|
||||||
}]
|
}]
|
||||||
readonly property int imageSize: 164
|
readonly property int imageSize: 164
|
||||||
|
property string collectibleType: "cryptokitty"
|
||||||
property var collectiblesModal
|
property var collectiblesModal
|
||||||
property string buttonText: "View in Cryptokitties"
|
property string buttonText: "View in Cryptokitties"
|
||||||
property var getLink: function () {}
|
property var getLink: function () {}
|
||||||
|
property alias collectiblesQty: collectibleModel.count
|
||||||
|
|
||||||
id: root
|
id: root
|
||||||
height: contentRow.height
|
height: visible ? contentRow.height : 0
|
||||||
width: parent.width
|
width: parent.width
|
||||||
ScrollBar.vertical.policy: ScrollBar.AlwaysOff
|
ScrollBar.vertical.policy: ScrollBar.AlwaysOff
|
||||||
ScrollBar.horizontal.policy: ScrollBar.AsNeeded
|
ScrollBar.horizontal.policy: ScrollBar.AsNeeded
|
||||||
@ -41,9 +44,40 @@ ScrollView {
|
|||||||
spacing: Style.current.padding
|
spacing: Style.current.padding
|
||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
model: collectibles
|
model: collectibleModel
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle {
|
DelegateModel {
|
||||||
|
id: collectibleModel
|
||||||
|
model: walletModel.collectibles
|
||||||
|
items.includeByDefault: false
|
||||||
|
|
||||||
|
groups: [
|
||||||
|
DelegateModelGroup {
|
||||||
|
id: uncheckedItems
|
||||||
|
name: "unchecked"
|
||||||
|
includeByDefault: true
|
||||||
|
onChanged: {
|
||||||
|
while (uncheckedItems.count > 0) {
|
||||||
|
var currentItem = uncheckedItems.get(0)
|
||||||
|
if (currentItem.model.collectibleType === root.collectibleType) {
|
||||||
|
currentItem.groups = "items"
|
||||||
|
} else {
|
||||||
|
currentItem.groups = "bad"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
DelegateModelGroup {
|
||||||
|
id: badCollectibleGroup
|
||||||
|
name: "bad"
|
||||||
|
includeByDefault: true
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
delegate: Rectangle {
|
||||||
radius: 16
|
radius: 16
|
||||||
border.width: 1
|
border.width: 1
|
||||||
border.color: Style.current.border
|
border.color: Style.current.border
|
||||||
@ -55,7 +89,7 @@ ScrollView {
|
|||||||
id: collectibleImage
|
id: collectibleImage
|
||||||
width: root.imageSize
|
width: root.imageSize
|
||||||
height: root.imageSize
|
height: root.imageSize
|
||||||
source: modelData.image
|
source: image
|
||||||
fillMode: Image.PreserveAspectCrop
|
fillMode: Image.PreserveAspectCrop
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,12 +98,13 @@ ScrollView {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: {
|
||||||
collectiblesModal.openModal({
|
collectiblesModal.openModal({
|
||||||
name: modelData.name,
|
name: name,
|
||||||
id: modelData.collectibleId,
|
id: collectibleId,
|
||||||
description: modelData.description,
|
// TODO do we even have a description?
|
||||||
|
description: "",
|
||||||
buttonText: root.buttonText,
|
buttonText: root.buttonText,
|
||||||
link: root.getLink(modelData.collectibleId),
|
link: root.getLink(collectibleId),
|
||||||
image: modelData.image
|
image: image
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ Rectangle {
|
|||||||
property bool isLoading: true
|
property bool isLoading: true
|
||||||
property bool hovered: false
|
property bool hovered: false
|
||||||
property var toggleCollectible: function () {}
|
property var toggleCollectible: function () {}
|
||||||
|
property int collectiblesQty: 6
|
||||||
|
|
||||||
id: collectibleHeader
|
id: collectibleHeader
|
||||||
height: 64
|
height: 64
|
||||||
@ -59,8 +60,7 @@ Rectangle {
|
|||||||
StyledText {
|
StyledText {
|
||||||
id: numberCollectibleText
|
id: numberCollectibleText
|
||||||
color: Style.current.secondaryText
|
color: Style.current.secondaryText
|
||||||
// TODO change with number of current collectible
|
text: collectibleHeader.collectiblesQty
|
||||||
text: "6"
|
|
||||||
font.pixelSize: 15
|
font.pixelSize: 15
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ ModalPopup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
id: popup
|
id: popup
|
||||||
title: collectibleName
|
title: collectibleName || qsTr("Unnamed")
|
||||||
|
|
||||||
CollectiblesModalContent {
|
CollectiblesModalContent {
|
||||||
collectibleName: popup.collectibleName
|
collectibleName: popup.collectibleName
|
||||||
|
@ -23,6 +23,10 @@ QtObject {
|
|||||||
readonly property string seedWalletType: "seed"
|
readonly property string seedWalletType: "seed"
|
||||||
readonly property string generatedWalletType: "generated"
|
readonly property string generatedWalletType: "generated"
|
||||||
|
|
||||||
|
readonly property string cryptokitty: "cryptokitty"
|
||||||
|
readonly property string kudo: "kudo"
|
||||||
|
readonly property string ethermon: "ethermon"
|
||||||
|
|
||||||
readonly property var accountColors: [
|
readonly property var accountColors: [
|
||||||
"#9B832F",
|
"#9B832F",
|
||||||
"#D37EF4",
|
"#D37EF4",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user