From 1b3a4cf955cdfd911a921bc94839a236c26866e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Cie=C5=9Blak?= Date: Wed, 2 Oct 2024 09:50:10 +0200 Subject: [PATCH] stores: walletSection usages moved from shared/RootStore to wallet/RootStore --- .../AppLayouts/Wallet/panels/WalletHeader.qml | 2 +- ui/app/AppLayouts/Wallet/stores/RootStore.qml | 41 +++++++++++++++++++ .../Wallet/views/TransactionDetailView.qml | 4 +- ui/imports/shared/stores/RootStore.qml | 40 +----------------- ui/imports/shared/views/HistoryView.qml | 37 +++++++++-------- 5 files changed, 64 insertions(+), 60 deletions(-) diff --git a/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml b/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml index 27c3b0687c..092f3a3aa0 100644 --- a/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml +++ b/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml @@ -118,7 +118,7 @@ Item { RootStore.lastReloadTimestamp * 1000) : "" tooltip.text: qsTr("Last refreshed %1").arg(lastReloadTimeFormated) - onClicked: RootStore.walletSectionInst.reloadAccountTokens() + onClicked: RootStore.reloadAccountTokens() Timer { id: throttleTimer diff --git a/ui/app/AppLayouts/Wallet/stores/RootStore.qml b/ui/app/AppLayouts/Wallet/stores/RootStore.qml index 0e8cf81666..3c75b0a060 100644 --- a/ui/app/AppLayouts/Wallet/stores/RootStore.qml +++ b/ui/app/AppLayouts/Wallet/stores/RootStore.qml @@ -34,6 +34,8 @@ QtObject { readonly property string signingPhrase: walletSectionInst.signingPhrase readonly property string mnemonicBackedUp: walletSectionInst.isMnemonicBackedUp + readonly property var transactionActivityStatus: walletSectionInst.activityController.status + /* This property holds networks currently selected in the Wallet Main layout */ readonly property var networkFilters: networksModule.enabledChainIds readonly property var networkFiltersArray: networkFilters.split(":").filter(Boolean).map(Number) @@ -110,6 +112,11 @@ QtObject { readonly property bool isAccountTokensReloading: walletSectionInst.isAccountTokensReloading readonly property double lastReloadTimestamp: walletSectionInst.lastReloadTimestamp + readonly property var historyTransactions: walletSectionInst.activityController.model + readonly property bool loadingHistoryTransactions: walletSectionInst.activityController.status.loadingData + readonly property bool newDataAvailable: walletSectionInst.activityController.status.newDataAvailable + readonly property bool isNonArchivalNode: walletSectionInst.isNonArchivalNode + signal savedAddressAddedOrUpdated(added: bool, name: string, address: string, errorMsg: string) signal savedAddressDeleted(name: string, address: string, errorMsg: string) @@ -585,4 +592,38 @@ QtObject { } return undefined } + + function resetActivityData() { + root.walletSectionInst.activityController.resetActivityData() + } + + function updateTransactionFilterIfDirty() { + if (root.transactionActivityStatus.isFilterDirty) + root.walletSectionInst.activityController.updateFilter() + } + + function getTxDetails() { + return root.walletSectionInst.activityDetailsController.activityDetails + } + + function fetchTxDetails(txID) { + root.walletSectionInst.activityController.fetchTxDetails(txID) + root.walletSectionInst.activityDetailsController.fetchExtraTxDetails() + } + + function fetchDecodedTxData(txHash, input) { + root.walletSectionInst.fetchDecodedTxData(txHash, input) + } + + function fetchMoreTransactions() { + if (root.historyTransactions.count === 0 + || !root.historyTransactions.hasMore + || root.loadingHistoryTransactions) + return + root.walletSectionInst.activityController.loadMoreItems() + } + + function reloadAccountTokens() { + root.walletSectionInst.reloadAccountTokens() + } } diff --git a/ui/app/AppLayouts/Wallet/views/TransactionDetailView.qml b/ui/app/AppLayouts/Wallet/views/TransactionDetailView.qml index bc3aa3ed89..68c992e977 100644 --- a/ui/app/AppLayouts/Wallet/views/TransactionDetailView.qml +++ b/ui/app/AppLayouts/Wallet/views/TransactionDetailView.qml @@ -68,7 +68,7 @@ Item { onDetailsChanged: { if (!!d.details && !!d.details.input && d.details.input !== "0x") { d.loadingInputDate = true - root.rootStore.fetchDecodedTxData(d.details.txHashOut, d.details.input) + WalletStores.RootStore.fetchDecodedTxData(d.details.txHashOut, d.details.input) } } @@ -128,7 +128,7 @@ Item { } Connections { - target: root.rootStore.walletSectionInst + target: WalletStores.RootStore.walletSectionInst function onTxDecoded(txHash: string, dataDecoded: string) { if (!d.isTransactionValid || (d.isDetailsValid && txHash !== d.details.txHashOut)) return diff --git a/ui/imports/shared/stores/RootStore.qml b/ui/imports/shared/stores/RootStore.qml index a1f1f6be33..8626bfe213 100644 --- a/ui/imports/shared/stores/RootStore.qml +++ b/ui/imports/shared/stores/RootStore.qml @@ -11,7 +11,6 @@ QtObject { property var profileSectionModuleInst: profileSectionModule property var privacyModule: profileSectionModuleInst.privacyModule property var userProfileInst: !!Global.userProfile? Global.userProfile : null - property var walletSectionInst: Global.appIsReady && !!walletSection? walletSection : null property var appSettingsInst: Global.appIsReady && !!appSettings? appSettings : null property var accountSensitiveSettings: Global.appIsReady && !!localAccountSensitiveSettings? localAccountSensitiveSettings : null property real volume: !!appSettingsInst ? appSettingsInst.volume * 0.01 : 0.5 @@ -23,18 +22,7 @@ QtObject { property CurrenciesStore currencyStore: CurrenciesStore {} - readonly property var transactionActivityStatus: Global.appIsReady ? walletSectionInst.activityController.status : null - - property var historyTransactions: Global.appIsReady? walletSectionInst.activityController.model : null - readonly property bool loadingHistoryTransactions: Global.appIsReady && walletSectionInst.activityController.status.loadingData - readonly property bool newDataAvailable: Global.appIsReady && walletSectionInst.activityController.status.newDataAvailable - property bool isNonArchivalNode: Global.appIsReady && walletSectionInst.isNonArchivalNode - - property TokenMarketValuesStore marketValueStore: TokenMarketValuesStore{} - - function resetActivityData() { - walletSectionInst.activityController.resetActivityData() - } + property TokenMarketValuesStore marketValueStore: TokenMarketValuesStore {} property var flatNetworks: networksModule.flatNetworks @@ -49,30 +37,4 @@ QtObject { function getPasswordStrengthScore(password) { return root.privacyModule.getPasswordStrengthScore(password); } - - function fetchMoreTransactions() { - if (RootStore.historyTransactions.count === 0 - || !RootStore.historyTransactions.hasMore - || loadingHistoryTransactions) - return - walletSectionInst.activityController.loadMoreItems() - } - - function updateTransactionFilterIfDirty() { - if (transactionActivityStatus.isFilterDirty) - walletSectionInst.activityController.updateFilter() - } - - function fetchDecodedTxData(txHash, input) { - walletSectionInst.fetchDecodedTxData(txHash, input) - } - - function fetchTxDetails(txID) { - walletSectionInst.activityController.fetchTxDetails(txID) - walletSectionInst.activityDetailsController.fetchExtraTxDetails() - } - - function getTxDetails() { - return walletSectionInst.activityDetailsController.activityDetails - } } diff --git a/ui/imports/shared/views/HistoryView.qml b/ui/imports/shared/views/HistoryView.qml index 540520ed98..290228d8b0 100644 --- a/ui/imports/shared/views/HistoryView.qml +++ b/ui/imports/shared/views/HistoryView.qml @@ -57,7 +57,7 @@ ColumnLayout { } Component.onCompleted: { - if (RootStore.transactionActivityStatus.isFilterDirty) { + if (root.walletRootStore.transactionActivityStatus.isFilterDirty) { root.walletRootStore.currentActivityFiltersStore.applyAllFilters() } @@ -66,10 +66,10 @@ ColumnLayout { } Connections { - target: RootStore.transactionActivityStatus + target: root.walletRootStore.transactionActivityStatus enabled: root.visible function onIsFilterDirtyChanged() { - RootStore.updateTransactionFilterIfDirty() + root.walletRootStore.updateTransactionFilterIfDirty() } function onFilterChainsChanged() { root.walletRootStore.currentActivityFiltersStore.updateCollectiblesModel() @@ -89,7 +89,7 @@ ColumnLayout { QtObject { id: d - readonly property bool isInitialLoading: RootStore.loadingHistoryTransactions && transactionListRoot.count === 0 + readonly property bool isInitialLoading: root.walletRootStore.loadingHistoryTransactions && transactionListRoot.count === 0 readonly property int loadingSectionWidth: 56 @@ -101,7 +101,7 @@ ColumnLayout { function openTxDetails(txID) { // Prevent opening details when loading, that will invalidate the model data - if (RootStore.loadingHistoryTransactions) { + if (root.walletRootStore.loadingHistoryTransactions) { return false } @@ -148,7 +148,7 @@ ColumnLayout { Layout.fillWidth: true Layout.alignment: Qt.AlignTop Layout.topMargin: root.firstItemOffset - visible: RootStore.isNonArchivalNode + visible: root.walletRootStore.isNonArchivalNode text: qsTr("Status Desktop is connected to a non-archival node. Transaction history may be incomplete.") font.pixelSize: Style.current.primaryTextFontSize color: Style.current.danger @@ -204,7 +204,7 @@ ColumnLayout { if (d.openTxDetails(d.openTxDetailsHash)) { d.openTxDetailsHash = "" } else { - RootStore.fetchMoreTransactions() + root.walletRootStore.fetchMoreTransactions() } } } @@ -212,7 +212,7 @@ ColumnLayout { model: SortFilterProxyModel { id: txModel - sourceModel: RootStore.historyTransactions + sourceModel: root.walletRootStore.historyTransactions // LocaleUtils is not accessable from inside expression, but local function works property var daysTo: (d1, d2) => LocaleUtils.daysTo(d1, d2) @@ -267,16 +267,17 @@ ColumnLayout { } Connections { - target: RootStore + target: root.walletRootStore + function onLoadingHistoryTransactionsChanged() { // Calling timer instead directly to not cause binding loop - if (!RootStore.loadingHistoryTransactions) + if (!root.walletRootStore.loadingHistoryTransactions) fetchMoreTimer.start() } } function tryFetchMoreTransactions() { - if (d.isInitialLoading || !footerItem || !RootStore.historyTransactions.hasMore) + if (d.isInitialLoading || !footerItem || !root.walletRootStore.historyTransactions.hasMore) return const footerYPosition = footerItem.height / contentHeight if (footerYPosition >= 1.0) { @@ -285,7 +286,7 @@ ColumnLayout { // On startup, first loaded ListView will have heightRatio equal 0 if (footerYPosition + visibleArea.yPosition + visibleArea.heightRatio > 1.0) { - RootStore.fetchMoreTransactions() + root.walletRootStore.fetchMoreTransactions() } } @@ -304,8 +305,8 @@ ColumnLayout { text: qsTr("New transactions") - visible: RootStore.newDataAvailable && !RootStore.loadingHistoryTransactions - onClicked: RootStore.resetActivityData() + visible: root.walletRootStore.newDataAvailable && !root.walletRootStore.loadingHistoryTransactions + onClicked: root.walletRootStore.resetActivityData() icon.name: "arrow-up" @@ -389,8 +390,8 @@ ColumnLayout { root.walletRootStore.addressWasShown(delegateMenu.transaction.recipient) } - RootStore.fetchTxDetails(delegateMenu.transaction.id) - let detailsObj = RootStore.getTxDetails() + root.walletRootStore.fetchTxDetails(delegateMenu.transaction.id) + let detailsObj = root.walletRootStore.getTxDetails() let detailsString = delegateMenu.transactionDelegate.getDetailsString(detailsObj) ClipboardUtils.setText(detailsString) } @@ -516,7 +517,7 @@ ColumnLayout { id: footerComp ColumnLayout { id: footerColumn - readonly property bool allActivityLoaded: !RootStore.historyTransactions.hasMore && transactionListRoot.count !== 0 + readonly property bool allActivityLoaded: !root.walletRootStore.historyTransactions.hasMore && transactionListRoot.count !== 0 width: root.width spacing: d.isInitialLoading ? 6 : 12 @@ -544,7 +545,7 @@ ColumnLayout { const delegateHeight = 64 + footerColumn.spacing if (d.isInitialLoading) { return Math.floor(transactionListRoot.height / delegateHeight) - } else if (RootStore.historyTransactions.hasMore) { + } else if (root.walletRootStore.historyTransactions.hasMore) { return Math.max(3, Math.floor(transactionListRoot.height / delegateHeight) - 3) } }