diff --git a/src/app/wallet/view.nim b/src/app/wallet/view.nim index e27fdab133..81f84ff0d6 100644 --- a/src/app/wallet/view.nim +++ b/src/app/wallet/view.nim @@ -43,6 +43,20 @@ QtObject: proc setCurrentAssetList*(self: WalletView, assetList: seq[Asset]) + proc currentCollectiblesListChanged*(self: WalletView) {.signal.} + + proc getCurrentCollectiblesList(self: WalletView): QVariant {.slot.} = + return newQVariant(self.currentCollectiblesList) + + proc setCurrentCollectiblesList*(self: WalletView, collectibles: seq[Collectible]) = + self.currentCollectiblesList.setNewData(collectibles) + self.currentCollectiblesListChanged() + + QtProperty[QVariant] collectibles: + read = getCurrentCollectiblesList + write = setCurrentCollectiblesList + notify = currentCollectiblesListChanged + proc setCurrentAccountByIndex*(self: WalletView, index: int) {.slot.} = if(self.accounts.rowCount() == 0): return @@ -51,6 +65,7 @@ QtObject: self.currentAccount.setAccountItem(selectedAccount) self.currentAccountChanged() self.setCurrentAssetList(selectedAccount.assetList) + self.setCurrentCollectiblesList(selectedAccount.collectibles) proc getCurrentAccount*(self: WalletView): QVariant {.slot.} = result = newQVariant(self.currentAccount) @@ -87,20 +102,6 @@ QtObject: read = getCurrentTransactions write = setCurrentTransactions notify = currentTransactionsChanged - - proc currentCollectiblesListChanged*(self: WalletView) {.signal.} - - proc getCurrentCollectiblesList(self: WalletView): QVariant {.slot.} = - return newQVariant(self.currentCollectiblesList) - - proc setCurrentCollectiblesList*(self: WalletView, collectibles: seq[Collectible]) = - self.currentCollectiblesList.setNewData(collectibles) - self.currentCollectiblesListChanged() - - QtProperty[QVariant] collectibles: - read = getCurrentCollectiblesList - write = setCurrentCollectiblesList - notify = currentCollectiblesListChanged proc totalFiatBalanceChanged*(self: WalletView) {.signal.} diff --git a/src/status/wallet.nim b/src/status/wallet.nim index 5e0c085d8f..98c5e60ef8 100644 --- a/src/status/wallet.nim +++ b/src/status/wallet.nim @@ -80,6 +80,7 @@ proc newAccount*(self: WalletModel, name: string, address: string, iconColor: st var assets: seq[Asset] = self.generateAccountConfiguredAssets(address) var account = WalletAccount(name: name, address: address, iconColor: iconColor, balance: fmt"{balance} {self.defaultCurrency}", assetList: assets, realFiatBalance: 0.0, publicKey: publicKey) updateBalance(account, self.getDefaultCurrency()) + account.collectibles = getAllCollectibles(parseAddress(account.address)) account proc initAccounts*(self: WalletModel) = diff --git a/src/status/wallet/collectibles.nim b/src/status/wallet/collectibles.nim index 57ff157c57..4e89bf921a 100644 --- a/src/status/wallet/collectibles.nim +++ b/src/status/wallet/collectibles.nim @@ -57,7 +57,11 @@ proc getCryptoKitties*(address: EthAddress): seq[Collectible] = let response = client.request(url) let kitties = parseJson(response.body)["kitties"] for kitty in kitties: - result.add(Collectible(id: kitty["id"].str, name: kitty["name"].str, image: kitty["image_url"].str)) + var id = kitty["id"] + var finalId = "" + if (not (id.kind == JNull)): + finalId = $id + result.add(Collectible(id: finalId, name: kitty["name"].str, image: kitty["image_url"].str)) except Exception as e: error "Error getting Cryptokitties", msg = e.msg @@ -77,9 +81,11 @@ proc getEthermons*(address: EthAddress): seq[Collectible] = let response = client.request(url) let monsters = parseJson(response.body)["data"] + var i = 0 for monsterKey in json.keys(monsters): let monster = monsters[monsterKey] - result.add(Collectible(id: monster["monster_id"].str, name: monster["class_name"].str, image: monster["image"].str)) + result.add(Collectible(id: $tokens[i], name: monster["class_name"].str, image: monster["image"].str)) + i = i + 1 except Exception as e: error "Error getting Ethermons", msg = e.msg