@meshconnect/uwc-core 1.0.1-snapshot.c7e65ce → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -211
- package/dist/events.d.ts +2 -69
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +1 -40
- package/dist/events.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/managers/event-manager.d.ts.map +1 -1
- package/dist/managers/event-manager.js +1 -5
- package/dist/managers/event-manager.js.map +1 -1
- package/dist/services/connection-service.d.ts +1 -2
- package/dist/services/connection-service.d.ts.map +1 -1
- package/dist/services/connection-service.js +15 -35
- package/dist/services/connection-service.js.map +1 -1
- package/dist/services/network-switch-service.d.ts +1 -2
- package/dist/services/network-switch-service.d.ts.map +1 -1
- package/dist/services/network-switch-service.js +15 -33
- package/dist/services/network-switch-service.js.map +1 -1
- package/dist/universal-wallet-connector.d.ts +2 -51
- package/dist/universal-wallet-connector.d.ts.map +1 -1
- package/dist/universal-wallet-connector.js +61 -163
- package/dist/universal-wallet-connector.js.map +1 -1
- package/package.json +5 -5
- package/src/events.ts +1 -114
- package/src/index.ts +0 -6
- package/src/managers/event-manager.test.ts +0 -25
- package/src/managers/event-manager.ts +1 -5
- package/src/services/connection-service.test.ts +1 -66
- package/src/services/connection-service.ts +32 -54
- package/src/services/network-switch-service.test.ts +1 -51
- package/src/services/network-switch-service.ts +23 -43
- package/src/universal-wallet-connector.ts +71 -244
- package/dist/logger/create-logger.d.ts +0 -32
- package/dist/logger/create-logger.d.ts.map +0 -1
- package/dist/logger/create-logger.js +0 -69
- package/dist/logger/create-logger.js.map +0 -1
- package/dist/observability/connect-observer.d.ts +0 -22
- package/dist/observability/connect-observer.d.ts.map +0 -1
- package/dist/observability/connect-observer.js +0 -60
- package/dist/observability/connect-observer.js.map +0 -1
- package/dist/observability/instrument-handoff.d.ts +0 -39
- package/dist/observability/instrument-handoff.d.ts.map +0 -1
- package/dist/observability/instrument-handoff.js +0 -86
- package/dist/observability/instrument-handoff.js.map +0 -1
- package/dist/observability/scrub.d.ts +0 -30
- package/dist/observability/scrub.d.ts.map +0 -1
- package/dist/observability/scrub.js +0 -135
- package/dist/observability/scrub.js.map +0 -1
- package/dist/observability/telemetry.d.ts +0 -77
- package/dist/observability/telemetry.d.ts.map +0 -1
- package/dist/observability/telemetry.js +0 -138
- package/dist/observability/telemetry.js.map +0 -1
- package/dist/utils/id.d.ts +0 -2
- package/dist/utils/id.d.ts.map +0 -1
- package/dist/utils/id.js +0 -41
- package/dist/utils/id.js.map +0 -1
- package/dist/utils/to-wallet-error.d.ts +0 -16
- package/dist/utils/to-wallet-error.d.ts.map +0 -1
- package/dist/utils/to-wallet-error.js +0 -33
- package/dist/utils/to-wallet-error.js.map +0 -1
- package/src/logger/create-logger.test.ts +0 -111
- package/src/logger/create-logger.ts +0 -101
- package/src/observability/connect-observer.test.ts +0 -100
- package/src/observability/connect-observer.ts +0 -71
- package/src/observability/instrument-handoff.test.ts +0 -150
- package/src/observability/instrument-handoff.ts +0 -122
- package/src/observability/scrub.test.ts +0 -109
- package/src/observability/scrub.ts +0 -142
- package/src/observability/telemetry.test.ts +0 -134
- package/src/observability/telemetry.ts +0 -211
- package/src/universal-wallet-connector.observability.test.ts +0 -265
- package/src/utils/id.test.ts +0 -15
- package/src/utils/id.ts +0 -48
- package/src/utils/to-wallet-error.ts +0 -36
|
@@ -81,8 +81,7 @@ describe('ConnectionService', () => {
|
|
|
81
81
|
sessionManager,
|
|
82
82
|
connectors,
|
|
83
83
|
false,
|
|
84
|
-
eventManager
|
|
85
|
-
60_000
|
|
84
|
+
eventManager
|
|
86
85
|
)
|
|
87
86
|
})
|
|
88
87
|
|
|
@@ -194,70 +193,6 @@ describe('ConnectionService', () => {
|
|
|
194
193
|
expect(connectingListener).not.toHaveBeenCalled()
|
|
195
194
|
})
|
|
196
195
|
|
|
197
|
-
it('does NOT emit awaitingWallet when validation throws (pre-wallet failure stays out of the funnel)', async () => {
|
|
198
|
-
const awaiting = vi.fn()
|
|
199
|
-
const failed = vi.fn()
|
|
200
|
-
eventManager.on('awaitingWallet', awaiting)
|
|
201
|
-
eventManager.on('walletFailed', failed)
|
|
202
|
-
|
|
203
|
-
await expect(
|
|
204
|
-
connectionService.connect('injected', 'no-such-wallet', 'eip155:1')
|
|
205
|
-
).rejects.toThrow()
|
|
206
|
-
|
|
207
|
-
expect(awaiting).not.toHaveBeenCalled()
|
|
208
|
-
expect(failed).not.toHaveBeenCalled()
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
it('emits awaitingWallet + walletSucceeded around the wallet call, with resolved facets', async () => {
|
|
212
|
-
wallets[0].extensionInjectedProvider = {
|
|
213
|
-
supportedNetworkIds: ['eip155:1']
|
|
214
|
-
} as any
|
|
215
|
-
const events: Array<{ name: string; data: any }> = []
|
|
216
|
-
eventManager.on('awaitingWallet', d =>
|
|
217
|
-
events.push({ name: 'awaitingWallet', data: d })
|
|
218
|
-
)
|
|
219
|
-
eventManager.on('walletSucceeded', d =>
|
|
220
|
-
events.push({ name: 'walletSucceeded', data: d })
|
|
221
|
-
)
|
|
222
|
-
mockConnector.connect = vi.fn().mockResolvedValue({
|
|
223
|
-
networkId: 'eip155:1',
|
|
224
|
-
address: '0x1234',
|
|
225
|
-
availableAddresses: [{ address: '0x1234', networkId: 'eip155:1' }]
|
|
226
|
-
})
|
|
227
|
-
|
|
228
|
-
await connectionService.connect('injected', 'metamask', 'eip155:1')
|
|
229
|
-
|
|
230
|
-
expect(events.map(e => e.name)).toEqual([
|
|
231
|
-
'awaitingWallet',
|
|
232
|
-
'walletSucceeded'
|
|
233
|
-
])
|
|
234
|
-
const awaiting = events[0].data
|
|
235
|
-
expect(awaiting.operation).toBe('connect')
|
|
236
|
-
expect(awaiting.namespace).toBe('eip155')
|
|
237
|
-
expect(awaiting.chainId).toBe('eip155:1')
|
|
238
|
-
expect(awaiting.handoffId).toBe(events[1].data.handoffId)
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
it('emits awaitingWallet + walletFailed when the connector call throws', async () => {
|
|
242
|
-
wallets[0].extensionInjectedProvider = {
|
|
243
|
-
supportedNetworkIds: ['eip155:1']
|
|
244
|
-
} as any
|
|
245
|
-
const awaiting = vi.fn()
|
|
246
|
-
const failed = vi.fn()
|
|
247
|
-
eventManager.on('awaitingWallet', awaiting)
|
|
248
|
-
eventManager.on('walletFailed', failed)
|
|
249
|
-
mockConnector.connect = vi
|
|
250
|
-
.fn()
|
|
251
|
-
.mockRejectedValue(new Error('wallet exploded'))
|
|
252
|
-
|
|
253
|
-
await expect(
|
|
254
|
-
connectionService.connect('injected', 'metamask', 'eip155:1')
|
|
255
|
-
).rejects.toThrow('wallet exploded')
|
|
256
|
-
|
|
257
|
-
expect(awaiting).toHaveBeenCalledTimes(1)
|
|
258
|
-
expect(failed).toHaveBeenCalledTimes(1)
|
|
259
|
-
})
|
|
260
|
-
|
|
261
196
|
it('rejects mid-flight when AbortSignal fires during connector.connect', async () => {
|
|
262
197
|
wallets[0].extensionInjectedProvider = {
|
|
263
198
|
supportedNetworkIds: ['eip155:1']
|
|
@@ -13,7 +13,6 @@ import type {
|
|
|
13
13
|
import type { SessionManager } from '../managers/session-manager'
|
|
14
14
|
import type { EventManager } from '../managers/event-manager'
|
|
15
15
|
import { raceAbort } from '../utils/abort'
|
|
16
|
-
import { instrumentHandoff } from '../observability/instrument-handoff'
|
|
17
16
|
|
|
18
17
|
export interface ServiceOptions {
|
|
19
18
|
signal?: AbortSignal
|
|
@@ -28,9 +27,7 @@ export class ConnectionService {
|
|
|
28
27
|
private sessionManager: SessionManager,
|
|
29
28
|
private connectors: Map<ConnectionMode, Connector>,
|
|
30
29
|
private usingIntegratedBrowser: boolean,
|
|
31
|
-
private eventManager: EventManager
|
|
32
|
-
// Observational wallet-response deadline for the handoff timeout marker.
|
|
33
|
-
private walletResponseTimeoutMs: number
|
|
30
|
+
private eventManager: EventManager
|
|
34
31
|
) {}
|
|
35
32
|
|
|
36
33
|
async connect(
|
|
@@ -63,56 +60,37 @@ export class ConnectionService {
|
|
|
63
60
|
|
|
64
61
|
let result
|
|
65
62
|
try {
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
//
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
} else if (
|
|
98
|
-
connectionMode === 'tonConnect' ||
|
|
99
|
-
connectionMode === 'walletConnect'
|
|
100
|
-
) {
|
|
101
|
-
return await raceAbort(
|
|
102
|
-
this.connectWithURIPoll(
|
|
103
|
-
connector,
|
|
104
|
-
network,
|
|
105
|
-
provider,
|
|
106
|
-
connectionMode,
|
|
107
|
-
options?.signal
|
|
108
|
-
),
|
|
109
|
-
options?.signal
|
|
110
|
-
)
|
|
111
|
-
} else {
|
|
112
|
-
throw new Error(`Unsupported connection mode: ${connectionMode}`)
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
)
|
|
63
|
+
// Race the connector call against the AbortSignal so a mid-flight abort
|
|
64
|
+
// (e.g. user cancels the WalletConnect QR while the prompt is open)
|
|
65
|
+
// rejects the caller's await promptly. The underlying wallet prompt
|
|
66
|
+
// itself can't be cancelled, but the dapp UI is no longer blocked on it.
|
|
67
|
+
if (connectionMode === 'injected') {
|
|
68
|
+
result = await raceAbort(
|
|
69
|
+
connector.connect(
|
|
70
|
+
network,
|
|
71
|
+
provider as
|
|
72
|
+
| ExtensionInjectedProvider
|
|
73
|
+
| IntegratedBrowserInjectedProvider
|
|
74
|
+
),
|
|
75
|
+
options?.signal
|
|
76
|
+
)
|
|
77
|
+
} else if (
|
|
78
|
+
connectionMode === 'tonConnect' ||
|
|
79
|
+
connectionMode === 'walletConnect'
|
|
80
|
+
) {
|
|
81
|
+
result = await raceAbort(
|
|
82
|
+
this.connectWithURIPoll(
|
|
83
|
+
connector,
|
|
84
|
+
network,
|
|
85
|
+
provider,
|
|
86
|
+
connectionMode,
|
|
87
|
+
options?.signal
|
|
88
|
+
),
|
|
89
|
+
options?.signal
|
|
90
|
+
)
|
|
91
|
+
} else {
|
|
92
|
+
throw new Error(`Unsupported connection mode: ${connectionMode}`)
|
|
93
|
+
}
|
|
116
94
|
} catch (error) {
|
|
117
95
|
this.activeConnector = null
|
|
118
96
|
throw error
|
|
@@ -84,8 +84,7 @@ describe('NetworkSwitchService', () => {
|
|
|
84
84
|
sessionManager,
|
|
85
85
|
connectors,
|
|
86
86
|
false,
|
|
87
|
-
eventManager
|
|
88
|
-
60_000
|
|
87
|
+
eventManager
|
|
89
88
|
)
|
|
90
89
|
})
|
|
91
90
|
|
|
@@ -185,53 +184,4 @@ describe('NetworkSwitchService', () => {
|
|
|
185
184
|
"Wallet 'metamask' does not have a provider for injected mode"
|
|
186
185
|
)
|
|
187
186
|
})
|
|
188
|
-
|
|
189
|
-
it('does NOT emit awaitingWallet when validation throws (no active wallet)', async () => {
|
|
190
|
-
const awaiting = vi.fn()
|
|
191
|
-
eventManager.on('awaitingWallet', awaiting)
|
|
192
|
-
|
|
193
|
-
await expect(
|
|
194
|
-
networkSwitchService.switchNetwork('eip155:1')
|
|
195
|
-
).rejects.toThrow()
|
|
196
|
-
|
|
197
|
-
expect(awaiting).not.toHaveBeenCalled()
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
it('emits awaitingWallet + walletSucceeded around the wallet switch call', async () => {
|
|
201
|
-
sessionManager.updateSession({
|
|
202
|
-
connectionMode: 'injected',
|
|
203
|
-
activeWallet: {
|
|
204
|
-
id: 'metamask',
|
|
205
|
-
name: 'MetaMask',
|
|
206
|
-
metadata: {
|
|
207
|
-
icon: 'test',
|
|
208
|
-
downloadUrl: 'test',
|
|
209
|
-
supportedChains: ['eip155:1', 'eip155:137']
|
|
210
|
-
},
|
|
211
|
-
extensionInjectedProvider: {
|
|
212
|
-
supportedNetworkIds: ['eip155:1', 'eip155:137']
|
|
213
|
-
}
|
|
214
|
-
} as any
|
|
215
|
-
})
|
|
216
|
-
mockConnector.switchNetwork = vi.fn().mockResolvedValue({
|
|
217
|
-
address: '0xabc',
|
|
218
|
-
availableAddresses: [{ address: '0xabc', networkId: 'eip155:137' }]
|
|
219
|
-
})
|
|
220
|
-
const events: Array<{ name: string; data: any }> = []
|
|
221
|
-
eventManager.on('awaitingWallet', d =>
|
|
222
|
-
events.push({ name: 'awaitingWallet', data: d })
|
|
223
|
-
)
|
|
224
|
-
eventManager.on('walletSucceeded', d =>
|
|
225
|
-
events.push({ name: 'walletSucceeded', data: d })
|
|
226
|
-
)
|
|
227
|
-
|
|
228
|
-
await networkSwitchService.switchNetwork('eip155:137')
|
|
229
|
-
|
|
230
|
-
expect(events.map(e => e.name)).toEqual([
|
|
231
|
-
'awaitingWallet',
|
|
232
|
-
'walletSucceeded'
|
|
233
|
-
])
|
|
234
|
-
expect(events[0].data.operation).toBe('switchNetwork')
|
|
235
|
-
expect(events[0].data.chainId).toBe('eip155:137')
|
|
236
|
-
})
|
|
237
187
|
})
|
|
@@ -12,7 +12,6 @@ import type {
|
|
|
12
12
|
import type { SessionManager } from '../managers/session-manager'
|
|
13
13
|
import type { EventManager } from '../managers/event-manager'
|
|
14
14
|
import type { ServiceOptions } from './connection-service'
|
|
15
|
-
import { instrumentHandoff } from '../observability/instrument-handoff'
|
|
16
15
|
|
|
17
16
|
export class NetworkSwitchService {
|
|
18
17
|
private isLoading = false
|
|
@@ -23,9 +22,7 @@ export class NetworkSwitchService {
|
|
|
23
22
|
private sessionManager: SessionManager,
|
|
24
23
|
private connectors: Map<ConnectionMode, Connector>,
|
|
25
24
|
private usingIntegratedBrowser: boolean,
|
|
26
|
-
private eventManager: EventManager
|
|
27
|
-
// Observational wallet-response deadline for the handoff timeout marker.
|
|
28
|
-
private walletResponseTimeoutMs: number
|
|
25
|
+
private eventManager: EventManager
|
|
29
26
|
) {}
|
|
30
27
|
|
|
31
28
|
getLoadingState() {
|
|
@@ -118,45 +115,28 @@ export class NetworkSwitchService {
|
|
|
118
115
|
isWaitingForUserApproval: requiresApproval
|
|
119
116
|
})
|
|
120
117
|
|
|
121
|
-
// Perform the network switch and get the new address
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
) {
|
|
144
|
-
return await activeConnector.switchNetwork(
|
|
145
|
-
network,
|
|
146
|
-
provider as
|
|
147
|
-
| ExtensionInjectedProvider
|
|
148
|
-
| IntegratedBrowserInjectedProvider
|
|
149
|
-
)
|
|
150
|
-
} else if (session.connectionMode === 'walletConnect' && provider) {
|
|
151
|
-
return await activeConnector.switchNetwork(
|
|
152
|
-
network,
|
|
153
|
-
provider as WalletConnectProvider
|
|
154
|
-
)
|
|
155
|
-
} else {
|
|
156
|
-
return await activeConnector.switchNetwork(network)
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
)
|
|
118
|
+
// Perform the network switch and get the new address
|
|
119
|
+
// Pass the appropriate provider based on connection mode
|
|
120
|
+
let result
|
|
121
|
+
if (
|
|
122
|
+
(session.connectionMode === 'injected' ||
|
|
123
|
+
session.connectionMode === 'tonConnect') &&
|
|
124
|
+
provider
|
|
125
|
+
) {
|
|
126
|
+
result = await activeConnector.switchNetwork(
|
|
127
|
+
network,
|
|
128
|
+
provider as
|
|
129
|
+
| ExtensionInjectedProvider
|
|
130
|
+
| IntegratedBrowserInjectedProvider
|
|
131
|
+
)
|
|
132
|
+
} else if (session.connectionMode === 'walletConnect' && provider) {
|
|
133
|
+
result = await activeConnector.switchNetwork(
|
|
134
|
+
network,
|
|
135
|
+
provider as WalletConnectProvider
|
|
136
|
+
)
|
|
137
|
+
} else {
|
|
138
|
+
result = await activeConnector.switchNetwork(network)
|
|
139
|
+
}
|
|
160
140
|
|
|
161
141
|
options?.signal?.throwIfAborted()
|
|
162
142
|
|