Skip to content

Commit 6853960

Browse files
committed
feat(dapp-browser-ens)_: integrate browserBridge to BrowserLayout
fixes #19141
1 parent 5d3b34d commit 6853960

File tree

8 files changed

+613
-624
lines changed

8 files changed

+613
-624
lines changed

ui/StatusQ/src/StatusQ/Core/Utils/SubscriptionBroker.qml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ QtObject {
126126
}
127127
}
128128

129+
const onDestructionHandler = () => {
130+
if(!d.managedSubscriptions.hasOwnProperty(subscriptionId))
131+
return
132+
133+
root.unsubscribed.disconnect(onUnsubscribedHandler) //object is destroyed, no need to listen to the signal anymore
134+
unsubscribe(subscriptionId)
135+
}
136+
129137
const onUnsubscribedHandler = (subscriptionId) => {
130138
if(subscriptionId !== subscription.subscriptionId)
131139
return
@@ -135,14 +143,6 @@ QtObject {
135143
subscription.topicChanged.disconnect(onTopicChangeHandler)
136144
}
137145

138-
const onDestructionHandler = () => {
139-
if(!d.managedSubscriptions.hasOwnProperty(subscriptionId))
140-
return
141-
142-
root.unsubscribed.disconnect(onUnsubscribedHandler) //object is destroyed, no need to listen to the signal anymore
143-
unsubscribe(subscriptionId)
144-
}
145-
146146
subscription.Component.onDestruction.connect(onDestructionHandler)
147147
subscription.isReadyChanged.connect(onReadyChangeHandler)
148148
subscription.topicChanged.connect(onTopicChangeHandler)

ui/StatusQ/src/StatusQ/Core/Utils/SubscriptionBrokerCommunities.qml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ QtObject {
116116
}
117117
}
118118

119+
const onDestructionHandler = () => {
120+
if(!d.managedSubscriptions.hasOwnProperty(subscriptionId))
121+
return
122+
123+
root.unsubscribed.disconnect(onUnsubscribedHandler) //object is destroyed, no need to listen to the signal anymore
124+
unsubscribe(subscriptionId)
125+
}
126+
119127
const onUnsubscribedHandler = (subscriptionId) => {
120128
if(subscriptionId !== subscription.subscriptionId)
121129
return
@@ -125,14 +133,6 @@ QtObject {
125133
subscription.topicChanged.disconnect(onTopicChangeHandler)
126134
}
127135

128-
const onDestructionHandler = () => {
129-
if(!d.managedSubscriptions.hasOwnProperty(subscriptionId))
130-
return
131-
132-
root.unsubscribed.disconnect(onUnsubscribedHandler) //object is destroyed, no need to listen to the signal anymore
133-
unsubscribe(subscriptionId)
134-
}
135-
136136
subscription.Component.onDestruction.connect(onDestructionHandler)
137137
subscription.isReadyChanged.connect(onReadyChangeHandler)
138138
subscription.topicChanged.connect(onTopicChangeHandler)

ui/app/AppLayouts/Browser/BrowserLayout.qml

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import shared.stores.send
1818

1919
import AppLayouts.Browser.stores as BrowserStores
2020

21+
import "provider/qml"
2122
import "popups"
2223
import "controls"
2324
import "views"
@@ -41,6 +42,7 @@ StatusSectionLayout {
4142
required property BrowserStores.DownloadsStore downloadsStore
4243
required property BrowserStores.BrowserRootStore browserRootStore
4344
required property BrowserStores.BrowserWalletStore browserWalletStore
45+
required property var connectorController
4446

4547
signal sendToRecipientRequested(string address)
4648

@@ -49,6 +51,22 @@ StatusSectionLayout {
4951
tab.url = _internal.determineRealURL(url)
5052
}
5153

54+
ConnectorBridge {
55+
id: connectorBridge
56+
57+
userUID: root.userUID
58+
connectorController: root.connectorController
59+
defaultAccountAddress: root.browserWalletStore.dappBrowserAccount.address
60+
accountsModel: root.browserWalletStore.accounts
61+
httpUserAgent: {
62+
if (localAccountSensitiveSettings.compatibilityMode) {
63+
// Google doesn't let you connect if the user agent is Chrome-ish and doesn't satisfy some sort of hidden requirement
64+
return "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36"
65+
}
66+
return ""
67+
}
68+
}
69+
5270
QtObject {
5371
id: _internal
5472

@@ -91,32 +109,13 @@ StatusSectionLayout {
91109
standardButtons: Dialog.Ok
92110
}
93111

94-
property QtObject defaultProfile: WebEngineProfile {
95-
storageName: "Profile_%1".arg(root.userUID)
96-
offTheRecord: false
97-
httpUserAgent: {
98-
if (localAccountSensitiveSettings.compatibilityMode) {
99-
// Google doesn't let you connect if the user agent is Chrome-ish and doesn't satisfy some sort of hidden requirement
100-
return "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36"
101-
}
102-
return ""
103-
}
104-
}
105-
106-
property QtObject otrProfile: WebEngineProfile {
107-
storageName: "IncognitoProfile_%1".arg(root.userUID)
108-
offTheRecord: true
109-
persistentCookiesPolicy: WebEngineProfile.NoPersistentCookies
110-
httpUserAgent: _internal.defaultProfile.httpUserAgent
111-
}
112-
113112
function addNewDownloadTab() {
114-
tabs.createDownloadTab(tabs.count !== 0 ? currentWebView.profile : defaultProfile);
113+
tabs.createDownloadTab(tabs.count !== 0 ? currentWebView.profile : connectorBridge.defaultProfile);
115114
tabs.currentIndex = tabs.count - 1;
116115
}
117116

118117
function addNewTab() {
119-
var tab = tabs.createEmptyTab(tabs.count !== 0 ? currentWebView.profile : defaultProfile);
118+
var tab = tabs.createEmptyTab(tabs.count !== 0 ? currentWebView.profile : connectorBridge.defaultProfile);
120119
browserHeader.addressBar.forceActiveFocus();
121120
browserHeader.addressBar.selectAll();
122121

@@ -218,9 +217,9 @@ StatusSectionLayout {
218217
}
219218
onOpenNewTabTriggered: _internal.addNewTab()
220219
Component.onCompleted: {
221-
_internal.defaultProfile.downloadRequested.connect(_internal.onDownloadRequested);
222-
_internal.otrProfile.downloadRequested.connect(_internal.onDownloadRequested);
223-
var tab = createEmptyTab(_internal.defaultProfile, true);
220+
connectorBridge.defaultProfile.downloadRequested.connect(_internal.onDownloadRequested);
221+
connectorBridge.otrProfile.downloadRequested.connect(_internal.onDownloadRequested);
222+
var tab = createEmptyTab(connectorBridge.defaultProfile, true);
224223
// For Devs: Uncomment the next line if you want to use the simpledapp on first load
225224
// tab.url = root.browserRootStore.determineRealURL("https://simpledapp.eth");
226225
}
@@ -312,11 +311,11 @@ StatusSectionLayout {
312311
id: settingsMenu
313312
x: parent.width - width
314313
y: browserHeader.y + browserHeader.height
315-
isIncognito: _internal.currentWebView && _internal.currentWebView.profile === _internal.otrProfile
314+
isIncognito: _internal.currentWebView && _internal.currentWebView.profile === connectorBridge.otrProfile
316315
onAddNewTab: _internal.addNewTab()
317316
onGoIncognito: function (checked) {
318317
if (_internal.currentWebView) {
319-
_internal.currentWebView.profile = checked ? _internal.otrProfile : _internal.defaultProfile;
318+
_internal.currentWebView.profile = checked ? connectorBridge.otrProfile : connectorBridge.defaultProfile;
320319
}
321320
}
322321
onZoomIn: {
@@ -455,7 +454,7 @@ StatusSectionLayout {
455454
bookmarksStore: root.bookmarksStore
456455
downloadsStore: root.downloadsStore
457456
currentWebView: _internal.currentWebView
458-
webChannel: channel
457+
webChannel: connectorBridge.webChannel
459458
findBarComp: findBar
460459
favMenu: favoriteMenu
461460
addFavModal: addFavoriteModal
@@ -542,6 +541,11 @@ StatusSectionLayout {
542541
function onUrlChanged() {
543542
browserHeader.addressBar.text = root.browserRootStore.obtainAddress(_internal.currentWebView.url)
544543
root.browserRootStore.currentTabConnected = false // TODO: Will be handled by connector
544+
545+
// Update ConnectorBridge with current dApp metadata
546+
if (_internal.currentWebView && _internal.currentWebView.url) {
547+
connectorBridge.updateDAppUrl(_internal.currentWebView.url, _internal.currentWebView.title)
548+
}
545549
}
546550
}
547551

ui/app/AppLayouts/Browser/provider/qml/ConnectorBridge.qml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ import QtWebChannel
55

66
import StatusQ.Core.Theme
77
import utils
8-
98
import "Utils.js" as Utils
109

1110
/**
1211
* ConnectorBridge
13-
*
12+
*
1413
* Simplified connector infrastructure for BrowserLayout.
15-
* Provides WebEngine profiles with script injection, WebChannel,
14+
* Provides WebEngine profiles with script injection, WebChannel,
1615
* ConnectorManager, and direct connection to Nim backend.
17-
*
16+
*
1817
* This component bridges the Browser UI with the Connector backend system.
1918
*/
2019
Item {
@@ -29,15 +28,15 @@ Item {
2928
readonly property alias webChannel: channel
3029
readonly property alias defaultProfile: defaultProfile
3130
readonly property alias otrProfile: otrProfile
32-
31+
3332
readonly property alias manager: connectorManager
34-
33+
3534
property alias dappUrl: connectorManager.dappUrl
3635
property alias dappOrigin: connectorManager.dappOrigin
3736
property alias dappName: connectorManager.dappName
3837
property alias dappIconUrl: connectorManager.dappIconUrl
3938
property alias clientId: connectorManager.clientId
40-
39+
4140
function hasWalletConnected(hostname, address) {
4241
if (!connectorController) return false
4342

@@ -59,10 +58,10 @@ Item {
5958
if (!connectorController) return false
6059
return connectorController.disconnect(hostname)
6160
}
62-
61+
6362
function updateDAppUrl(url, name) {
6463
if (!url) return
65-
64+
6665
const urlStr = url.toString()
6766
connectorManager.dappUrl = urlStr
6867
connectorManager.dappOrigin = Utils.normalizeOrigin(urlStr)
@@ -107,7 +106,7 @@ Item {
107106
ConnectorManager {
108107
id: connectorManager
109108
connectorController: root.connectorController // (shared_modules/connector/controller.nim)
110-
109+
111110
dappUrl: ""
112111
dappOrigin: ""
113112
dappName: ""
@@ -134,16 +133,14 @@ Item {
134133
Eip1193ProviderAdapter {
135134
id: eip1193ProviderAdapter
136135
WebChannel.id: "ethereumProvider"
137-
136+
138137
chainId: "0x" + connectorManager.dappChainId.toString(16) // Convert decimal to hex
139138
networkVersion: connectorManager.dappChainId.toString()
140139
selectedAddress: connectorManager.accounts.length > 0 ? connectorManager.accounts[0] : ""
141140
accounts: connectorManager.accounts
142141
connected: connectorManager.connected
143142

144-
function request(args) {
145-
return connectorManager.request(args)
146-
}
143+
onRequestInternal: (args) => connectorManager.request(args)
147144
}
148145
}
149146

ui/app/AppLayouts/Browser/provider/qml/Eip1193ProviderAdapter.qml

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,32 @@ import QtQuick 2.15
22

33
QtObject {
44
id: root
5-
6-
// ============================================================================
7-
// EIP-1193 PUBLIC PROPERTIES (exposed to JS via WebChannel)
8-
// ============================================================================
5+
6+
// EIP-1193 PUBLIC PROPERTIES
97
readonly property bool isStatus: true
108
readonly property bool isMetaMask: false
119
property string chainId: "0x1" // hex format for EIP-1193
1210
property string networkVersion: "1" // decimal format (deprecated but used by some dApps)
1311
property string selectedAddress: "" // current active address
1412
property var accounts: []
1513
property bool connected: false
16-
17-
// ============================================================================
14+
1815
// EIP-1193 EVENTS (for WebChannel)
19-
// ============================================================================
20-
2116
signal connectEvent(var info)
2217
signal disconnectEvent(var error)
2318
signal accountsChangedEvent(var accounts)
2419
signal chainChangedEvent(string chainId)
2520
signal messageEvent(var message)
2621
signal requestCompletedEvent(var payload)
22+
signal requestInternal(var args)
2723

2824
// Internal
2925
signal providerStateChanged() // re-read State
30-
31-
// ============================================================================
26+
3227
// EIP-1193 REQUEST METHOD STUB
33-
// ============================================================================
3428
function request(args) {
35-
console.error("[Eip1193ProviderAdapter] request() not injected - should be overridden by ConnectorBridge")
36-
return JSON.stringify({
37-
jsonrpc: "2.0",
38-
id: args && args.requestId || 0,
39-
error: { code: -32603, message: "Request function not properly injected" }
40-
})
29+
requestInternal(args)
30+
// Return immediately - async response comes via requestCompletedEvent
31+
return { jsonrpc: "2.0", id: args.requestId || 0, result: null }
4132
}
4233
}

ui/app/AppLayouts/Browser/provider/qml/Utils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.pragma library
2+
13
function accountsDidChange(oldAccounts, newAccounts) {
24
const a = oldAccounts || []
35
const b = newAccounts || []
@@ -55,6 +57,6 @@ function extractDomainName(urlString) {
5557
return urlObj.hostname || "Unknown dApp"
5658
} catch (e) {
5759
return "Unknown dApp"
58-
}
60+
}
5961
}
6062

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ConnectorBridge 1.0 ConnectorBridge.qml
2+
ConnectorManager 1.0 ConnectorManager.qml
3+
Eip1193ProviderAdapter 1.0 Eip1193ProviderAdapter.qml
4+

0 commit comments

Comments
 (0)