Skip to content

Commit

Permalink
feat(WC): Enable Wallet Connect feature by default
Browse files Browse the repository at this point in the history
+ 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
  • Loading branch information
alexjba committed Nov 7, 2024
1 parent dbda82f commit 8efad11
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/app/global/feature_flags.nim
Original file line number Diff line number Diff line change
@@ -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
Expand Down
31 changes: 26 additions & 5 deletions storybook/pages/DAppsWorkflowPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}
}

Expand Down
30 changes: 30 additions & 0 deletions storybook/qmlTests/tests/tst_DappsComboBox.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
2 changes: 0 additions & 2 deletions ui/app/AppLayouts/Wallet/WalletLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Item {
property SharedStores.NetworkConnectionStore networkConnectionStore
property bool appMainVisible

property bool dappsEnabled
property bool swapEnabled

onAppMainVisibleChanged: {
Expand Down Expand Up @@ -228,7 +227,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)
Expand Down
7 changes: 7 additions & 0 deletions ui/app/AppLayouts/Wallet/controls/DappsComboBox.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,6 +89,7 @@ ComboBox {
id: dappConnectSelectComponent
StatusDialog {
id: dappConnectSelect
objectName: "dappConnectSelect"
width: 480
topPadding: Theme.bigPadding
leftPadding: Theme.padding
Expand All @@ -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"
Expand All @@ -130,6 +136,7 @@ ComboBox {
title: "Wallet Connect"
asset.name: Theme.svg("walletconnect")
asset.isImage: true
enabled: root.walletConnectEnabled
components: [
StatusIcon {
icon: "next"
Expand Down
5 changes: 3 additions & 2 deletions ui/app/AppLayouts/Wallet/panels/WalletHeader.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Item {
property var overview
property WalletStores.RootStore walletStore

property bool dappsEnabled
property int loginType // RootStore.loginType -> Constants.LoginType enum

property alias headerButton: headerButton
Expand Down Expand Up @@ -144,10 +143,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,10 +43,18 @@ QObject {
}

function revokeSession(topic) {
if (!enabled) {
return
}

d.revokeSession(topic)
}

function getActiveSession(topic) {
if (!enabled) {
return
}

return d.getActiveSession(topic)
}

Expand Down
15 changes: 15 additions & 0 deletions ui/app/AppLayouts/Wallet/services/dapps/DAppsListProvider.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -33,6 +46,8 @@ QObject {

property Connections sdkConnections: Connections {
target: root.sdk
enabled: root.enabled

function onSessionDelete(topic, err) {
d.updateDappsModel()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -77,7 +80,7 @@ QObject {
timeoutTimer.start()
requestHandler.pair(uri)
}

/// Approves or rejects the session proposal
function approvePairSession(key, approvedChainIds, accountAddress) {
requestHandler.approvePairSession(key, approvedChainIds, accountAddress)
Expand Down Expand Up @@ -292,13 +295,15 @@ QObject {

DAppsListProvider {
id: dappsProvider
enabled: root.walletConnectFeatureEnabled
sdk: root.wcSDK
store: root.store
supportedAccountsModel: root.walletRootStore.nonWatchAccounts
}

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
Expand Down
2 changes: 0 additions & 2 deletions ui/app/AppLayouts/Wallet/views/RightTabBaseView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ FocusScope {
property CommunitiesStore communitiesStore
property NetworkConnectionStore networkConnectionStore

property bool dappsEnabled
property bool swapEnabled

property var sendModal
Expand All @@ -40,7 +39,6 @@ FocusScope {
overview: WalletStores.RootStore.overview
walletStore: WalletStores.RootStore
networkConnectionStore: root.networkConnectionStore
dappsEnabled: root.dappsEnabled
loginType: root.store.loginType
}

Expand Down
4 changes: 3 additions & 1 deletion ui/app/mainui/AppMain.qml
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,6 @@ Item {
sendModalPopup: sendModal
networkConnectionStore: appMain.networkConnectionStore
appMainVisible: appMain.visible
dappsEnabled: featureFlagsStore.dappsEnabled
swapEnabled: featureFlagsStore.swapEnabled
}
onLoaded: {
Expand Down Expand Up @@ -2201,6 +2200,9 @@ Item {
walletRootStore: WalletStores.RootStore
blockchainNetworksDown: appMain.networkConnectionStore.blockchainNetworksDown

connectorFeatureEnabled: featureFlagsStore.connectorEnabled
walletConnectFeatureEnabled: featureFlagsStore.dappsEnabled

Component.onCompleted: {
Global.walletConnectService = walletConnectService
}
Expand Down

0 comments on commit 8efad11

Please sign in to comment.