fix(hisotry): fix load more history button

Fixes #2754
This commit is contained in:
Jonathan Rainville 2021-06-23 15:23:30 -04:00 committed by Iuri Matias
parent f71870cb8f
commit eb726a315c
5 changed files with 35 additions and 41 deletions

View File

@ -131,9 +131,6 @@ QtObject:
proc setDappBrowserAddress*(self: WalletView) {.slot.} = proc setDappBrowserAddress*(self: WalletView) {.slot.} =
self.dappBrowserView.setDappBrowserAddress() self.dappBrowserView.setDappBrowserAddress()
proc loadTransactionsForAccount*(self: WalletView, address: string) {.slot.} =
self.historyView.loadTransactionsForAccount(address)
proc setHistoryFetchState*(self: WalletView, accounts: seq[string], isFetching: bool) = proc setHistoryFetchState*(self: WalletView, accounts: seq[string], isFetching: bool) =
self.historyView.setHistoryFetchState(accounts, isFetching) self.historyView.setHistoryFetchState(accounts, isFetching)

View File

@ -4,6 +4,7 @@ import NimQml, json, sequtils, chronicles, strutils, strformat, json
import import
../../../status/[status, settings, wallet, tokens, types, utils], ../../../status/[status, settings, wallet, tokens, types, utils],
../../../status/wallet as status_wallet,
../../../status/tasks/[qt, task_runner_impl] ../../../status/tasks/[qt, task_runner_impl]
import account_list, account_item, transaction_list, accounts, asset_list, token_list, transactions 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: logScope:
topics = "history-view" 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: QtObject:
type HistoryView* = ref object of QObject type HistoryView* = ref object of QObject
status: Status status: Status
@ -46,19 +73,11 @@ QtObject:
proc loadingTrxHistoryChanged*(self: HistoryView, isLoading: bool, address: string) {.signal.} 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.} = proc loadTransactionsForAccount*(self: HistoryView, address: string, toBlock: string = "0x0", limit: int = 20, loadMore: bool = false) {.slot.} =
self.loadingTrxHistoryChanged(true, address) self.loadingTrxHistoryChanged(true, address)
let toBlockParsed = stint.fromHex(Uint256, toBlock) let toBlockParsed = stint.fromHex(Uint256, toBlock)
self.loadTransactions("setTrxHistoryResult", address, toBlockParsed, limit, loadMore) 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.} = proc setTrxHistoryResult(self: HistoryView, historyJSON: string) {.slot.} =
let let
historyData = parseJson(historyJSON) historyData = parseJson(historyJSON)

View File

@ -36,6 +36,8 @@ QtObject:
result.setup result.setup
proc getLastTxBlockNumber*(self: TransactionList): string {.slot.} = proc getLastTxBlockNumber*(self: TransactionList): string {.slot.} =
if (self.transactions.len == 0):
return "0x0"
return self.transactions[^1].blockNumber return self.transactions[^1].blockNumber
method rowCount*(self: TransactionList, index: QModelIndex = nil): int = method rowCount*(self: TransactionList, index: QModelIndex = nil): int =

View File

@ -23,11 +23,6 @@ type
gasPrice: string gasPrice: string
password: string password: string
uuid: string uuid: string
LoadTransactionsTaskArg = ref object of QObjectTaskArg
address: string
toBlock: Uint256
limit: int
loadMore: bool
WatchTransactionTaskArg = ref object of QObjectTaskArg WatchTransactionTaskArg = ref object of QObjectTaskArg
transactionHash: string 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) 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.} = const watchTransactionTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let let
arg = decode[WatchTransactionTaskArg](argEncoded) arg = decode[WatchTransactionTaskArg](argEncoded)

View File

@ -30,12 +30,12 @@ Item {
} }
function fetchHistory() { function fetchHistory() {
if (walletModel.isFetchingHistory()) { if (walletModel.historyView.isFetchingHistory(walletModel.accountsView.currentAccount.address)) {
loadingImg.active = true loadingImg.active = true
} else { } else {
walletModel.loadTransactionsForAccount( walletModel.historyView.loadTransactionsForAccount(
walletModel.currentAccount.address, walletModel.accountsView.currentAccount.address,
walletModel.transactions.getLastTxBlockNumber(), walletModel.transactionsView.transactions.getLastTxBlockNumber(),
pageSize, pageSize,
true) true)
} }
@ -72,7 +72,7 @@ Item {
target: walletModel.historyView target: walletModel.historyView
// onHistoryWasFetched: checkIfHistoryIsBeingFetched() // onHistoryWasFetched: checkIfHistoryIsBeingFetched()
onLoadingTrxHistoryChanged: { onLoadingTrxHistoryChanged: {
if (walletModel.currentAccount.address.toLowerCase() === address.toLowerCase()) { if (walletModel.accountsView.currentAccount.address.toLowerCase() === address.toLowerCase()) {
loadingImg.active = isLoading loadingImg.active = isLoading
} }
} }
@ -267,7 +267,7 @@ Item {
text: qsTrId("load-more") text: qsTrId("load-more")
// TODO: handle case when requested limit === transaction count -- there // TODO: handle case when requested limit === transaction count -- there
// 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: !loadingImg.active && walletModel.transactions.hasMore enabled: !loadingImg.active && walletModel.transactionsView.transactions.hasMore
anchors.right: parent.right anchors.right: parent.right
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.bottomMargin: Style.current.padding anchors.bottomMargin: Style.current.padding