feat: save collectiblesList to WalletAccount

This commit is contained in:
Jonathan Rainville 2020-08-25 11:04:35 -04:00 committed by Iuri Matias
parent 68a903e3f0
commit 898bb27b56
2 changed files with 30 additions and 11 deletions

View File

@ -107,7 +107,7 @@ QtObject:
write = setCurrentTransactions write = setCurrentTransactions
notify = currentTransactionsChanged notify = currentTransactionsChanged
proc loadCollectiblesForAccount*(self: WalletView, address: string) proc loadCollectiblesForAccount*(self: WalletView, address: string, currentCollectiblesList: seq[CollectibleList])
proc loadTransactionsForAccount*(self: WalletView, address: string) proc loadTransactionsForAccount*(self: WalletView, address: string)
proc currentAccountChanged*(self: WalletView) {.signal.} proc currentAccountChanged*(self: WalletView) {.signal.}
@ -123,8 +123,8 @@ QtObject:
# Display currently known collectibles, and get latest from API/Contracts # Display currently known collectibles, and get latest from API/Contracts
self.setCurrentCollectiblesLists(selectedAccount.collectiblesLists) self.setCurrentCollectiblesLists(selectedAccount.collectiblesLists)
# TODO only load if the list is empty self.loadCollectiblesForAccount(selectedAccount.address, selectedAccount.collectiblesLists)
self.loadCollectiblesForAccount(selectedAccount.address)
# Display currently known transactions, and get latest transactions from status-go # Display currently known transactions, and get latest transactions from status-go
self.setCurrentTransactions(selectedAccount.transactions) self.setCurrentTransactions(selectedAccount.transactions)
self.loadTransactionsForAccount(selectedAccount.address) self.loadTransactionsForAccount(selectedAccount.address)
@ -268,7 +268,9 @@ QtObject:
proc addCustomToken*(self: WalletView, address: string, name: string, symbol: string, decimals: string) {.slot.} = proc addCustomToken*(self: WalletView, address: string, name: string, symbol: string, decimals: string) {.slot.} =
self.status.wallet.toggleAsset(symbol, true, address, name, parseInt(decimals), "") self.status.wallet.toggleAsset(symbol, true, address, name, parseInt(decimals), "")
proc loadCollectiblesForAccount*(self: WalletView, address: string) {.slot.} = proc loadCollectiblesForAccount*(self: WalletView, address: string, currentCollectiblesList: seq[CollectibleList]) =
if (currentCollectiblesList.len > 0):
return
# Add loading state if it is the current account # Add loading state if it is the current account
if address == self.currentAccount.address: if address == self.currentAccount.address:
for collectibleType in status_collectibles.COLLECTIBLE_TYPES: for collectibleType in status_collectibles.COLLECTIBLE_TYPES:
@ -303,6 +305,7 @@ QtObject:
proc setCollectiblesResult(self: WalletView, collectiblesJSON: string) {.slot.} = proc setCollectiblesResult(self: WalletView, collectiblesJSON: string) {.slot.} =
let collectibleData = parseJson(collectiblesJSON) let collectibleData = parseJson(collectiblesJSON)
let address = collectibleData["address"].getStr let address = collectibleData["address"].getStr
let collectibleType = collectibleData["collectibleType"].getStr
var collectibles: JSONNode var collectibles: JSONNode
try: try:
@ -310,19 +313,20 @@ QtObject:
except Exception as e: except Exception as e:
# We failed parsing, this means the result is an error string # We failed parsing, this means the result is an error string
self.currentCollectiblesLists.setErrorByType( self.currentCollectiblesLists.setErrorByType(
collectibleData["collectibleType"].getStr, collectibleType,
$collectibleData["collectiblesOrError"] $collectibleData["collectiblesOrError"]
) )
return return
# TODO Add the collectibleData to the Wallet account # Add the collectibles to the WalletAccount
# let index = self.accounts.getAccountindexByAddress(address) let index = self.accounts.getAccountindexByAddress(address)
# if index == -1: return if index == -1: return
# self.accounts.getAccount(index).collectiblesLists = collectiblesList self.accounts.addCollectibleListToAccount(index, collectibleType, $collectibles)
if address == self.currentAccount.address: if address == self.currentAccount.address:
# Add CollectibleListJSON to the right list # Add CollectibleListJSON to the right list
self.currentCollectiblesLists.setCollectiblesJSONByType( self.currentCollectiblesLists.setCollectiblesJSONByType(
collectibleData["collectibleType"].getStr, collectibleType,
$collectibles $collectibles
) )

View File

@ -1,7 +1,7 @@
import NimQml, Tables, random, strformat, json_serialization import NimQml, Tables, random, strformat, json_serialization
import sequtils as sequtils import sequtils as sequtils
import account_item, asset_list import account_item, asset_list
from ../../../status/wallet import WalletAccount, Asset from ../../../status/wallet import WalletAccount, Asset, CollectibleList
const accountColors* = ["#9B832F", "#D37EF4", "#1D806F", "#FA6565", "#7CDA00", "#887af9", "#8B3131"] const accountColors* = ["#9B832F", "#D37EF4", "#1D806F", "#FA6565", "#7CDA00", "#887af9", "#8B3131"]
type type
@ -56,6 +56,21 @@ QtObject:
i = i + 1 i = i + 1
return -1 return -1
proc addCollectibleListToAccount*(self: AccountList, index: int, collectibleType: string, collectibles: string) =
var i = 0
for collectibleList in self.accounts[index].account.collectiblesLists:
if collectibleList.collectibleType == collectibleType:
self.accounts[index].account.collectiblesLists[i].collectiblesJSON = collectibles
return
i = i + 1
self.accounts[index].account.collectiblesLists.add(CollectibleList(
collectibleType: collectibleType,
collectiblesJSON: collectibles,
error: "",
loading: 0
))
proc deleteAccountAtIndex*(self: AccountList, index: int) = proc deleteAccountAtIndex*(self: AccountList, index: int) =
sequtils.delete(self.accounts, index, index) sequtils.delete(self.accounts, index, index)