fix: fix watchonly collectibles

This commit is contained in:
Jonathan Rainville 2020-06-18 15:24:46 -04:00 committed by Iuri Matias
parent 98d4c7ef1e
commit c2ed0da1ca
3 changed files with 24 additions and 16 deletions

View File

@ -43,6 +43,20 @@ QtObject:
proc setCurrentAssetList*(self: WalletView, assetList: seq[Asset]) 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.} = proc setCurrentAccountByIndex*(self: WalletView, index: int) {.slot.} =
if(self.accounts.rowCount() == 0): return if(self.accounts.rowCount() == 0): return
@ -51,6 +65,7 @@ QtObject:
self.currentAccount.setAccountItem(selectedAccount) self.currentAccount.setAccountItem(selectedAccount)
self.currentAccountChanged() self.currentAccountChanged()
self.setCurrentAssetList(selectedAccount.assetList) self.setCurrentAssetList(selectedAccount.assetList)
self.setCurrentCollectiblesList(selectedAccount.collectibles)
proc getCurrentAccount*(self: WalletView): QVariant {.slot.} = proc getCurrentAccount*(self: WalletView): QVariant {.slot.} =
result = newQVariant(self.currentAccount) result = newQVariant(self.currentAccount)
@ -88,20 +103,6 @@ QtObject:
write = setCurrentTransactions write = setCurrentTransactions
notify = currentTransactionsChanged 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.} proc totalFiatBalanceChanged*(self: WalletView) {.signal.}
proc getTotalFiatBalance(self: WalletView): string {.slot.} = proc getTotalFiatBalance(self: WalletView): string {.slot.} =

View File

@ -80,6 +80,7 @@ proc newAccount*(self: WalletModel, name: string, address: string, iconColor: st
var assets: seq[Asset] = self.generateAccountConfiguredAssets(address) 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) 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()) updateBalance(account, self.getDefaultCurrency())
account.collectibles = getAllCollectibles(parseAddress(account.address))
account account
proc initAccounts*(self: WalletModel) = proc initAccounts*(self: WalletModel) =

View File

@ -57,7 +57,11 @@ 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:
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: except Exception as e:
error "Error getting Cryptokitties", msg = e.msg error "Error getting Cryptokitties", msg = e.msg
@ -77,9 +81,11 @@ proc getEthermons*(address: EthAddress): seq[Collectible] =
let response = client.request(url) let response = client.request(url)
let monsters = parseJson(response.body)["data"] let monsters = parseJson(response.body)["data"]
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: 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: except Exception as e:
error "Error getting Ethermons", msg = e.msg error "Error getting Ethermons", msg = e.msg