From a7e74f3e000705334ebe0177534e6d806d3c332f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Tinkl?= Date: Mon, 12 Aug 2024 12:41:27 +0200 Subject: [PATCH] chore(Global): Remove FeatureFlags access via Global singleton - rationale: do not save global state in a singleton, gather and propagate the values via FeatureFlagsStore Fixes #14697 --- storybook/stubs/nim/sectionmocks/FeatureFlags.qml | 10 ---------- ui/app/AppLayouts/Wallet/WalletLayout.qml | 7 +++++++ ui/app/AppLayouts/Wallet/panels/WalletFooter.qml | 4 +++- ui/app/AppLayouts/Wallet/panels/WalletHeader.qml | 9 ++++++--- .../AppLayouts/Wallet/views/RightTabBaseView.qml | 4 ++++ ui/app/AppLayouts/Wallet/views/RightTabView.qml | 2 +- ui/app/AppLayouts/stores/FeatureFlagsStore.qml | 7 +++++++ ui/app/AppLayouts/stores/qmldir | 1 + ui/app/mainui/AppMain.qml | 14 ++++++++++++-- ui/imports/utils/Global.qml | 3 --- 10 files changed, 41 insertions(+), 20 deletions(-) delete mode 100644 storybook/stubs/nim/sectionmocks/FeatureFlags.qml create mode 100644 ui/app/AppLayouts/stores/FeatureFlagsStore.qml diff --git a/storybook/stubs/nim/sectionmocks/FeatureFlags.qml b/storybook/stubs/nim/sectionmocks/FeatureFlags.qml deleted file mode 100644 index ca61597349..0000000000 --- a/storybook/stubs/nim/sectionmocks/FeatureFlags.qml +++ /dev/null @@ -1,10 +0,0 @@ -// Mock of src/app/global/feature_flags.nim -import QtQuick 2.15 - -QtObject { - readonly property string contextPropertyName: "featureFlagsRootContextProperty" - - // - // Silence warnings - readonly property bool dappsEnabled: true -} diff --git a/ui/app/AppLayouts/Wallet/WalletLayout.qml b/ui/app/AppLayouts/Wallet/WalletLayout.qml index 5672283622..1e86e90453 100644 --- a/ui/app/AppLayouts/Wallet/WalletLayout.qml +++ b/ui/app/AppLayouts/Wallet/WalletLayout.qml @@ -32,6 +32,9 @@ Item { property var networkConnectionStore property bool appMainVisible + property bool dappsEnabled + property bool swapEnabled + onAppMainVisibleChanged: { resetView() } @@ -215,6 +218,9 @@ Item { sendModal: root.sendModalPopup networkConnectionStore: root.networkConnectionStore + dappsEnabled: root.dappsEnabled + swapEnabled: root.swapEnabled + headerButton.text: RootStore.overview.ens || StatusQUtils.Utils.elideAndFormatWalletAddress(RootStore.overview.mixedcaseAddress) headerButton.visible: !RootStore.overview.isAllAccounts onLaunchShareAddressModal: Global.openShowQRPopup({ @@ -292,6 +298,7 @@ Item { height: visible ? 61: implicitHeight walletStore: RootStore transactionStore: root.transactionStore + swapEnabled: root.swapEnabled networkConnectionStore: root.networkConnectionStore isCommunityOwnershipTransfer: footer.isHoldingSelected && footer.isOwnerCommunityCollectible communityName: { diff --git a/ui/app/AppLayouts/Wallet/panels/WalletFooter.qml b/ui/app/AppLayouts/Wallet/panels/WalletFooter.qml index 0c87c89f64..1a597081be 100644 --- a/ui/app/AppLayouts/Wallet/panels/WalletFooter.qml +++ b/ui/app/AppLayouts/Wallet/panels/WalletFooter.qml @@ -25,6 +25,8 @@ Rectangle { property var networkConnectionStore required property TransactionStore transactionStore + property bool swapEnabled + // Community-token related properties: required property bool isCommunityOwnershipTransfer property string communityName: "" @@ -76,7 +78,7 @@ Rectangle { readonly property bool buyActionAvailable: !isCollectibleViewed - readonly property bool swapActionAvailable: Global.featureFlags.swapEnabled + readonly property bool swapActionAvailable: root.swapEnabled && !walletStore.overview.isWatchOnlyAccount && walletStore.overview.canSend && !d.isCollectibleViewed diff --git a/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml b/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml index c03d2f5cff..8fa1247788 100644 --- a/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml +++ b/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml @@ -1,5 +1,6 @@ -import QtQuick 2.13 -import QtQuick.Layouts 1.13 +import QtQuick 2.15 +import QtQuick.Controls 2.15 +import QtQuick.Layouts 1.15 import QtQml 2.15 import StatusQ 0.1 @@ -25,6 +26,8 @@ Item { property var store property var walletStore + property bool dappsEnabled + property alias headerButton: headerButton property alias networkFilter: networkFilter @@ -134,7 +137,7 @@ Item { spacing: 8 visible: !root.walletStore.showSavedAddresses - && Global.featureFlags.dappsEnabled + && root.dappsEnabled && Global.walletConnectService.isServiceAvailableForAddressSelection enabled: !!Global.walletConnectService diff --git a/ui/app/AppLayouts/Wallet/views/RightTabBaseView.qml b/ui/app/AppLayouts/Wallet/views/RightTabBaseView.qml index 98894876f5..539dab2f0e 100644 --- a/ui/app/AppLayouts/Wallet/views/RightTabBaseView.qml +++ b/ui/app/AppLayouts/Wallet/views/RightTabBaseView.qml @@ -14,6 +14,9 @@ FocusScope { property var communitiesStore property var networkConnectionStore + property bool dappsEnabled + property bool swapEnabled + property var sendModal property alias header: header @@ -33,6 +36,7 @@ FocusScope { store: root.store walletStore: RootStore networkConnectionStore: root.networkConnectionStore + dappsEnabled: root.dappsEnabled } Item { diff --git a/ui/app/AppLayouts/Wallet/views/RightTabView.qml b/ui/app/AppLayouts/Wallet/views/RightTabView.qml index 1bb929e18e..21e313cfff 100644 --- a/ui/app/AppLayouts/Wallet/views/RightTabView.qml +++ b/ui/app/AppLayouts/Wallet/views/RightTabView.qml @@ -219,7 +219,7 @@ RightTabBaseView { !RootStore.overview.isWatchOnlyAccount && RootStore.overview.canSend communitySendEnabled: RootStore.tokensStore.showCommunityAssetsInSend swapEnabled: !RootStore.overview.isWatchOnlyAccount - swapVisible: Global.featureFlags.swapEnabled + swapVisible: root.swapEnabled onSendRequested: { const modal = root.sendModal diff --git a/ui/app/AppLayouts/stores/FeatureFlagsStore.qml b/ui/app/AppLayouts/stores/FeatureFlagsStore.qml new file mode 100644 index 0000000000..f23f874528 --- /dev/null +++ b/ui/app/AppLayouts/stores/FeatureFlagsStore.qml @@ -0,0 +1,7 @@ +import QtQml 2.15 + +QtObject { + property bool connectorEnabled + property bool dappsEnabled + property bool swapEnabled +} diff --git a/ui/app/AppLayouts/stores/qmldir b/ui/app/AppLayouts/stores/qmldir index 4efbc79d9b..3b7da189e9 100644 --- a/ui/app/AppLayouts/stores/qmldir +++ b/ui/app/AppLayouts/stores/qmldir @@ -1 +1,2 @@ RootStore 1.0 RootStore.qml +FeatureFlagsStore 1.0 FeatureFlagsStore.qml diff --git a/ui/app/mainui/AppMain.qml b/ui/app/mainui/AppMain.qml index d2434bdeba..0e22bf0da1 100644 --- a/ui/app/mainui/AppMain.qml +++ b/ui/app/mainui/AppMain.qml @@ -79,6 +79,14 @@ Item { tokensStore: appMain.tokensStore currencyStore: appMain.currencyStore } + readonly property FeatureFlagsStore featureFlagsStore: FeatureFlagsStore { + readonly property var featureFlags: typeof featureFlagsRootContextProperty !== undefined ? featureFlagsRootContextProperty : null + + connectorEnabled: featureFlags ? featureFlags.connectorEnabled : false + dappsEnabled: featureFlags ? featureFlags.dappsEnabled : false + swapEnabled: featureFlags ? featureFlags.swapEnabled : false + } + required property bool isCentralizedMetricsEnabled // set from main.qml @@ -1379,6 +1387,8 @@ Item { sendModalPopup: sendModal networkConnectionStore: appMain.networkConnectionStore appMainVisible: appMain.visible + dappsEnabled: featureFlagsStore.dappsEnabled + swapEnabled: featureFlagsStore.swapEnabled } onLoaded: { item.resetView() @@ -2137,7 +2147,7 @@ Item { Loader { id: dappsConnectorSDKLoader - active: Global.featureFlags.connectorEnabled + active: featureFlagsStore.connectorEnabled sourceComponent: dappsConnectorSDK } @@ -2145,7 +2155,7 @@ Item { id: walletConnectServiceLoader // It seems some of the functionality of the dapp connector depends on the WalletConnectService - active: (Global.featureFlags.dappsEnabled || Global.featureFlags.connectorEnabled) && appMain.visible + active: (featureFlagsStore.dappsEnabled || featureFlagsStore.connectorEnabled) && appMain.visible sourceComponent: WalletConnectService { id: walletConnectService diff --git a/ui/imports/utils/Global.qml b/ui/imports/utils/Global.qml index e8b2ed52d7..822b350187 100644 --- a/ui/imports/utils/Global.qml +++ b/ui/imports/utils/Global.qml @@ -17,9 +17,6 @@ QtObject { // use the generic var as type to break the cyclic dependency property var walletConnectService: null - // avoid lookup of context property in QML - readonly property var featureFlags: featureFlagsRootContextProperty - signal openPinnedMessagesPopupRequested(var store, var messageStore, var pinnedMessagesModel, string messageToPin, string chatId) signal openCommunityProfilePopupRequested(var store, var community, var chatCommunitySectionModule)