@portal-hq/provider 2.1.0 → 2.1.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.
@@ -188,6 +188,17 @@ class Provider {
188
188
  if (method === 'eth_chainId') {
189
189
  return this.chainId;
190
190
  }
191
+ // Handle changing chains
192
+ if (method == 'wallet_switchEthereumChain') {
193
+ const param = params[0];
194
+ const chainId = parseInt(param.chainId, 16);
195
+ this.chainId = chainId;
196
+ this.emit('portal_signatureReceived', {
197
+ method,
198
+ params,
199
+ signature: null,
200
+ });
201
+ }
191
202
  const isSignerMethod = signerMethods.includes(method);
192
203
  let result;
193
204
  if (!isSignerMethod && !method.startsWith('wallet_')) {
@@ -186,6 +186,17 @@ class Provider {
186
186
  if (method === 'eth_chainId') {
187
187
  return this.chainId;
188
188
  }
189
+ // Handle changing chains
190
+ if (method == 'wallet_switchEthereumChain') {
191
+ const param = params[0];
192
+ const chainId = parseInt(param.chainId, 16);
193
+ this.chainId = chainId;
194
+ this.emit('portal_signatureReceived', {
195
+ method,
196
+ params,
197
+ signature: null,
198
+ });
199
+ }
189
200
  const isSignerMethod = signerMethods.includes(method);
190
201
  let result;
191
202
  if (!isSignerMethod && !method.startsWith('wallet_')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portal-hq/provider",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "license": "MIT",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/esm/index",
@@ -19,8 +19,8 @@
19
19
  "test": "jest"
20
20
  },
21
21
  "dependencies": {
22
- "@portal-hq/connect": "^2.1.0",
23
- "@portal-hq/utils": "^2.1.0"
22
+ "@portal-hq/connect": "^2.1.2",
23
+ "@portal-hq/utils": "^2.1.2"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@babel/preset-typescript": "^7.18.6",
@@ -30,5 +30,5 @@
30
30
  "ts-jest": "^29.0.3",
31
31
  "typescript": "^4.8.4"
32
32
  },
33
- "gitHead": "999b5482f22d2c3fa94d550f65b3ade8d14b8a5d"
33
+ "gitHead": "17a0445191c1399577154042e09fa8759edf194f"
34
34
  }
@@ -160,7 +160,7 @@ class Provider implements IPortalProvider {
160
160
  ) {
161
161
  // If there's no explicit mapping for the current chainId, error out
162
162
  throw new Error(
163
- `[PortalProvider] No RPC endpoint configured for chainId: ${this.chainId}`
163
+ `[PortalProvider] No RPC endpoint configured for chainId: ${this.chainId}`,
164
164
  )
165
165
  }
166
166
 
@@ -173,7 +173,7 @@ class Provider implements IPortalProvider {
173
173
 
174
174
  // If we got this far, there's no way to support the chain with the current config
175
175
  throw new Error(
176
- `[PortalProvider] Could not find a valid gatewayConfig entry for chainId: ${this.chainId}`
176
+ `[PortalProvider] Could not find a valid gatewayConfig entry for chainId: ${this.chainId}`,
177
177
  )
178
178
  }
179
179
 
@@ -227,7 +227,7 @@ class Provider implements IPortalProvider {
227
227
 
228
228
  public removeEventListener(
229
229
  event: string,
230
- listenerToRemove?: EventHandler
230
+ listenerToRemove?: EventHandler,
231
231
  ): void {
232
232
  if (!this.events[event]) {
233
233
  return
@@ -237,7 +237,7 @@ class Provider implements IPortalProvider {
237
237
  this.events[event] = []
238
238
  } else {
239
239
  const filterEventHandlers = (
240
- registeredEventHandler: RegisteredEventHandler
240
+ registeredEventHandler: RegisteredEventHandler,
241
241
  ) => {
242
242
  return registeredEventHandler.handler !== listenerToRemove
243
243
  }
@@ -263,6 +263,20 @@ class Provider implements IPortalProvider {
263
263
  return this.chainId
264
264
  }
265
265
 
266
+ // Handle changing chains
267
+ if (method == 'wallet_switchEthereumChain') {
268
+ const param = (params as any[])[0]
269
+ const chainId = parseInt(param.chainId as string, 16)
270
+
271
+ this.chainId = chainId
272
+
273
+ this.emit('portal_signatureReceived', {
274
+ method,
275
+ params,
276
+ signature: null,
277
+ })
278
+ }
279
+
266
280
  const isSignerMethod = signerMethods.includes(method)
267
281
 
268
282
  let result: any
@@ -322,7 +336,7 @@ class Provider implements IPortalProvider {
322
336
  */
323
337
  public async setChainId(
324
338
  chainId: number,
325
- connect?: PortalConnect
339
+ connect?: PortalConnect,
326
340
  ): Promise<Provider> {
327
341
  // Update the chainId
328
342
  this.chainId = chainId
@@ -368,7 +382,7 @@ class Provider implements IPortalProvider {
368
382
 
369
383
  if (!connect && (!signingHandlers || signingHandlers.length === 0)) {
370
384
  throw new Error(
371
- `[PortalProvider] Auto-approve is disabled. Cannot perform Provider signing requests without an event handler for the 'portal_signingRequested' event.`
385
+ `[PortalProvider] Auto-approve is disabled. Cannot perform Provider signing requests without an event handler for the 'portal_signingRequested' event.`,
372
386
  )
373
387
  }
374
388
 
@@ -392,7 +406,7 @@ class Provider implements IPortalProvider {
392
406
  ) {
393
407
  resolve(true)
394
408
  }
395
- }
409
+ },
396
410
  )
397
411
 
398
412
  // If the signing request has been rejected, resolve to false
@@ -410,7 +424,7 @@ class Provider implements IPortalProvider {
410
424
  ) {
411
425
  resolve(false)
412
426
  }
413
- }
427
+ },
414
428
  )
415
429
 
416
430
  // Tell any listening clients that signing has been requested
@@ -475,7 +489,7 @@ class Provider implements IPortalProvider {
475
489
 
476
490
  if (!isApproved) {
477
491
  this.log.info(
478
- `[PortalProvider] Request for signing method '${method}' could not be completed because it was not approved by the user.`
492
+ `[PortalProvider] Request for signing method '${method}' could not be completed because it was not approved by the user.`,
479
493
  )
480
494
  return
481
495
  }
@@ -493,7 +507,7 @@ class Provider implements IPortalProvider {
493
507
  case 'personal_sign': {
494
508
  const result = await this.signer?.sign(
495
509
  { chainId: this.chainId, method, params },
496
- this
510
+ this,
497
511
  )
498
512
 
499
513
  if (result) {
@@ -519,7 +533,7 @@ class Provider implements IPortalProvider {
519
533
  }
520
534
  default:
521
535
  throw new Error(
522
- '[PortalProvider] Method "' + method + '" not supported'
536
+ '[PortalProvider] Method "' + method + '" not supported',
523
537
  )
524
538
  }
525
539
  }