feat: load more transactions with a button
use qstrid; trx width and heights; add positionViewEnd; fix some qt rules; missing semi colons
This commit is contained in:
parent
5da0d47c5a
commit
7a5060da32
|
@ -518,14 +518,22 @@ QtObject:
|
||||||
return self.fetchingHistoryState[address]
|
return self.fetchingHistoryState[address]
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
proc isHistoryFetched*(self: WalletView, address: string): bool {.slot.} =
|
||||||
|
return self.currentTransactions.rowCount() > 0
|
||||||
|
|
||||||
proc loadingTrxHistory*(self: WalletView, isLoading: bool) {.signal.}
|
proc loadingTrxHistory*(self: WalletView, isLoading: bool) {.signal.}
|
||||||
|
|
||||||
proc loadTransactionsForAccount*(self: WalletView, address: string) {.slot.} =
|
proc loadTransactionsForAccount*(self: WalletView, address: string) {.slot.} =
|
||||||
|
var bn = "latest"
|
||||||
|
if self.currentTransactions.rowCount() > 0:
|
||||||
|
bn = self.currentTransactions.getLastTxBlockNumber()
|
||||||
|
# spawn'ed function cannot have a 'var' parameter
|
||||||
|
let blockNumber = bn
|
||||||
self.loadingTrxHistory(true)
|
self.loadingTrxHistory(true)
|
||||||
spawnAndSend(self, "setTrxHistoryResult") do:
|
spawnAndSend(self, "setTrxHistoryResult") do:
|
||||||
$(%*{
|
$(%*{
|
||||||
"address": address,
|
"address": address,
|
||||||
"history": getTransfersByAddress(address)
|
"history": getTransfersByAddress(address, blockNumber)
|
||||||
})
|
})
|
||||||
|
|
||||||
proc setTrxHistoryResult(self: WalletView, historyJSON: string) {.slot.} =
|
proc setTrxHistoryResult(self: WalletView, historyJSON: string) {.slot.} =
|
||||||
|
@ -534,9 +542,10 @@ QtObject:
|
||||||
let address = historyData["address"].getStr
|
let address = historyData["address"].getStr
|
||||||
let index = self.accounts.getAccountindexByAddress(address)
|
let index = self.accounts.getAccountindexByAddress(address)
|
||||||
if index == -1: return
|
if index == -1: return
|
||||||
self.accounts.getAccount(index).transactions = transactions
|
self.accounts.getAccount(index).transactions.add(transactions)
|
||||||
if address == self.currentAccount.address:
|
if address == self.currentAccount.address:
|
||||||
self.setCurrentTransactions(transactions)
|
self.setCurrentTransactions(
|
||||||
|
self.accounts.getAccount(index).transactions)
|
||||||
self.loadingTrxHistory(false)
|
self.loadingTrxHistory(false)
|
||||||
|
|
||||||
proc resolveENS*(self: WalletView, ens: string) {.slot.} =
|
proc resolveENS*(self: WalletView, ens: string) {.slot.} =
|
||||||
|
|
|
@ -33,7 +33,10 @@ QtObject:
|
||||||
result.transactions = @[]
|
result.transactions = @[]
|
||||||
result.setup
|
result.setup
|
||||||
|
|
||||||
method rowCount(self: TransactionList, index: QModelIndex = nil): int =
|
proc getLastTxBlockNumber*(self: TransactionList): string =
|
||||||
|
return self.transactions[^1].blockNumber
|
||||||
|
|
||||||
|
method rowCount*(self: TransactionList, index: QModelIndex = nil): int =
|
||||||
return self.transactions.len
|
return self.transactions.len
|
||||||
|
|
||||||
method data(self: TransactionList, index: QModelIndex, role: int): QVariant =
|
method data(self: TransactionList, index: QModelIndex, role: int): QVariant =
|
||||||
|
|
|
@ -33,9 +33,9 @@ proc getWalletAccounts*(): seq[WalletAccount] =
|
||||||
proc getTransactionReceipt*(transactionHash: string): string =
|
proc getTransactionReceipt*(transactionHash: string): string =
|
||||||
result = callPrivateRPC("eth_getTransactionReceipt", %* [transactionHash])
|
result = callPrivateRPC("eth_getTransactionReceipt", %* [transactionHash])
|
||||||
|
|
||||||
proc getTransfersByAddress*(address: string): seq[types.Transaction] =
|
proc getTransfersByAddress*(address: string, blockNumber: string = "latest"): seq[types.Transaction] =
|
||||||
try:
|
try:
|
||||||
let response = getBlockByNumber("latest")
|
let response = getBlockByNumber(blockNumber)
|
||||||
let latestBlock = parseJson(response)["result"]
|
let latestBlock = parseJson(response)["result"]
|
||||||
|
|
||||||
let transactionsResponse = getTransfersByAddress(address, latestBlock["number"].getStr, "0x14")
|
let transactionsResponse = getTransfersByAddress(address, latestBlock["number"].getStr, "0x14")
|
||||||
|
@ -59,7 +59,11 @@ proc getTransfersByAddress*(address: string): seq[types.Transaction] =
|
||||||
fromAddress: transaction["from"].getStr,
|
fromAddress: transaction["from"].getStr,
|
||||||
to: transaction["to"].getStr
|
to: transaction["to"].getStr
|
||||||
))
|
))
|
||||||
result = accountTransactions
|
# if we feching more trxs, we should skip the first trx as its already saved in the
|
||||||
|
# existing list
|
||||||
|
if blockNumber == "latest":
|
||||||
|
return accountTransactions
|
||||||
|
return accountTransactions[1 .. ^1]
|
||||||
except:
|
except:
|
||||||
let msg = getCurrentExceptionMsg()
|
let msg = getCurrentExceptionMsg()
|
||||||
error "Failed getting wallet account transactions", msg
|
error "Failed getting wallet account transactions", msg
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
import QtQuick 2.13
|
import QtQuick 2.13
|
||||||
|
import QtQuick.Controls 2.1
|
||||||
|
import QtQuick.Layouts 1.3
|
||||||
import "./components"
|
import "./components"
|
||||||
import "./data"
|
import "./data"
|
||||||
import "../../../imports"
|
import "../../../imports"
|
||||||
import "../../../shared"
|
import "../../../shared"
|
||||||
|
import "../../../shared/status"
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
property var tokens: {
|
property var tokens: {
|
||||||
|
@ -18,6 +21,17 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkIfHistoryIsBeingFetched() {
|
function checkIfHistoryIsBeingFetched() {
|
||||||
|
loadMoreButton.loadedMore = false;
|
||||||
|
|
||||||
|
// prevent history from being fetched everytime you click on
|
||||||
|
// the history tab
|
||||||
|
if (walletModel.isHistoryFetched(walletModel.currentAccount.account))
|
||||||
|
return;
|
||||||
|
|
||||||
|
fetchHistory();
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetchHistory() {
|
||||||
if (walletModel.isFetchingHistory(walletModel.currentAccount.address)) {
|
if (walletModel.isFetchingHistory(walletModel.currentAccount.address)) {
|
||||||
loadingImg.active = true
|
loadingImg.active = true
|
||||||
} else {
|
} else {
|
||||||
|
@ -205,10 +219,48 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
|
id: transactionListRoot
|
||||||
anchors.topMargin: 20
|
anchors.topMargin: 20
|
||||||
anchors.fill: parent
|
height: parent.height - extraButtons.height
|
||||||
|
width: parent.width
|
||||||
|
clip: true
|
||||||
model: walletModel.transactions
|
model: walletModel.transactions
|
||||||
delegate: transactionListItemCmp
|
delegate: transactionListItemCmp
|
||||||
|
ScrollBar.vertical: ScrollBar {
|
||||||
|
id: scrollBar
|
||||||
|
}
|
||||||
|
|
||||||
|
onCountChanged: {
|
||||||
|
if (loadMoreButton.loadedMore)
|
||||||
|
transactionListRoot.positionViewAtEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
id: extraButtons
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
height: loadMoreButton.height
|
||||||
|
|
||||||
|
StatusButton {
|
||||||
|
id: loadMoreButton
|
||||||
|
//% "Load More"
|
||||||
|
text: qsTrId("load-more")
|
||||||
|
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
|
||||||
|
property bool loadedMore: false
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
onClicked: {
|
||||||
|
fetchHistory()
|
||||||
|
loadMoreButton.loadedMore = true
|
||||||
|
}
|
||||||
|
|
||||||
|
onLoadingTrxHistory: {
|
||||||
|
loadingImg.active = isLoading
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue