@@ -32,30 +32,30 @@ Item {
3232 signal messageEvent (var message)
3333 signal requestCompletedEvent (var payload)
3434
35- // PUBLIC API - EIP-1193 REQUEST
36- function request (args ) {
37- if (! args || ! args .method ) {
38- console .error (" [ConnectorManager] Invalid request" )
39- return JSON .stringify ({
40- error: { code: - 32600 , message: " Missing method" }
41- })
42- }
43-
44- const method = args .method
45- const requestId = args .requestId || 0
46-
47- var rpcRequest = {
48- " jsonrpc" : " 2.0" ,
49- " id" : requestId,
50- " method" : method,
51- " params" : args .params || [],
52- " url" : dappOrigin || dappUrl || " " ,
53- " name" : dappName || " Unknown dApp" ,
54- " clientId" : clientId,
55- " chainId" : dappChainId,
56- " iconUrl" : dappIconUrl || " "
57- }
58-
35+ // PUBLIC API - EIP-1193 REQUEST
36+ function request (args ) {
37+ if (! args || ! args .method ) {
38+ console .error (" [ConnectorManager] Invalid request - missing method " )
39+ return JSON .stringify ({
40+ error: { code: - 32600 , message: " Missing method" } // EIP-1193: Invalid Request
41+ })
42+ }
43+
44+ const method = args .method
45+ const requestId = args .requestId || 0
46+
47+ var rpcRequest = {
48+ " jsonrpc" : " 2.0" ,
49+ " id" : requestId,
50+ " method" : method,
51+ " params" : args .params || [],
52+ " url" : dappOrigin || " " ,
53+ " name" : dappName || " Unknown dApp" ,
54+ " clientId" : clientId,
55+ " chainId" : dappChainId,
56+ " iconUrl" : dappIconUrl || " "
57+ }
58+
5959 // Direct call to Nim connectorCallRPC -> status-go connector/api.go
6060 if (connectorController) {
6161 connectorController .connectorCallRPC (requestId, JSON .stringify (rpcRequest))
@@ -81,13 +81,13 @@ Item {
8181 _hasPermission = newAccounts .length > 0
8282
8383 providerStateChanged ()
84- accountsChangedEvent (accounts)
84+ accuntsChangedEvent (accounts)
8585 console .log (" [ConnectorManager] Accounts updated:" , JSON .stringify (accounts))
86- return true
87- }
88-
89- function setConnected (isConnected ) {
90- if (connected === isConnected) {
86+ return true
87+ }
88+
89+ function setConnected (isConnected ) {
90+ if (connected === isConnected) {
9191 return false
9292 }
9393
@@ -118,27 +118,29 @@ Item {
118118 _initialConnectionDone = false
119119
120120 providerStateChanged ()
121- disconnectEvent ({ code: 4900 , message: " User disconnected" }) // EIP-1193: Disconnected
122- accountsChangedEvent ([])
123- console .log (" [ConnectorManager] State cleared" )
124- return true
125- }
126-
127- // PUBLIC API
128- function disconnect () {
129- console .log (" [ConnectorManager] Disconnecting dApp" )
130-
131- clearState ()
132-
133- if (connectorController) {
134- const effectiveUrl = dappOrigin || dappUrl
135- console .log (" [ConnectorManager] Calling backend disconnect for:" , effectiveUrl)
136- connectorController .disconnect (effectiveUrl)
137- }
138- }
139-
140- // HELPER FUNCTIONS
141- function shouldProcessSignal (event ) {
121+ disconnectEvent ({ code: 4900 , message: " User disconnected" }) // EIP-1193: Disconnected
122+ accountsChangedEvent ([])
123+ console .log (" [ConnectorManager] State cleared" )
124+ return true
125+ }
126+
127+ // PUBLIC API
128+ function disconnect () {
129+ clearState ()
130+
131+ if (connectorController) {
132+ connectorController .disconnect (dappOrigin)
133+ }
134+ }
135+
136+ function changeAccount (newAccount ) {
137+ if (connectorController) {
138+ connectorController .changeAccount (dappOrigin, clientId, newAccount)
139+ }
140+ }
141+
142+ // HELPER FUNCTIONS
143+ function shouldProcessSignal (event ) {
142144 // Filter by origin
143145 if (event .url && Utils .normalizeOrigin (event .url ) !== Utils .normalizeOrigin (dappOrigin)) {
144146 console .log (" [ConnectorManager] Ignoring signal for other origin:" , event .url , " expected:" , dappOrigin)
@@ -216,12 +218,23 @@ Item {
216218 const chainIdHex = Utils .chainIdToHex (chainIdDecimal)
217219
218220 providerStateChanged ()
219- chainChangedEvent (chainIdHex)
220- console .log (" [ConnectorManager] Chain switched to:" , chainIdHex)
221- }
222- } catch (error) {
223- console .error (" [ConnectorManager] Error processing chainIdSwitched signal:" , error)
224- }
225- }
226- }
221+ chainChangedEvent (chainIdHex)
222+ console .log (" [ConnectorManager] Chain switched to:" , chainIdHex)
223+ }
224+ } catch (error) {
225+ console .error (" [ConnectorManager] Error processing chainIdSwitched signal:" , error)
226+ }
227+ }
228+
229+ function onAccountChanged (payload ) {
230+ try {
231+ const data = JSON .parse (payload)
232+ if (! shouldProcessSignal (data)) return
233+ const newAccounts = data .sharedAccount ? [data .sharedAccount ] : []
234+ updateAccounts (newAccounts)
235+ } catch (error) {
236+ console .error (" [ConnectorManager] Error processing accountChanged signal:" , error)
237+ }
238+ }
239+ }
227240}
0 commit comments