From 7e1e82714835353b50874c718c0de7f52cf4fa32 Mon Sep 17 00:00:00 2001 From: Alex Jbanca Date: Fri, 25 Oct 2024 22:28:45 +0300 Subject: [PATCH] feat(WC): Enable Wallet Connect feature by default + Update the dialog where the user choses the connection to enable or disable the connection option based on flags + Separating the walletConnect flag and browserConnect flag usage so that either one can be disabled without affecting the other feature + Update qml test --- src/app/global/feature_flags.nim | 2 +- storybook/pages/DAppsWorkflowPage.qml | 31 ++++++++++++++++--- .../qmlTests/tests/tst_DappsComboBox.qml | 30 ++++++++++++++++++ ui/app/AppLayouts/Wallet/WalletLayout.qml | 2 -- .../Wallet/controls/DappsComboBox.qml | 7 +++++ .../AppLayouts/Wallet/panels/WalletHeader.qml | 6 ++-- .../dapps/ConnectorDAppsListProvider.qml | 13 ++++++++ .../services/dapps/DAppsListProvider.qml | 15 +++++++++ .../services/dapps/WalletConnectService.qml | 7 ++++- .../Wallet/views/RightTabBaseView.qml | 2 -- ui/app/mainui/AppMain.qml | 4 ++- 11 files changed, 104 insertions(+), 15 deletions(-) diff --git a/src/app/global/feature_flags.nim b/src/app/global/feature_flags.nim index 40cf2bffec..5c7740817c 100644 --- a/src/app/global/feature_flags.nim +++ b/src/app/global/feature_flags.nim @@ -1,7 +1,7 @@ import NimQml import os -const DEFAULT_FLAG_DAPPS_ENABLED = false +const DEFAULT_FLAG_DAPPS_ENABLED = true const DEFAULT_FLAG_SWAP_ENABLED = true const DEFAULT_FLAG_CONNECTOR_ENABLED* = false const DEFAULT_FLAG_SEND_VIA_PERSONAL_CHAT_ENABLED = true diff --git a/storybook/pages/DAppsWorkflowPage.qml b/storybook/pages/DAppsWorkflowPage.qml index 56ae94df02..3bb9a8802d 100644 --- a/storybook/pages/DAppsWorkflowPage.qml +++ b/storybook/pages/DAppsWorkflowPage.qml @@ -74,6 +74,9 @@ Item { sessionRequestsModel: wcService.sessionRequestsModel enabled: wcService.isServiceOnline + walletConnectEnabled: wcService.walletConnectFeatureEnabled + connectorEnabled: wcService.connectorFeatureEnabled + //formatBigNumber: (number, symbol, noSymbolOption) => wcService.walletRootStore.currencyStore.formatBigNumber(number, symbol, noSymbolOption) onDisconnectRequested: (connectionId) => wcService.disconnectDapp(connectionId) @@ -211,12 +214,30 @@ Item { // spacer ColumnLayout {} - CheckBox { + RowLayout { + CheckBox { - text: "Enable SDK" - checked: settings.enableSDK - onCheckedChanged: { - settings.enableSDK = checked + text: "Enable SDK" + checked: settings.enableSDK + onCheckedChanged: { + settings.enableSDK = checked + } + } + + CheckBox { + text: "WC feature flag" + checked: true + onCheckedChanged: { + walletConnectService.walletConnectFeatureEnabled = checked + } + } + + CheckBox { + text: "Connector feature flag" + checked: true + onCheckedChanged: { + walletConnectService.connectorFeatureEnabled = checked + } } } diff --git a/storybook/qmlTests/tests/tst_DappsComboBox.qml b/storybook/qmlTests/tests/tst_DappsComboBox.qml index 2daec2ea70..f18b8d8fcf 100644 --- a/storybook/qmlTests/tests/tst_DappsComboBox.qml +++ b/storybook/qmlTests/tests/tst_DappsComboBox.qml @@ -96,5 +96,35 @@ Item { compare(background.active, false) compare(dappTooltip.visible, false) } + + function test_connectorsEnabledOrDisabled() { + mouseClick(controlUnderTest) + const dappListPopup = findChild(controlUnderTest, "dappsListPopup") + verify(!!dappListPopup) + + dappListPopup.connectDapp() + waitForRendering(controlUnderTest) + waitForItemPolished(controlUnderTest) + + const connectorButton = findChild(controlUnderTest, "btnStatusConnector") + const wcButton = findChild(controlUnderTest, "btnWalletConnect") + verify(!!connectorButton) + verify(!!wcButton) + + compare(controlUnderTest.walletConnectEnabled, true) + compare(controlUnderTest.connectorEnabled, true) + + controlUnderTest.walletConnectEnabled = false + compare(wcButton.enabled, false) + + controlUnderTest.walletConnectEnabled = true + compare(wcButton.enabled, true) + + controlUnderTest.connectorEnabled = false + compare(connectorButton.enabled, false) + + controlUnderTest.connectorEnabled = true + compare(connectorButton.enabled, true) + } } } diff --git a/ui/app/AppLayouts/Wallet/WalletLayout.qml b/ui/app/AppLayouts/Wallet/WalletLayout.qml index d5496c4d61..3754e604e6 100644 --- a/ui/app/AppLayouts/Wallet/WalletLayout.qml +++ b/ui/app/AppLayouts/Wallet/WalletLayout.qml @@ -41,7 +41,6 @@ Item { property SharedStores.NetworkConnectionStore networkConnectionStore property bool appMainVisible - property bool dappsEnabled property bool swapEnabled onAppMainVisibleChanged: { @@ -224,7 +223,6 @@ Item { sendModal: root.sendModalPopup networkConnectionStore: root.networkConnectionStore - dappsEnabled: root.dappsEnabled swapEnabled: root.swapEnabled headerButton.text: RootStore.overview.ens || StatusQUtils.Utils.elideAndFormatWalletAddress(RootStore.overview.mixedcaseAddress) diff --git a/ui/app/AppLayouts/Wallet/controls/DappsComboBox.qml b/ui/app/AppLayouts/Wallet/controls/DappsComboBox.qml index e808883247..6305664787 100644 --- a/ui/app/AppLayouts/Wallet/controls/DappsComboBox.qml +++ b/ui/app/AppLayouts/Wallet/controls/DappsComboBox.qml @@ -17,6 +17,9 @@ import StatusQ.Components.private 0.1 as SQP ComboBox { id: root + + property bool walletConnectEnabled: true + property bool connectorEnabled: true signal dappsListReady signal pairDapp @@ -86,6 +89,7 @@ ComboBox { id: dappConnectSelectComponent StatusDialog { id: dappConnectSelect + objectName: "dappConnectSelect" width: 480 topPadding: Theme.bigPadding leftPadding: Theme.padding @@ -111,9 +115,11 @@ ComboBox { text: qsTr("How would you like to connect?") } StatusListItem { + objectName: "btnStatusConnector" title: "Status Connector" asset.name: Theme.png("status-logo") asset.isImage: true + enabled: root.connectorEnabled components: [ StatusIcon { icon: "external-link" @@ -130,6 +136,7 @@ ComboBox { title: "Wallet Connect" asset.name: Theme.svg("walletconnect") asset.isImage: true + enabled: root.walletConnectEnabled components: [ StatusIcon { icon: "next" diff --git a/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml b/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml index 147e701427..2aa3dba800 100644 --- a/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml +++ b/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml @@ -29,8 +29,6 @@ Item { property WalletStores.RootStore walletStore property var overview - - property bool dappsEnabled property int loginType // RootStore.loginType -> Constants.LoginType enum property alias headerButton: headerButton @@ -144,10 +142,12 @@ Item { spacing: 8 visible: !root.walletStore.showSavedAddresses - && root.dappsEnabled + && (wcService.walletConnectFeatureEnabled || wcService.connectorFeatureEnabled) && wcService.serviceAvailableToCurrentAddress enabled: !!wcService && wcService.isServiceOnline + walletConnectEnabled: wcService.walletConnectFeatureEnabled + connectorEnabled: wcService.connectorFeatureEnabled loginType: root.loginType selectedAccountAddress: root.walletStore.selectedAddress diff --git a/ui/app/AppLayouts/Wallet/services/dapps/ConnectorDAppsListProvider.qml b/ui/app/AppLayouts/Wallet/services/dapps/ConnectorDAppsListProvider.qml index 438083506f..59a00cc445 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/ConnectorDAppsListProvider.qml +++ b/ui/app/AppLayouts/Wallet/services/dapps/ConnectorDAppsListProvider.qml @@ -11,8 +11,13 @@ QObject { readonly property alias dappsModel: d.dappsModel readonly property int connectorId: Constants.StatusConnect + property bool enabled: true function addSession(url, name, iconUrl, accountAddress) { + if (!enabled) { + return + } + if (!url || !name || !iconUrl || !accountAddress) { console.error("addSession: missing required parameters") return @@ -38,10 +43,18 @@ QObject { } function revokeSession(topic) { + if (!enabled) { + return + } + d.revokeSession(topic) } function getActiveSession(topic) { + if (!enabled) { + return + } + return d.getActiveSession(topic) } diff --git a/ui/app/AppLayouts/Wallet/services/dapps/DAppsListProvider.qml b/ui/app/AppLayouts/Wallet/services/dapps/DAppsListProvider.qml index a1ab1704ca..90cce12d2e 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/DAppsListProvider.qml +++ b/ui/app/AppLayouts/Wallet/services/dapps/DAppsListProvider.qml @@ -18,11 +18,24 @@ QObject { readonly property int connectorId: Constants.WalletConnect readonly property var dappsModel: d.dappsModel + property bool enabled: true + Component.onCompleted: { + if (!enabled) { + return + } // Just in case the SDK is already initialized d.updateDappsModel() } + onEnabledChanged: { + if (enabled) { + d.updateDappsModel() + } else { + d.dappsModel.clear() + } + } + QObject { id: d @@ -33,6 +46,8 @@ QObject { property Connections sdkConnections: Connections { target: root.sdk + enabled: root.enabled + function onSessionDelete(topic, err) { d.updateDappsModel() } diff --git a/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectService.qml b/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectService.qml index 32342c3804..fb2619c37b 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectService.qml +++ b/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectService.qml @@ -35,6 +35,9 @@ QObject { // // Array[chainId] of the networks that are down required property var blockchainNetworksDown + property bool walletConnectFeatureEnabled: true + property bool connectorFeatureEnabled: true + //output properties /// Model contaning all dApps available for the currently selected account readonly property var dappsModel: d.filteredDappsModel @@ -81,7 +84,7 @@ QObject { timeoutTimer.start() requestHandler.pair(uri) } - + /// Approves or rejects the session proposal function approvePairSession(key, approvedChainIds, accountAddress) { requestHandler.approvePairSession(key, approvedChainIds, accountAddress) @@ -296,6 +299,7 @@ QObject { DAppsListProvider { id: dappsProvider + enabled: root.walletConnectFeatureEnabled sdk: root.wcSDK store: root.store supportedAccountsModel: root.walletRootStore.nonWatchAccounts @@ -303,6 +307,7 @@ QObject { ConnectorDAppsListProvider { id: connectorDAppsProvider + enabled: root.connectorFeatureEnabled } // Timeout for the corner case where the URL was already dismissed and the SDK doesn't respond with an error nor advances with the proposal diff --git a/ui/app/AppLayouts/Wallet/views/RightTabBaseView.qml b/ui/app/AppLayouts/Wallet/views/RightTabBaseView.qml index 01f4882e89..27427a7361 100644 --- a/ui/app/AppLayouts/Wallet/views/RightTabBaseView.qml +++ b/ui/app/AppLayouts/Wallet/views/RightTabBaseView.qml @@ -19,7 +19,6 @@ FocusScope { property CommunitiesStore communitiesStore property NetworkConnectionStore networkConnectionStore - property bool dappsEnabled property bool swapEnabled property var sendModal @@ -40,7 +39,6 @@ FocusScope { overview: WalletStores.RootStore.overview walletStore: WalletStores.RootStore networkConnectionStore: root.networkConnectionStore - dappsEnabled: root.dappsEnabled loginType: root.store.loginType } diff --git a/ui/app/mainui/AppMain.qml b/ui/app/mainui/AppMain.qml index 16e0ef8c6c..3575c4c0a3 100644 --- a/ui/app/mainui/AppMain.qml +++ b/ui/app/mainui/AppMain.qml @@ -1434,7 +1434,6 @@ Item { sendModalPopup: sendModal networkConnectionStore: appMain.networkConnectionStore appMainVisible: appMain.visible - dappsEnabled: featureFlagsStore.dappsEnabled swapEnabled: featureFlagsStore.swapEnabled } onLoaded: { @@ -2214,6 +2213,9 @@ Item { walletRootStore: WalletStores.RootStore blockchainNetworksDown: appMain.networkConnectionStore.blockchainNetworksDown + connectorFeatureEnabled: featureFlagsStore.connectorEnabled + walletConnectFeatureEnabled: featureFlagsStore.dappsEnabled + Component.onCompleted: { Global.walletConnectService = walletConnectService }