From d066b59f814a4e26486ac2269b58ad94b7d0d1f8 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Wed, 29 Jul 2020 15:17:48 -0400 Subject: [PATCH] feat: load transaction history async --- src/app/wallet/view.nim | 61 ++++++++++++++------ src/status/wallet.nim | 1 - src/status/wallet/account.nim | 2 + ui/app/AppLayouts/Wallet/CollectiblesTab.qml | 1 - ui/app/AppLayouts/Wallet/HistoryTab.qml | 22 +++++++ 5 files changed, 66 insertions(+), 21 deletions(-) diff --git a/src/app/wallet/view.nim b/src/app/wallet/view.nim index 4c83f4127a..48760f0331 100644 --- a/src/app/wallet/view.nim +++ b/src/app/wallet/view.nim @@ -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) diff --git a/src/status/wallet.nim b/src/status/wallet.nim index 3615d11ecb..5a08d1288c 100644 --- a/src/status/wallet.nim +++ b/src/status/wallet.nim @@ -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 diff --git a/src/status/wallet/account.nim b/src/status/wallet/account.nim index 4a0a1c63a2..8e38889658 100644 --- a/src/status/wallet/account.nim +++ b/src/status/wallet/account.nim @@ -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 diff --git a/ui/app/AppLayouts/Wallet/CollectiblesTab.qml b/ui/app/AppLayouts/Wallet/CollectiblesTab.qml index 072c1f0bb8..2354169be3 100644 --- a/ui/app/AppLayouts/Wallet/CollectiblesTab.qml +++ b/ui/app/AppLayouts/Wallet/CollectiblesTab.qml @@ -17,7 +17,6 @@ Item { anchors.rightMargin: Style.current.padding anchors.top: parent.top anchors.topMargin: Style.currentPadding - anchors.verticalCenter: txtPassword.verticalCenter } Component { diff --git a/ui/app/AppLayouts/Wallet/HistoryTab.qml b/ui/app/AppLayouts/Wallet/HistoryTab.qml index cfce578b90..7a70f43518 100644 --- a/ui/app/AppLayouts/Wallet/HistoryTab.qml +++ b/ui/app/AppLayouts/Wallet/HistoryTab.qml @@ -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