diff --git a/src/app/modules/main/wallet_section/transactions/controller.nim b/src/app/modules/main/wallet_section/transactions/controller.nim index b0b50a9629..b7b1d88920 100644 --- a/src/app/modules/main/wallet_section/transactions/controller.nim +++ b/src/app/modules/main/wallet_section/transactions/controller.nim @@ -48,20 +48,20 @@ proc init*(self: Controller) = # TODO find a way to use data.blockNumber self.loadTransactions(account, stint.fromHex(Uint256, "0x0")) of "recent-history-fetching": - self.delegate.setHistoryFetchState(data.accounts, true) + self.delegate.setHistoryFetchState(data.accounts, isFetching = true) of "recent-history-ready": for account in data.accounts: self.loadTransactions(account, stint.fromHex(Uint256, "0x0")) - self.delegate.setHistoryFetchState(data.accounts, false) + self.delegate.setHistoryFetchState(data.accounts, isFetching = false) of "non-archival-node-detected": let accounts = self.getWalletAccounts() let addresses = accounts.map(account => account.address) - self.delegate.setHistoryFetchState(addresses, false) + self.delegate.setHistoryFetchState(addresses, isFetching = false) self.delegate.setIsNonArchivalNode(true) of "fetching-history-error": let accounts = self.getWalletAccounts() let addresses = accounts.map(account => account.address) - self.delegate.setHistoryFetchState(addresses, false) + self.delegate.setHistoryFetchState(addresses, isFetching = false) self.events.on(SIGNAL_TRANSACTIONS_LOADED) do(e:Args): let args = TransactionsLoadedArgs(e) @@ -82,6 +82,10 @@ proc init*(self: Controller) = self.events.on(SIGNAL_PENDING_TX_COMPLETED) do(e:Args): self.walletAccountService.checkRecentHistory() + self.events.on(SIGNAL_TRANSACTION_LOADING_COMPLETED_FOR_ALL_NETWORKS) do(e:Args): + let args = TransactionsLoadedArgs(e) + self.delegate.setHistoryFetchState(args.address, isFetching = false) + proc checkPendingTransactions*(self: Controller): seq[TransactionDto] = return self.transactionService.checkPendingTransactions() diff --git a/src/app/modules/main/wallet_section/transactions/io_interface.nim b/src/app/modules/main/wallet_section/transactions/io_interface.nim index 6f71d51b2e..5a1be21cd8 100644 --- a/src/app/modules/main/wallet_section/transactions/io_interface.nim +++ b/src/app/modules/main/wallet_section/transactions/io_interface.nim @@ -34,6 +34,9 @@ method setTrxHistoryResult*(self: AccessInterface, transactions: seq[Transaction method setHistoryFetchState*(self: AccessInterface, addresses: seq[string], isFetching: bool) {.base.} = raise newException(ValueError, "No implementation available") +method setHistoryFetchState*(self: AccessInterface, address: string, isFetching: bool) {.base.} = + raise newException(ValueError, "No implementation available") + method setIsNonArchivalNode*(self: AccessInterface, isNonArchivalNode: bool) {.base.} = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/wallet_section/transactions/model.nim b/src/app/modules/main/wallet_section/transactions/model.nim index 99bc89d0b5..68753c9f59 100644 --- a/src/app/modules/main/wallet_section/transactions/model.nim +++ b/src/app/modules/main/wallet_section/transactions/model.nim @@ -248,5 +248,3 @@ QtObject: self.items = allTxs self.setItems(itemsWithDateHeaders) self.setHasMore(true) - else: - self.setHasMore(false) diff --git a/src/app/modules/main/wallet_section/transactions/module.nim b/src/app/modules/main/wallet_section/transactions/module.nim index 57c9b6502b..0f59f1ac77 100644 --- a/src/app/modules/main/wallet_section/transactions/module.nim +++ b/src/app/modules/main/wallet_section/transactions/module.nim @@ -91,6 +91,9 @@ method setTrxHistoryResult*(self: Module, transactions: seq[TransactionDto], add method setHistoryFetchState*(self: Module, addresses: seq[string], isFetching: bool) = self.view.setHistoryFetchStateForAccounts(addresses, isFetching) +method setHistoryFetchState*(self: Module, address: string, isFetching: bool) = + self.view.setHistoryFetchState(address, isFetching) + method setIsNonArchivalNode*(self: Module, isNonArchivalNode: bool) = self.view.setIsNonArchivalNode(isNonArchivalNode) diff --git a/src/app/modules/main/wallet_section/transactions/view.nim b/src/app/modules/main/wallet_section/transactions/view.nim index 9e8baf9d65..4665b5367a 100644 --- a/src/app/modules/main/wallet_section/transactions/view.nim +++ b/src/app/modules/main/wallet_section/transactions/view.nim @@ -75,8 +75,6 @@ QtObject: self.models[address].addNewTransactions(transactions, wasFetchMore) - self.setHistoryFetchState(address, false) - proc setHistoryFetchStateForAccounts*(self: View, addresses: seq[string], isFetching: bool) = for address in addresses: self.setHistoryFetchState(address, isFetching) diff --git a/src/app_service/service/transaction/async_tasks.nim b/src/app_service/service/transaction/async_tasks.nim index f5672756ec..123e2be89f 100644 --- a/src/app_service/service/transaction/async_tasks.nim +++ b/src/app_service/service/transaction/async_tasks.nim @@ -26,7 +26,7 @@ const loadTransactionsTask*: Task = proc(argEncoded: string) {.gcsafe, nimcall.} "address": arg.address, "chainId": arg.chainId, "history": transactions.getTransfersByAddress(arg.chainId, arg.address, arg.toBlock, limitAsHex, arg.loadMore), - "loadMore": arg.loadMore + "loadMore": arg.loadMore, } arg.finish(output) diff --git a/src/app_service/service/transaction/service.nim b/src/app_service/service/transaction/service.nim index ef5c78f0a6..e620a1418f 100644 --- a/src/app_service/service/transaction/service.nim +++ b/src/app_service/service/transaction/service.nim @@ -1,4 +1,4 @@ -import Tables, NimQml, chronicles, sequtils, sugar, stint, strutils, json, strformat, algorithm, math +import Tables, NimQml, chronicles, sequtils, sugar, stint, strutils, json, strformat, algorithm, math, random import ../../../backend/transactions as transactions import ../../../backend/backend @@ -36,6 +36,7 @@ const SIGNAL_TRANSACTIONS_LOADED* = "transactionsLoaded" const SIGNAL_TRANSACTION_SENT* = "transactionSent" const SIGNAL_SUGGESTED_ROUTES_READY* = "suggestedRoutesReady" const SIGNAL_PENDING_TX_COMPLETED* = "pendingTransactionCompleted" +const SIGNAL_TRANSACTION_LOADING_COMPLETED_FOR_ALL_NETWORKS* = "transactionsLoadingCompleteForAllNetworks" type EstimatedTime* {.pure.} = enum @@ -78,6 +79,7 @@ QtObject: networkService: network_service.Service settingsService: settings_service.Service tokenService: token_service.Service + txCounter: Table[string, seq[int]] # Forward declaration proc checkPendingTransactions*(self: Service): seq[TransactionDto] @@ -100,6 +102,7 @@ QtObject: result.networkService = networkService result.settingsService = settingsService result.tokenService = tokenService + result.txCounter = initTable[string, seq[int]]() proc doConnect*(self: Service) = self.events.on(SignalType.Wallet.event) do(e:Args): @@ -200,6 +203,7 @@ QtObject: proc setTrxHistoryResult*(self: Service, historyJSON: string) {.slot.} = let historyData = parseJson(historyJSON) let address = historyData["address"].getStr + let chainID = historyData["chainId"].getInt let wasFetchMore = historyData["loadMore"].getBool var transactions: seq[TransactionDto] = @[] for tx in historyData["history"]["result"].getElems(): @@ -212,19 +216,34 @@ QtObject: wasFetchMore: wasFetchMore )) + # when requests for all networks are completed then set loading state as completed + if self.txCounter.hasKey(address): + var chainIDs = self.txCounter[address] + chainIDs.del(chainIDs.find(chainID)) + self.txCounter[address] = chainIDs + if self.txCounter[address].len == 0: + self.txCounter.del(address) + self.events.emit(SIGNAL_TRANSACTION_LOADING_COMPLETED_FOR_ALL_NETWORKS, TransactionsLoadedArgs(address: address)) + proc loadTransactions*(self: Service, address: string, toBlock: Uint256, limit: int = 20, loadMore: bool = false) = - for networks in self.networkService.getNetworks(): - let arg = LoadTransactionsTaskArg( - address: address, - tptr: cast[ByteAddress](loadTransactionsTask), - vptr: cast[ByteAddress](self.vptr), - slot: "setTrxHistoryResult", - toBlock: toBlock, - limit: limit, - loadMore: loadMore, - chainId: networks.chainId, - ) - self.threadpool.start(arg) + let networks = self.networkService.getNetworks() + if not self.txCounter.hasKey(address): + var networkChains: seq[int] = @[] + self.txCounter[address] = networkChains + for network in networks: + networkChains.add(network.chainId) + let arg = LoadTransactionsTaskArg( + address: address, + tptr: cast[ByteAddress](loadTransactionsTask), + vptr: cast[ByteAddress](self.vptr), + slot: "setTrxHistoryResult", + toBlock: toBlock, + limit: limit, + loadMore: loadMore, + chainId: network.chainId, + ) + self.txCounter[address] = networkChains + self.threadpool.start(arg) proc transfer*( self: Service, diff --git a/ui/imports/shared/views/HistoryView.qml b/ui/imports/shared/views/HistoryView.qml index 70479b3a6b..dfc80d16aa 100644 --- a/ui/imports/shared/views/HistoryView.qml +++ b/ui/imports/shared/views/HistoryView.qml @@ -44,7 +44,7 @@ ColumnLayout { id: loadingImg active: isLoading sourceComponent: loadingImageComponent - Layout.alignment: Qt.AlignRight | Qt.AlignTop + Layout.alignment: Qt.AlignHCenter | Qt.AlignTop Layout.rightMargin: Style.current.padding } @@ -94,6 +94,7 @@ ColumnLayout { // is currently no way to know that there are no more results enabled: !isLoading && RootStore.historyTransactions.hasMore onClicked: fetchHistory() + loading: isLoading } }