Skip to content

Commit df3a72e

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

File tree

4 files changed

+590
-606
lines changed

4 files changed

+590
-606
lines changed

ui/app/AppLayouts/Browser/BrowserLayout.qml

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

1919
import AppLayouts.Browser.stores as BrowserStores
20+
import "provider"
2021

2122
import "popups"
2223
import "controls"
@@ -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: {
@@ -454,7 +453,7 @@ StatusSectionLayout {
454453
bookmarksStore: root.bookmarksStore
455454
downloadsStore: root.downloadsStore
456455
currentWebView: _internal.currentWebView
457-
webChannel: channel
456+
webChannel: connectorBridge.webChannel
458457
findBarComp: findBar
459458
favMenu: favoriteMenu
460459
addFavModal: addFavoriteModal
@@ -541,6 +540,11 @@ StatusSectionLayout {
541540
function onUrlChanged() {
542541
browserHeader.addressBar.text = root.browserRootStore.obtainAddress(_internal.currentWebView.url)
543542
root.browserRootStore.currentTabConnected = false // TODO: Will be handled by connector
543+
544+
// Update ConnectorBridge with current dApp metadata
545+
if (_internal.currentWebView && _internal.currentWebView.url) {
546+
connectorBridge.updateDAppUrl(_internal.currentWebView.url, _internal.currentWebView.title)
547+
}
544548
}
545549
}
546550

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import "Utils.js" as Utils
1010

1111
/**
1212
* ConnectorBridge
13-
*
13+
*
1414
* Simplified connector infrastructure for BrowserLayout.
15-
* Provides WebEngine profiles with script injection, WebChannel,
15+
* Provides WebEngine profiles with script injection, WebChannel,
1616
* ConnectorManager, and direct connection to Nim backend.
17-
*
17+
*
1818
* This component bridges the Browser UI with the Connector backend system.
1919
*/
2020
Item {
@@ -29,15 +29,15 @@ Item {
2929
readonly property alias webChannel: channel
3030
readonly property alias defaultProfile: defaultProfile
3131
readonly property alias otrProfile: otrProfile
32-
32+
3333
readonly property alias manager: connectorManager
34-
34+
3535
property alias dappUrl: connectorManager.dappUrl
3636
property alias dappOrigin: connectorManager.dappOrigin
3737
property alias dappName: connectorManager.dappName
3838
property alias dappIconUrl: connectorManager.dappIconUrl
3939
property alias clientId: connectorManager.clientId
40-
40+
4141
function hasWalletConnected(hostname, address) {
4242
if (!connectorController) return false
4343

@@ -59,10 +59,10 @@ Item {
5959
if (!connectorController) return false
6060
return connectorController.disconnect(hostname)
6161
}
62-
62+
6363
function updateDAppUrl(url, name) {
6464
if (!url) return
65-
65+
6666
const urlStr = url.toString()
6767
connectorManager.dappUrl = urlStr
6868
connectorManager.dappOrigin = urlStr
@@ -107,7 +107,7 @@ Item {
107107
ConnectorManager {
108108
id: connectorManager
109109
connectorController: root.connectorController // (shared_modules/connector/controller.nim)
110-
110+
111111
dappUrl: ""
112112
dappOrigin: ""
113113
dappName: ""
@@ -134,16 +134,14 @@ Item {
134134
Eip1193ProviderAdapter {
135135
id: eip1193ProviderAdapter
136136
WebChannel.id: "ethereumProvider"
137-
137+
138138
chainId: "0x" + connectorManager.dappChainId.toString(16) // Convert decimal to hex
139139
networkVersion: connectorManager.dappChainId.toString()
140140
selectedAddress: connectorManager.accounts.length > 0 ? connectorManager.accounts[0] : ""
141141
accounts: connectorManager.accounts
142142
connected: connectorManager.connected
143143

144-
function request(args) {
145-
return connectorManager.request(args)
146-
}
144+
onRequestInternal: (args) => connectorManager.request(args)
147145
}
148146
}
149147

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
}

0 commit comments

Comments
 (0)