fix(@desktop/wallet): Wallet -> Activity tab: transaction history issues

fixes #7278
This commit is contained in:
Khushboo Mehta 2023-01-03 10:24:04 +01:00 committed by Khushboo-dev-cpp
parent 8cb4420d49
commit bfd5fe1446
8 changed files with 49 additions and 23 deletions

View File

@ -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()

View File

@ -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")

View File

@ -248,5 +248,3 @@ QtObject:
self.items = allTxs
self.setItems(itemsWithDateHeaders)
self.setHasMore(true)
else:
self.setHasMore(false)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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,8 +216,22 @@ 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 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),
@ -222,8 +240,9 @@ QtObject:
toBlock: toBlock,
limit: limit,
loadMore: loadMore,
chainId: networks.chainId,
chainId: network.chainId,
)
self.txCounter[address] = networkChains
self.threadpool.start(arg)
proc transfer*(

View File

@ -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
}
}