fix(@desktop/wallet): Wallet -> Activity tab: transaction history issues
fixes #7278
This commit is contained in:
parent
8cb4420d49
commit
bfd5fe1446
|
@ -48,20 +48,20 @@ proc init*(self: Controller) =
|
||||||
# TODO find a way to use data.blockNumber
|
# TODO find a way to use data.blockNumber
|
||||||
self.loadTransactions(account, stint.fromHex(Uint256, "0x0"))
|
self.loadTransactions(account, stint.fromHex(Uint256, "0x0"))
|
||||||
of "recent-history-fetching":
|
of "recent-history-fetching":
|
||||||
self.delegate.setHistoryFetchState(data.accounts, true)
|
self.delegate.setHistoryFetchState(data.accounts, isFetching = true)
|
||||||
of "recent-history-ready":
|
of "recent-history-ready":
|
||||||
for account in data.accounts:
|
for account in data.accounts:
|
||||||
self.loadTransactions(account, stint.fromHex(Uint256, "0x0"))
|
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":
|
of "non-archival-node-detected":
|
||||||
let accounts = self.getWalletAccounts()
|
let accounts = self.getWalletAccounts()
|
||||||
let addresses = accounts.map(account => account.address)
|
let addresses = accounts.map(account => account.address)
|
||||||
self.delegate.setHistoryFetchState(addresses, false)
|
self.delegate.setHistoryFetchState(addresses, isFetching = false)
|
||||||
self.delegate.setIsNonArchivalNode(true)
|
self.delegate.setIsNonArchivalNode(true)
|
||||||
of "fetching-history-error":
|
of "fetching-history-error":
|
||||||
let accounts = self.getWalletAccounts()
|
let accounts = self.getWalletAccounts()
|
||||||
let addresses = accounts.map(account => account.address)
|
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):
|
self.events.on(SIGNAL_TRANSACTIONS_LOADED) do(e:Args):
|
||||||
let args = TransactionsLoadedArgs(e)
|
let args = TransactionsLoadedArgs(e)
|
||||||
|
@ -82,6 +82,10 @@ proc init*(self: Controller) =
|
||||||
self.events.on(SIGNAL_PENDING_TX_COMPLETED) do(e:Args):
|
self.events.on(SIGNAL_PENDING_TX_COMPLETED) do(e:Args):
|
||||||
self.walletAccountService.checkRecentHistory()
|
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] =
|
proc checkPendingTransactions*(self: Controller): seq[TransactionDto] =
|
||||||
return self.transactionService.checkPendingTransactions()
|
return self.transactionService.checkPendingTransactions()
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,9 @@ method setTrxHistoryResult*(self: AccessInterface, transactions: seq[Transaction
|
||||||
method setHistoryFetchState*(self: AccessInterface, addresses: seq[string], isFetching: bool) {.base.} =
|
method setHistoryFetchState*(self: AccessInterface, addresses: seq[string], isFetching: bool) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
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.} =
|
method setIsNonArchivalNode*(self: AccessInterface, isNonArchivalNode: bool) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
|
|
@ -248,5 +248,3 @@ QtObject:
|
||||||
self.items = allTxs
|
self.items = allTxs
|
||||||
self.setItems(itemsWithDateHeaders)
|
self.setItems(itemsWithDateHeaders)
|
||||||
self.setHasMore(true)
|
self.setHasMore(true)
|
||||||
else:
|
|
||||||
self.setHasMore(false)
|
|
||||||
|
|
|
@ -91,6 +91,9 @@ method setTrxHistoryResult*(self: Module, transactions: seq[TransactionDto], add
|
||||||
method setHistoryFetchState*(self: Module, addresses: seq[string], isFetching: bool) =
|
method setHistoryFetchState*(self: Module, addresses: seq[string], isFetching: bool) =
|
||||||
self.view.setHistoryFetchStateForAccounts(addresses, isFetching)
|
self.view.setHistoryFetchStateForAccounts(addresses, isFetching)
|
||||||
|
|
||||||
|
method setHistoryFetchState*(self: Module, address: string, isFetching: bool) =
|
||||||
|
self.view.setHistoryFetchState(address, isFetching)
|
||||||
|
|
||||||
method setIsNonArchivalNode*(self: Module, isNonArchivalNode: bool) =
|
method setIsNonArchivalNode*(self: Module, isNonArchivalNode: bool) =
|
||||||
self.view.setIsNonArchivalNode(isNonArchivalNode)
|
self.view.setIsNonArchivalNode(isNonArchivalNode)
|
||||||
|
|
||||||
|
|
|
@ -75,8 +75,6 @@ QtObject:
|
||||||
|
|
||||||
self.models[address].addNewTransactions(transactions, wasFetchMore)
|
self.models[address].addNewTransactions(transactions, wasFetchMore)
|
||||||
|
|
||||||
self.setHistoryFetchState(address, false)
|
|
||||||
|
|
||||||
proc setHistoryFetchStateForAccounts*(self: View, addresses: seq[string], isFetching: bool) =
|
proc setHistoryFetchStateForAccounts*(self: View, addresses: seq[string], isFetching: bool) =
|
||||||
for address in addresses:
|
for address in addresses:
|
||||||
self.setHistoryFetchState(address, isFetching)
|
self.setHistoryFetchState(address, isFetching)
|
||||||
|
|
|
@ -26,7 +26,7 @@ const loadTransactionsTask*: Task = proc(argEncoded: string) {.gcsafe, nimcall.}
|
||||||
"address": arg.address,
|
"address": arg.address,
|
||||||
"chainId": arg.chainId,
|
"chainId": arg.chainId,
|
||||||
"history": transactions.getTransfersByAddress(arg.chainId, arg.address, arg.toBlock, limitAsHex, arg.loadMore),
|
"history": transactions.getTransfersByAddress(arg.chainId, arg.address, arg.toBlock, limitAsHex, arg.loadMore),
|
||||||
"loadMore": arg.loadMore
|
"loadMore": arg.loadMore,
|
||||||
}
|
}
|
||||||
arg.finish(output)
|
arg.finish(output)
|
||||||
|
|
||||||
|
|
|
@ -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/transactions as transactions
|
||||||
import ../../../backend/backend
|
import ../../../backend/backend
|
||||||
|
@ -36,6 +36,7 @@ const SIGNAL_TRANSACTIONS_LOADED* = "transactionsLoaded"
|
||||||
const SIGNAL_TRANSACTION_SENT* = "transactionSent"
|
const SIGNAL_TRANSACTION_SENT* = "transactionSent"
|
||||||
const SIGNAL_SUGGESTED_ROUTES_READY* = "suggestedRoutesReady"
|
const SIGNAL_SUGGESTED_ROUTES_READY* = "suggestedRoutesReady"
|
||||||
const SIGNAL_PENDING_TX_COMPLETED* = "pendingTransactionCompleted"
|
const SIGNAL_PENDING_TX_COMPLETED* = "pendingTransactionCompleted"
|
||||||
|
const SIGNAL_TRANSACTION_LOADING_COMPLETED_FOR_ALL_NETWORKS* = "transactionsLoadingCompleteForAllNetworks"
|
||||||
|
|
||||||
type
|
type
|
||||||
EstimatedTime* {.pure.} = enum
|
EstimatedTime* {.pure.} = enum
|
||||||
|
@ -78,6 +79,7 @@ QtObject:
|
||||||
networkService: network_service.Service
|
networkService: network_service.Service
|
||||||
settingsService: settings_service.Service
|
settingsService: settings_service.Service
|
||||||
tokenService: token_service.Service
|
tokenService: token_service.Service
|
||||||
|
txCounter: Table[string, seq[int]]
|
||||||
|
|
||||||
# Forward declaration
|
# Forward declaration
|
||||||
proc checkPendingTransactions*(self: Service): seq[TransactionDto]
|
proc checkPendingTransactions*(self: Service): seq[TransactionDto]
|
||||||
|
@ -100,6 +102,7 @@ QtObject:
|
||||||
result.networkService = networkService
|
result.networkService = networkService
|
||||||
result.settingsService = settingsService
|
result.settingsService = settingsService
|
||||||
result.tokenService = tokenService
|
result.tokenService = tokenService
|
||||||
|
result.txCounter = initTable[string, seq[int]]()
|
||||||
|
|
||||||
proc doConnect*(self: Service) =
|
proc doConnect*(self: Service) =
|
||||||
self.events.on(SignalType.Wallet.event) do(e:Args):
|
self.events.on(SignalType.Wallet.event) do(e:Args):
|
||||||
|
@ -200,6 +203,7 @@ QtObject:
|
||||||
proc setTrxHistoryResult*(self: Service, historyJSON: string) {.slot.} =
|
proc setTrxHistoryResult*(self: Service, historyJSON: string) {.slot.} =
|
||||||
let historyData = parseJson(historyJSON)
|
let historyData = parseJson(historyJSON)
|
||||||
let address = historyData["address"].getStr
|
let address = historyData["address"].getStr
|
||||||
|
let chainID = historyData["chainId"].getInt
|
||||||
let wasFetchMore = historyData["loadMore"].getBool
|
let wasFetchMore = historyData["loadMore"].getBool
|
||||||
var transactions: seq[TransactionDto] = @[]
|
var transactions: seq[TransactionDto] = @[]
|
||||||
for tx in historyData["history"]["result"].getElems():
|
for tx in historyData["history"]["result"].getElems():
|
||||||
|
@ -212,8 +216,22 @@ QtObject:
|
||||||
wasFetchMore: wasFetchMore
|
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) =
|
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(
|
let arg = LoadTransactionsTaskArg(
|
||||||
address: address,
|
address: address,
|
||||||
tptr: cast[ByteAddress](loadTransactionsTask),
|
tptr: cast[ByteAddress](loadTransactionsTask),
|
||||||
|
@ -222,8 +240,9 @@ QtObject:
|
||||||
toBlock: toBlock,
|
toBlock: toBlock,
|
||||||
limit: limit,
|
limit: limit,
|
||||||
loadMore: loadMore,
|
loadMore: loadMore,
|
||||||
chainId: networks.chainId,
|
chainId: network.chainId,
|
||||||
)
|
)
|
||||||
|
self.txCounter[address] = networkChains
|
||||||
self.threadpool.start(arg)
|
self.threadpool.start(arg)
|
||||||
|
|
||||||
proc transfer*(
|
proc transfer*(
|
||||||
|
|
|
@ -44,7 +44,7 @@ ColumnLayout {
|
||||||
id: loadingImg
|
id: loadingImg
|
||||||
active: isLoading
|
active: isLoading
|
||||||
sourceComponent: loadingImageComponent
|
sourceComponent: loadingImageComponent
|
||||||
Layout.alignment: Qt.AlignRight | Qt.AlignTop
|
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
|
||||||
Layout.rightMargin: Style.current.padding
|
Layout.rightMargin: Style.current.padding
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,6 +94,7 @@ ColumnLayout {
|
||||||
// is currently no way to know that there are no more results
|
// is currently no way to know that there are no more results
|
||||||
enabled: !isLoading && RootStore.historyTransactions.hasMore
|
enabled: !isLoading && RootStore.historyTransactions.hasMore
|
||||||
onClicked: fetchHistory()
|
onClicked: fetchHistory()
|
||||||
|
loading: isLoading
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue