2021-10-05 20:50:22 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.1
|
|
|
|
import QtQuick.Layouts 1.3
|
|
|
|
|
2022-07-14 11:03:36 +00:00
|
|
|
import StatusQ.Core 0.1
|
2021-10-20 10:21:23 +00:00
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
2022-09-01 15:34:27 +00:00
|
|
|
import StatusQ.Core.Theme 0.1
|
2021-10-20 10:21:23 +00:00
|
|
|
|
2023-03-23 07:34:05 +00:00
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
2022-07-14 11:03:36 +00:00
|
|
|
import utils 1.0
|
|
|
|
|
2022-03-25 08:46:47 +00:00
|
|
|
import "../panels"
|
2021-10-05 20:50:22 +00:00
|
|
|
import "../popups"
|
|
|
|
import "../stores"
|
|
|
|
import "../controls"
|
|
|
|
|
2022-09-01 15:34:27 +00:00
|
|
|
ColumnLayout {
|
2023-01-12 23:26:48 +00:00
|
|
|
id: root
|
2021-10-05 20:50:22 +00:00
|
|
|
|
2022-03-25 08:46:47 +00:00
|
|
|
property var account
|
2021-10-05 20:50:22 +00:00
|
|
|
property int pageSize: 20 // number of transactions per page
|
|
|
|
|
2022-09-05 09:15:47 +00:00
|
|
|
signal launchTransactionDetail(var transaction)
|
|
|
|
|
2021-10-05 20:50:22 +00:00
|
|
|
function fetchHistory() {
|
2023-01-12 23:26:48 +00:00
|
|
|
if (!RootStore.isFetchingHistory(root.account.address)) {
|
|
|
|
d.isLoading = true
|
|
|
|
RootStore.loadTransactionsForAccount(root.account.address, pageSize)
|
2021-10-05 20:50:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-12 23:26:48 +00:00
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
property bool isLoading: false
|
|
|
|
}
|
|
|
|
|
2021-10-05 20:50:22 +00:00
|
|
|
Connections {
|
2021-10-21 08:22:05 +00:00
|
|
|
target: RootStore.history
|
2023-01-18 09:25:36 +00:00
|
|
|
function onLoadingTrxHistoryChanged(isLoading: bool, address: string) {
|
2023-01-12 23:26:48 +00:00
|
|
|
if (root.account.address.toLowerCase() === address.toLowerCase()) {
|
|
|
|
d.isLoading = isLoading
|
2021-10-05 20:50:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: nonArchivalNodeError
|
2022-09-01 15:34:27 +00:00
|
|
|
Layout.alignment: Qt.AlignTop
|
|
|
|
|
2021-10-05 20:50:22 +00:00
|
|
|
visible: RootStore.isNonArchivalNode
|
2022-04-04 11:26:30 +00:00
|
|
|
text: qsTr("Status Desktop is connected to a non-archival node. Transaction history may be incomplete.")
|
2021-10-05 20:50:22 +00:00
|
|
|
font.pixelSize: Style.current.primaryTextFontSize
|
|
|
|
color: Style.current.danger
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: noTxs
|
2023-01-12 23:26:48 +00:00
|
|
|
visible: !d.isLoading && transactionListRoot.count === 0
|
2022-04-04 11:26:30 +00:00
|
|
|
text: qsTr("No transactions found")
|
2021-10-05 20:50:22 +00:00
|
|
|
font.pixelSize: Style.current.primaryTextFontSize
|
|
|
|
}
|
|
|
|
|
2022-07-14 11:03:36 +00:00
|
|
|
StatusListView {
|
2021-10-05 20:50:22 +00:00
|
|
|
id: transactionListRoot
|
2022-09-20 12:27:52 +00:00
|
|
|
objectName: "walletAccountTransactionList"
|
2022-09-01 15:34:27 +00:00
|
|
|
Layout.alignment: Qt.AlignTop
|
|
|
|
Layout.topMargin: nonArchivalNodeError.visible || noTxs.visible ? Style.current.padding : 0
|
|
|
|
Layout.bottomMargin: Style.current.padding
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
|
2023-03-23 07:34:05 +00:00
|
|
|
property string firstSection
|
|
|
|
|
|
|
|
model: SortFilterProxyModel {
|
|
|
|
id: txModel
|
|
|
|
|
|
|
|
sourceModel: RootStore.historyTransactions
|
|
|
|
|
|
|
|
// LocaleUtils is not accessable from inside expression, but local function works
|
|
|
|
property var formatDate: (ms) => LocaleUtils.formatDate(ms, Locale.ShortFormat)
|
|
|
|
sorters: RoleSorter {
|
|
|
|
roleName: "timestamp"
|
|
|
|
sortOrder: Qt.DescendingOrder
|
|
|
|
}
|
|
|
|
proxyRoles: ExpressionRole {
|
|
|
|
name: "date"
|
|
|
|
expression: {
|
|
|
|
return timestamp > 0 ? txModel.formatDate(timestamp * 1000) : ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-01 15:34:27 +00:00
|
|
|
delegate: Loader {
|
2023-01-12 23:26:48 +00:00
|
|
|
width: ListView.view.width
|
2023-03-23 07:34:05 +00:00
|
|
|
sourceComponent: transactionDelegate
|
2022-09-01 15:34:27 +00:00
|
|
|
onLoaded: {
|
|
|
|
item.modelData = model
|
2023-03-23 07:34:05 +00:00
|
|
|
|
|
|
|
if (index == 0)
|
|
|
|
ListView.view.firstSection = date
|
2021-10-05 20:50:22 +00:00
|
|
|
}
|
2023-01-12 23:26:48 +00:00
|
|
|
}
|
|
|
|
footer: footerComp
|
2021-10-05 20:50:22 +00:00
|
|
|
|
2023-03-23 07:34:05 +00:00
|
|
|
displaced: Transition {
|
|
|
|
NumberAnimation { properties: "y"; duration: 250; easing.type: Easing.Linear; alwaysRunToEnd: true }
|
|
|
|
}
|
|
|
|
|
|
|
|
readonly property point lastVisibleItemPos: Qt.point(0, contentY + height - 1)
|
|
|
|
property int lastVisibleIndex: indexAt(lastVisibleItemPos.x, lastVisibleItemPos.y)
|
|
|
|
|
|
|
|
onCountChanged: {
|
|
|
|
const lastVisibleItem = itemAtIndex(lastVisibleIndex)
|
|
|
|
const newItem = itemAt(lastVisibleItemPos.x, lastVisibleItemPos.y)
|
|
|
|
const lastVisibleItemY = lastVisibleItem ? lastVisibleItem.y : -1
|
|
|
|
if (newItem) {
|
|
|
|
if (newItem.y < lastVisibleItemY) { // item inserted higher than last visible
|
|
|
|
lastVisibleIndex = indexAt(lastVisibleItemPos.x, lastVisibleItemPos.y)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
currentIndex: 0
|
|
|
|
|
|
|
|
property bool userScrolled: false
|
|
|
|
|
|
|
|
onMovingVerticallyChanged: {
|
|
|
|
if (!userScrolled) {
|
|
|
|
userScrolled = true
|
|
|
|
currentIndex = Qt.binding(() => lastVisibleIndex >= 0 ? lastVisibleIndex : (count - 1))
|
|
|
|
}
|
|
|
|
|
|
|
|
lastVisibleIndex = indexAt(lastVisibleItemPos.x, lastVisibleItemPos.y)
|
|
|
|
}
|
|
|
|
|
2022-09-01 15:34:27 +00:00
|
|
|
ScrollBar.vertical: StatusScrollBar {}
|
|
|
|
|
2023-03-23 07:34:05 +00:00
|
|
|
section.property: "date"
|
|
|
|
section.delegate: Item {
|
|
|
|
width: ListView.view.width
|
|
|
|
height: ListView.view.firstSection === section || section.length > 0 ? 40 : 0
|
|
|
|
visible: height > 0
|
2021-10-05 20:50:22 +00:00
|
|
|
|
2023-03-23 07:34:05 +00:00
|
|
|
required property string section
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
text: parent.section
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
font.pixelSize: 15
|
|
|
|
}
|
2021-10-05 20:50:22 +00:00
|
|
|
}
|
2023-03-23 07:34:05 +00:00
|
|
|
onAtYEndChanged: if (atYEnd && RootStore.historyTransactions.hasMore) fetchHistory()
|
2021-10-05 20:50:22 +00:00
|
|
|
}
|
|
|
|
|
2022-09-01 15:34:27 +00:00
|
|
|
Component {
|
|
|
|
id: transactionDelegate
|
|
|
|
TransactionDelegate {
|
2023-01-12 23:26:48 +00:00
|
|
|
property bool modelDataValid: !!modelData
|
2023-01-08 22:23:51 +00:00
|
|
|
isIncoming: modelDataValid ? modelData.to === account.address: false
|
2023-02-17 12:56:31 +00:00
|
|
|
currentCurrency: RootStore.currentCurrency
|
|
|
|
cryptoValue: modelDataValid ? modelData.value.amount : 0.0
|
|
|
|
fiatValue: modelDataValid ? RootStore.getFiatValue(cryptoValue, symbol, currentCurrency): 0.0
|
2023-01-08 22:23:51 +00:00
|
|
|
networkIcon: modelDataValid ? RootStore.getNetworkIcon(modelData.chainId) : ""
|
|
|
|
networkColor: modelDataValid ? RootStore.getNetworkColor(modelData.chainId) : ""
|
|
|
|
networkName: modelDataValid ? RootStore.getNetworkShortName(modelData.chainId) : ""
|
2023-01-12 23:26:48 +00:00
|
|
|
symbol: modelDataValid && !!modelData.symbol ? modelData.symbol : ""
|
2023-01-08 22:23:51 +00:00
|
|
|
transferStatus: modelDataValid ? RootStore.hex2Dec(modelData.txStatus) : ""
|
|
|
|
shortTimeStamp: modelDataValid ? LocaleUtils.formatTime(modelData.timestamp * 1000, Locale.ShortFormat) : ""
|
2023-02-28 17:15:22 +00:00
|
|
|
savedAddressNameTo: modelDataValid ? RootStore.getNameForSavedWalletAddress(modelData.to) : ""
|
|
|
|
savedAddressNameFrom: modelDataValid ? RootStore.getNameForSavedWalletAddress(modelData.from) : ""
|
|
|
|
isSummary: true
|
2022-09-05 09:15:47 +00:00
|
|
|
onClicked: launchTransactionDetail(modelData)
|
2023-01-12 23:26:48 +00:00
|
|
|
loading: modelDataValid ? modelData.loadingTransaction : false
|
2021-10-05 20:50:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-01 15:34:27 +00:00
|
|
|
Component {
|
2023-01-12 23:26:48 +00:00
|
|
|
id: footerComp
|
|
|
|
ColumnLayout {
|
|
|
|
width: root.width
|
|
|
|
visible: !RootStore.historyTransactions.hasMore && transactionListRoot.count !== 0
|
|
|
|
spacing: 12
|
|
|
|
Rectangle {
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
2023-02-28 14:54:10 +00:00
|
|
|
Layout.topMargin: Style.current.padding
|
2023-01-12 23:26:48 +00:00
|
|
|
Layout.preferredWidth: parent.width - 100
|
|
|
|
Layout.preferredHeight: 1
|
|
|
|
color: Theme.palette.directColor8
|
|
|
|
visible: !RootStore.historyTransactions.hasMore
|
|
|
|
}
|
|
|
|
StatusBaseText {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
text: qsTr("You have reached the beginning of the activity for this account")
|
|
|
|
font.pixelSize: 13
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
visible: !RootStore.historyTransactions.hasMore
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
}
|
|
|
|
StatusButton {
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
text: qsTr("Back to most recent transaction")
|
|
|
|
visible: !RootStore.historyTransactions.hasMore
|
|
|
|
onClicked: transactionListRoot.positionViewAtBeginning()
|
|
|
|
}
|
|
|
|
}
|
2022-09-01 15:34:27 +00:00
|
|
|
}
|
2021-10-05 20:50:22 +00:00
|
|
|
}
|