diff --git a/src/app/wallet/view.nim b/src/app/wallet/view.nim index b83863b956..41c53d9331 100644 --- a/src/app/wallet/view.nim +++ b/src/app/wallet/view.nim @@ -131,9 +131,6 @@ QtObject: proc setDappBrowserAddress*(self: WalletView) {.slot.} = self.dappBrowserView.setDappBrowserAddress() - proc loadTransactionsForAccount*(self: WalletView, address: string) {.slot.} = - self.historyView.loadTransactionsForAccount(address) - proc setHistoryFetchState*(self: WalletView, accounts: seq[string], isFetching: bool) = self.historyView.setHistoryFetchState(accounts, isFetching) diff --git a/src/app/wallet/views/history.nim b/src/app/wallet/views/history.nim index 48762d16f8..ebb551978b 100644 --- a/src/app/wallet/views/history.nim +++ b/src/app/wallet/views/history.nim @@ -4,6 +4,7 @@ import NimQml, json, sequtils, chronicles, strutils, strformat, json import ../../../status/[status, settings, wallet, tokens, types, utils], + ../../../status/wallet as status_wallet, ../../../status/tasks/[qt, task_runner_impl] import account_list, account_item, transaction_list, accounts, asset_list, token_list, transactions @@ -11,6 +12,32 @@ import account_list, account_item, transaction_list, accounts, asset_list, token logScope: topics = "history-view" +type + LoadTransactionsTaskArg = ref object of QObjectTaskArg + address: string + toBlock: Uint256 + limit: int + loadMore: bool + +const loadTransactionsTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = + let + arg = decode[LoadTransactionsTaskArg](argEncoded) + output = %*{ + "address": arg.address, + "history": status_wallet.getTransfersByAddress(arg.address, arg.toBlock, arg.limit, arg.loadMore), + "loadMore": arg.loadMore + } + arg.finish(output) + +proc loadTransactions*[T](self: T, slot: string, address: string, toBlock: Uint256, limit: int, loadMore: bool) = + let arg = LoadTransactionsTaskArg( + tptr: cast[ByteAddress](loadTransactionsTask), + vptr: cast[ByteAddress](self.vptr), + slot: slot, address: address, + toBlock: toBlock, limit: limit, loadMore: loadMore + ) + self.status.tasks.threadpool.start(arg) + QtObject: type HistoryView* = ref object of QObject status: Status @@ -46,19 +73,11 @@ QtObject: proc loadingTrxHistoryChanged*(self: HistoryView, isLoading: bool, address: string) {.signal.} - # proc loadTransactionsForAccount*(self: HistoryView, address: string) {.slot.} = - # self.loadingTrxHistoryChanged(true) - # self.transactionsView.loadTransactions("setTrxHistoryResult", address) - proc loadTransactionsForAccount*(self: HistoryView, address: string, toBlock: string = "0x0", limit: int = 20, loadMore: bool = false) {.slot.} = self.loadingTrxHistoryChanged(true, address) let toBlockParsed = stint.fromHex(Uint256, toBlock) self.loadTransactions("setTrxHistoryResult", address, toBlockParsed, limit, loadMore) - # proc getLatestTransactionHistory*(self: HistoryView, accounts: seq[string]) = - # for acc in accounts: - # self.loadTransactionsForAccount(acc) - proc setTrxHistoryResult(self: HistoryView, historyJSON: string) {.slot.} = let historyData = parseJson(historyJSON) diff --git a/src/app/wallet/views/transaction_list.nim b/src/app/wallet/views/transaction_list.nim index 76d580ac41..38b98cd50a 100644 --- a/src/app/wallet/views/transaction_list.nim +++ b/src/app/wallet/views/transaction_list.nim @@ -36,6 +36,8 @@ QtObject: result.setup proc getLastTxBlockNumber*(self: TransactionList): string {.slot.} = + if (self.transactions.len == 0): + return "0x0" return self.transactions[^1].blockNumber method rowCount*(self: TransactionList, index: QModelIndex = nil): int = diff --git a/src/app/wallet/views/transactions.nim b/src/app/wallet/views/transactions.nim index 57873396d5..ea09e3f1eb 100644 --- a/src/app/wallet/views/transactions.nim +++ b/src/app/wallet/views/transactions.nim @@ -23,11 +23,6 @@ type gasPrice: string password: string uuid: string - LoadTransactionsTaskArg = ref object of QObjectTaskArg - address: string - toBlock: Uint256 - limit: int - loadMore: bool WatchTransactionTaskArg = ref object of QObjectTaskArg transactionHash: string @@ -53,25 +48,6 @@ proc sendTransaction[T](self: T, slot: string, from_addr: string, to: string, as ) self.status.tasks.threadpool.start(arg) -const loadTransactionsTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = - let - arg = decode[LoadTransactionsTaskArg](argEncoded) - output = %*{ - "address": arg.address, - "history": status_wallet.getTransfersByAddress(arg.address, arg.toBlock, arg.limit, arg.loadMore), - "loadMore": arg.loadMore - } - arg.finish(output) - -proc loadTransactions*[T](self: T, slot: string, address: string, toBlock: Uint256, limit: int, loadMore: bool) = - let arg = LoadTransactionsTaskArg( - tptr: cast[ByteAddress](loadTransactionsTask), - vptr: cast[ByteAddress](self.vptr), - slot: slot, address: address, - toBlock: toBlock, limit: limit, loadMore: loadMore - ) - self.status.tasks.threadpool.start(arg) - const watchTransactionTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = let arg = decode[WatchTransactionTaskArg](argEncoded) diff --git a/ui/app/AppLayouts/Wallet/HistoryTab.qml b/ui/app/AppLayouts/Wallet/HistoryTab.qml index 804d47ee11..63cecdc50e 100644 --- a/ui/app/AppLayouts/Wallet/HistoryTab.qml +++ b/ui/app/AppLayouts/Wallet/HistoryTab.qml @@ -30,12 +30,12 @@ Item { } function fetchHistory() { - if (walletModel.isFetchingHistory()) { + if (walletModel.historyView.isFetchingHistory(walletModel.accountsView.currentAccount.address)) { loadingImg.active = true } else { - walletModel.loadTransactionsForAccount( - walletModel.currentAccount.address, - walletModel.transactions.getLastTxBlockNumber(), + walletModel.historyView.loadTransactionsForAccount( + walletModel.accountsView.currentAccount.address, + walletModel.transactionsView.transactions.getLastTxBlockNumber(), pageSize, true) } @@ -72,7 +72,7 @@ Item { target: walletModel.historyView // onHistoryWasFetched: checkIfHistoryIsBeingFetched() onLoadingTrxHistoryChanged: { - if (walletModel.currentAccount.address.toLowerCase() === address.toLowerCase()) { + if (walletModel.accountsView.currentAccount.address.toLowerCase() === address.toLowerCase()) { loadingImg.active = isLoading } } @@ -267,7 +267,7 @@ Item { text: qsTrId("load-more") // TODO: handle case when requested limit === transaction count -- there // is currently no way to know that there are no more results - enabled: !loadingImg.active && walletModel.transactions.hasMore + enabled: !loadingImg.active && walletModel.transactionsView.transactions.hasMore anchors.right: parent.right anchors.bottom: parent.bottom anchors.bottomMargin: Style.current.padding