feat: load transaction history async

This commit is contained in:
Richard Ramos 2020-07-29 15:17:48 -04:00
parent 7c856be981
commit d066b59f81
No known key found for this signature in database
GPG Key ID: 80D4B01265FDFE8F
5 changed files with 66 additions and 21 deletions

View File

@ -1,6 +1,7 @@
import NimQml, Tables, strformat, strutils, chronicles, json
import ../../status/[status, wallet, threads]
import ../../status/wallet/collectibles as status_collectibles
import ../../status/libstatus/wallet as status_wallet
import views/[asset_list, account_list, account_item, transaction_list, collectibles_list]
QtObject:
@ -66,7 +67,22 @@ QtObject:
write = setCurrentCollectiblesList
notify = currentCollectiblesListChanged
proc currentTransactionsChanged*(self: WalletView) {.signal.}
proc getCurrentTransactions*(self: WalletView): QVariant {.slot.} =
return newQVariant(self.currentTransactions)
proc setCurrentTransactions*(self: WalletView, transactionList: seq[Transaction]) =
self.currentTransactions.setNewData(transactionList)
self.currentTransactionsChanged()
QtProperty[QVariant] transactions:
read = getCurrentTransactions
write = setCurrentTransactions
notify = currentTransactionsChanged
proc loadCollectiblesForAccount*(self: WalletView, address: string)
proc loadTransactionsForAccount*(self: WalletView, address: string)
proc currentAccountChanged*(self: WalletView) {.signal.}
@ -82,7 +98,9 @@ QtObject:
# Display currently known collectibles, and get latest from API/Contracts
self.setCurrentCollectiblesList(selectedAccount.collectibles)
self.loadCollectiblesForAccount(selectedAccount.address)
self.currentCollectiblesListChanged()
# Display currently known transactions, and get latest transactions from status-go
self.setCurrentTransactions(selectedAccount.transactions)
self.loadTransactionsForAccount(selectedAccount.address)
proc getCurrentAccount*(self: WalletView): QVariant {.slot.} =
result = newQVariant(self.currentAccount)
@ -106,19 +124,6 @@ QtObject:
write = setCurrentAssetList
notify = currentAssetListChanged
proc currentTransactionsChanged*(self: WalletView) {.signal.}
proc getCurrentTransactions*(self: WalletView): QVariant {.slot.} =
return newQVariant(self.currentTransactions)
proc setCurrentTransactions*(self: WalletView, transactionList: seq[Transaction]) =
self.currentTransactions.setNewData(transactionList)
self.currentTransactionsChanged()
QtProperty[QVariant] transactions:
read = getCurrentTransactions
write = setCurrentTransactions
notify = currentTransactionsChanged
proc totalFiatBalanceChanged*(self: WalletView) {.signal.}
@ -216,9 +221,6 @@ QtObject:
proc addCustomToken*(self: WalletView, address: string, name: string, symbol: string, decimals: string) {.slot.} =
self.status.wallet.toggleAsset(symbol, true, address, name, parseInt(decimals), "")
proc loadTransactionsForAccount*(self: WalletView, address: string) {.slot.} =
self.setCurrentTransactions(self.status.wallet.getTransfersByAddress(address))
proc loadingCollectibles*(self: WalletView, isLoading: bool) {.signal.}
proc loadCollectiblesForAccount*(self: WalletView, address: string) {.slot.} =
@ -233,9 +235,30 @@ QtObject:
let collectibleData = parseJson(collectiblesJSON)
let collectibles = collectibleData["collectibles"].to(seq[Collectible]);
let address = collectibleData["address"].getStr
self.accounts.getAccount(self.accounts.getAccountindexByAddress(address)).collectibles = collectibles
let index = self.accounts.getAccountindexByAddress(address)
if index == -1: return
self.accounts.getAccount(index).collectibles = collectibles
if address == self.currentAccount.address:
self.setCurrentCollectiblesList(collectibles)
self.loadingCollectibles(false)
proc loadingTrxHistory*(self: WalletView, isLoading: bool) {.signal.}
proc loadTransactionsForAccount*(self: WalletView, address: string) {.slot.} =
self.loadingTrxHistory(true)
spawnAndSend(self, "setTrxHistoryResult") do:
$(%*{
"address": address,
"history": getTransfersByAddress(address)
})
proc setTrxHistoryResult(self: WalletView, historyJSON: string) {.slot.} =
let historyData = parseJson(historyJSON)
let transactions = historyData["history"].to(seq[Transaction]);
let address = historyData["address"].getStr
let index = self.accounts.getAccountindexByAddress(address)
if index == -1: return
self.accounts.getAccount(index).transactions = transactions
if address == self.currentAccount.address:
self.setCurrentTransactions(transactions)
self.loadingTrxHistory(false)

View File

@ -90,7 +90,6 @@ proc initAccounts*(self: WalletModel) =
var acc = WalletAccount(account)
self.populateAccount(acc, "")
self.accounts.add(acc)
self.calculateTotalFiatBalance
proc getTotalFiatBalance*(self: WalletModel): string =
var newBalance = 0.0

View File

@ -1,4 +1,5 @@
from eventemitter import Args
import ../libstatus/types
type Collectible* = ref object
name*, image*, id*: string
@ -15,6 +16,7 @@ type WalletAccount* = ref object
assetList*: seq[Asset]
wallet*, chat*: bool
collectibles*: seq[Collectible]
transactions*: seq[Transaction]
type AccountArgs* = ref object of Args
account*: WalletAccount

View File

@ -17,7 +17,6 @@ Item {
anchors.rightMargin: Style.current.padding
anchors.top: parent.top
anchors.topMargin: Style.currentPadding
anchors.verticalCenter: txtPassword.verticalCenter
}
Component {

View File

@ -9,6 +9,28 @@ Item {
id: tokenList
}
Loader {
id: loadingImg
active: false
sourceComponent: loadingImageComponent
anchors.right: parent.right
anchors.rightMargin: Style.current.padding
anchors.top: parent.top
anchors.topMargin: Style.currentPadding
}
Component {
id: loadingImageComponent
LoadingImage {}
}
Connections {
target: walletModel
onLoadingTrxHistory: {
loadingImg.active = isLoading
}
}
Component {
id: transactionListItemCmp