From fef2e6651d1c8e51736ce3ce0f3272f60647a370 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 27 Aug 2020 10:41:50 -0400 Subject: [PATCH] feat: add stickers to collectibles --- src/app/wallet/view.nim | 13 +++++ src/status/wallet/collectibles.nim | 49 ++++++++++++++++-- ui/app/AppLayouts/Wallet/CollectiblesTab.qml | 2 +- .../CollectiblesContent.qml | 19 +++++-- .../collectiblesData.js | 9 ++++ ui/app/img/collectibles/SNT.png | Bin 0 -> 730 bytes 6 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 ui/app/img/collectibles/SNT.png diff --git a/src/app/wallet/view.nim b/src/app/wallet/view.nim index 3c51bc072f..957521ea02 100644 --- a/src/app/wallet/view.nim +++ b/src/app/wallet/view.nim @@ -301,6 +301,12 @@ QtObject: "collectibleType": status_collectibles.ETHERMON, "collectiblesOrError": status_collectibles.getEthermons(address) }) + spawnAndSend(self, "setCollectiblesResult") do: + $(%*{ + "address": address, + "collectibleType": status_collectibles.STICKER, + "collectiblesOrError": status_collectibles.getStickers(address) + }) proc setCollectiblesResult(self: WalletView, collectiblesJSON: string) {.slot.} = let collectibleData = parseJson(collectiblesJSON) @@ -355,6 +361,13 @@ QtObject: "collectibleType": status_collectibles.ETHERMON, "collectiblesOrError": status_collectibles.getEthermons(address) }) + of STICKER: + spawnAndSend(self, "setCollectiblesResult") do: + $(%*{ + "address": address, + "collectibleType": status_collectibles.STICKER, + "collectiblesOrError": status_collectibles.getStickers(address) + }) else: error "Unrecognized collectible" return diff --git a/src/status/wallet/collectibles.nim b/src/status/wallet/collectibles.nim index f9db3f7a87..02f8768577 100644 --- a/src/status/wallet/collectibles.nim +++ b/src/status/wallet/collectibles.nim @@ -1,7 +1,9 @@ -import strformat, httpclient, json, chronicles, sequtils, strutils, tables +import strformat, httpclient, json, chronicles, sequtils, strutils, tables, sugar from eth/common/utils import parseAddress import ../libstatus/core as status import ../libstatus/contracts as contracts +import ../libstatus/stickers as status_stickers +import ../chat as status_chat import ../libstatus/types import eth/common/eth_types import ../libstatus/types @@ -10,8 +12,9 @@ import account const CRYPTOKITTY* = "cryptokitty" const KUDO* = "kudo" const ETHERMON* = "ethermon" +const STICKER* = "stickers" -const COLLECTIBLE_TYPES* = [CRYPTOKITTY, KUDO, ETHERMON] +const COLLECTIBLE_TYPES* = [CRYPTOKITTY, KUDO, ETHERMON, STICKER] proc getTokenUri(contract: Contract, tokenId: Stuint[256]): string = try: @@ -169,7 +172,7 @@ proc getKudos*(address: EthAddress): string = description: kudo["description"].str, externalUrl: kudo["external_url"].str)) - return $(%*kudos) + return $(%*kudos) except Exception as e: error "Error getting Kudos", msg = e.msg result = e.msg @@ -177,3 +180,43 @@ proc getKudos*(address: EthAddress): string = proc getKudos*(address: string): string = let eth_address = parseAddress(address) result = getKudos(eth_address) + +proc getStickers*(address: EthAddress): string = + try: + var stickers: seq[Collectible] + stickers = @[] + let contract = getContract("sticker-pack") + if contract == nil: return + + let tokensIds = tokensOfOwnerByIndex(contract, address) + + if (tokensIds.len == 0): + return $(%*stickers) + + let purchasedStickerPacks = tokensIds.map(tokenId => status_stickers.getPackIdFromTokenId(tokenId.u256)) + + if (purchasedStickerPacks.len == 0): + return $(%*stickers) + # TODO find a way to keep those in memory so as not to reload it each time + let availableStickerPacks = status_chat.getAvailableStickerPacks() + + var index = 0 + for stickerId in purchasedStickerPacks: + let sticker = availableStickerPacks[stickerId] + stickers.add(Collectible(id: $tokensIds[index], + name: sticker.name, + image: fmt"https://ipfs.infura.io/ipfs/{status_stickers.decodeContentHash(sticker.preview)}", + collectibleType: STICKER, + description: sticker.author, + externalUrl: "") + ) + index = index + 1 + + return $(%*stickers) + except Exception as e: + error "Error getting Stickers", msg = e.msg + result = e.msg + +proc getStickers*(address: string): string = + let eth_address = parseAddress(address) + result = getStickers(eth_address) diff --git a/ui/app/AppLayouts/Wallet/CollectiblesTab.qml b/ui/app/AppLayouts/Wallet/CollectiblesTab.qml index 6e20306483..eeebf26e2e 100644 --- a/ui/app/AppLayouts/Wallet/CollectiblesTab.qml +++ b/ui/app/AppLayouts/Wallet/CollectiblesTab.qml @@ -55,7 +55,7 @@ Item { collectiblesModal: collectiblesModalComponent buttonText: collectibleData.buttonText getLink: collectibleData.getLink - onVisibleChanged: { + onActiveChanged: { checkCollectiblesVisibility() } } diff --git a/ui/app/AppLayouts/Wallet/components/collectiblesComponents/CollectiblesContent.qml b/ui/app/AppLayouts/Wallet/components/collectiblesComponents/CollectiblesContent.qml index d5902c0d56..97df3e76ea 100644 --- a/ui/app/AppLayouts/Wallet/components/collectiblesComponents/CollectiblesContent.qml +++ b/ui/app/AppLayouts/Wallet/components/collectiblesComponents/CollectiblesContent.qml @@ -75,20 +75,29 @@ ScrollView { Repeater { model: collectibles - Rectangle { - radius: 16 - border.width: 1 - border.color: Style.current.border - color: Style.current.background + Item { width: collectibleImage.width height: collectibleImage.height + clip: true Image { id: collectibleImage width: root.imageSize height: root.imageSize + z: 1 source: modelData.image fillMode: Image.PreserveAspectCrop + anchors.verticalCenter: parent.verticalCenter + anchors.horizontalCenter: parent.horizontalCenter + } + + Rectangle { + radius: 16 + z: 2 + border.width: 1 + border.color: Style.current.border + color: Style.current.transparent + anchors.fill: parent } MouseArea { diff --git a/ui/app/AppLayouts/Wallet/components/collectiblesComponents/collectiblesData.js b/ui/app/AppLayouts/Wallet/components/collectiblesComponents/collectiblesData.js index d9a2ca0fd9..3a6e52143b 100644 --- a/ui/app/AppLayouts/Wallet/components/collectiblesComponents/collectiblesData.js +++ b/ui/app/AppLayouts/Wallet/components/collectiblesComponents/collectiblesData.js @@ -2,6 +2,7 @@ var cryptokitty = "cryptokitty" var kudo = "kudo" var ethermon = "ethermon" +var stickers = "stickers" var collectiblesData = { [cryptokitty] :{ @@ -29,4 +30,12 @@ var collectiblesData = { return externalUrl } }, + [stickers] :{ + collectibleName: qsTr("Purchased Stickers"), + collectibleIconSource: "SNT.png", + buttonText: "", + getLink: function (id, externalUrl) { + return "" + } + }, } diff --git a/ui/app/img/collectibles/SNT.png b/ui/app/img/collectibles/SNT.png new file mode 100644 index 0000000000000000000000000000000000000000..460b4b256032080c88c2bb7b3d469943a50eda7e GIT binary patch literal 730 zcmV<00ww*4P);7e!VOlaUyY~fRF;Z|_sS8?K4a^hKX;#+j% zTy^7LcjI4p<6wB?VS40beB@?*4KH%hneb$o9c<1>x-T1jGpU}qU@5R?31JHl%(vLsO_7o?zF)2!prp3+xOPo z_}AU|*xvZs;P~C*`QGFC-{kq`>iX#G`|9oc>+bvU^ZfJm{r30$_W1qy`ThC&{rUR- z`}_X<{Qmy_{{R2~4!@=E0000KbW%=J009XM79&z}e}aRhs=w3O=<@UaEaxZn0004D zNklp+jT*5)+g@X;xTcqB^uluv1Kx+Ty+xGo<~UA!Z7@IBLvPHxW4{<|v)X z51)DUb9sO3*XN;r+%?ed{pC~tub^REB8s6s+u+u3v?3zPq1@f%-V-!(A`i;oKMP;b z@+g4vj-~f#1(ZPf!@|xLv=Yi7U1RAhIvEv^UU6^XC3*!JNVlKfyngfH%a5Nwzqtj; zPzCAiy{Atf-Mj$c$|XpZdiws)?Iw!N9ex3+kiop!W#KxcOr+=X1`Ge7BqHG-So#Dd z5GDN1!qO0mCz|3l_x2t`$%!aJY`myubME;^aA$ z!!@{Z=ls;+Ivmm2m2d$-Vv$0)kRqwrBV3S@Uo?Z_h>LJxPq_L30CgUo6stVregFUf M07*qoM6N<$f*9qErvLx| literal 0 HcmV?d00001