@0xsequence/provider 0.43.4 → 0.43.5

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.
@@ -1914,10 +1914,12 @@ class BaseWalletTransport {
1914
1914
  }
1915
1915
 
1916
1916
  // Set connect options on the walletRequestHandler as our primary
1917
- // wallet controller
1917
+ // wallet controller, and fall back to networkId if necessary
1918
1918
  _this.walletRequestHandler.setConnectOptions(connectOptions);
1919
1919
  if (connectOptions.networkId) {
1920
1920
  networkId = connectOptions.networkId;
1921
+ } else if (networkId) {
1922
+ connectOptions.networkId = networkId;
1921
1923
  }
1922
1924
  } else {
1923
1925
  _this.walletRequestHandler.setConnectOptions(undefined);
@@ -1934,32 +1936,28 @@ class BaseWalletTransport {
1934
1936
  });
1935
1937
  return true;
1936
1938
  } else {
1937
- // Set default network, in case of error chainId will be undefined or 0
1938
- let chainId = undefined;
1939
- try {
1940
- if (networkId) {
1941
- chainId = await _this.walletRequestHandler.setDefaultNetwork(networkId, false);
1942
- } else {
1943
- chainId = await _this.walletRequestHandler.getChainId();
1944
- }
1945
- } catch (err) {
1946
- console.error(err);
1947
- }
1948
-
1949
- // Failed to set default network on open -- quit + close
1950
- if (!chainId || chainId <= 0) {
1951
- _this.notifyOpen({
1952
- sessionId: _this._sessionId,
1953
- error: `failed to open wallet on network ${networkId}`
1954
- });
1955
- return false;
1956
- }
1957
-
1958
1939
  // prompt user with a connect request. the options will be used as previously set above.
1959
1940
  // upon success, the walletRequestHandler will notify the dapp with the ConnectDetails.
1960
1941
  // upon cancellation by user, the walletRequestHandler will throw an error
1961
1942
 
1962
1943
  if (intent && intent.type === 'connect') {
1944
+ let chainId = undefined;
1945
+ try {
1946
+ if (networkId) {
1947
+ chainId = await _this.walletRequestHandler.setDefaultNetwork(networkId, false);
1948
+ } else {
1949
+ chainId = await _this.walletRequestHandler.getChainId();
1950
+ }
1951
+ } catch (err) {
1952
+ console.error(err);
1953
+ }
1954
+ // Failed to set default network on open
1955
+ // Fail silently here so we can continue with connect flow and ask
1956
+ // user to connect on a different network if necessary
1957
+ if (!chainId || chainId <= 0) {
1958
+ console.log('Failed to set default network on open');
1959
+ }
1960
+
1963
1961
  // notify wallet is opened, without session details
1964
1962
  _this.notifyOpen({
1965
1963
  sessionId: _this._sessionId
@@ -1978,6 +1976,27 @@ class BaseWalletTransport {
1978
1976
  }
1979
1977
  }
1980
1978
  } else {
1979
+ // Set default network, in case of error chainId will be undefined or 0
1980
+ let chainId = undefined;
1981
+ try {
1982
+ if (networkId) {
1983
+ chainId = await _this.walletRequestHandler.setDefaultNetwork(networkId, false);
1984
+ } else {
1985
+ chainId = await _this.walletRequestHandler.getChainId();
1986
+ }
1987
+ } catch (err) {
1988
+ console.error(err);
1989
+ }
1990
+
1991
+ // Failed to set default network on open -- quit + close
1992
+ if (!chainId || chainId <= 0) {
1993
+ _this.notifyOpen({
1994
+ sessionId: _this._sessionId,
1995
+ error: `failed to open wallet on network ${networkId}`
1996
+ });
1997
+ return false;
1998
+ }
1999
+
1981
2000
  // user is already connected, notify session details.
1982
2001
  // TODO: in future, keep list if 'connected' dapps / sessions in the session
1983
2002
  // controller, and only sync with allowed apps
@@ -3425,10 +3444,18 @@ class Wallet {
3425
3444
  type: 'connect',
3426
3445
  options
3427
3446
  });
3428
- const connectDetails = await _this.transport.messageProvider.waitUntilConnected().catch(_ => {
3429
- return {
3430
- connected: false
3431
- };
3447
+ const connectDetails = await _this.transport.messageProvider.waitUntilConnected().catch(error => {
3448
+ if (error instanceof Error) {
3449
+ return {
3450
+ connected: false,
3451
+ error: error.message
3452
+ };
3453
+ } else {
3454
+ return {
3455
+ connected: false,
3456
+ error: JSON.stringify(error)
3457
+ };
3458
+ }
3432
3459
  });
3433
3460
  if (connectDetails.connected) {
3434
3461
  if (!!connectDetails.session) {
@@ -1914,10 +1914,12 @@ class BaseWalletTransport {
1914
1914
  }
1915
1915
 
1916
1916
  // Set connect options on the walletRequestHandler as our primary
1917
- // wallet controller
1917
+ // wallet controller, and fall back to networkId if necessary
1918
1918
  _this.walletRequestHandler.setConnectOptions(connectOptions);
1919
1919
  if (connectOptions.networkId) {
1920
1920
  networkId = connectOptions.networkId;
1921
+ } else if (networkId) {
1922
+ connectOptions.networkId = networkId;
1921
1923
  }
1922
1924
  } else {
1923
1925
  _this.walletRequestHandler.setConnectOptions(undefined);
@@ -1934,32 +1936,28 @@ class BaseWalletTransport {
1934
1936
  });
1935
1937
  return true;
1936
1938
  } else {
1937
- // Set default network, in case of error chainId will be undefined or 0
1938
- let chainId = undefined;
1939
- try {
1940
- if (networkId) {
1941
- chainId = await _this.walletRequestHandler.setDefaultNetwork(networkId, false);
1942
- } else {
1943
- chainId = await _this.walletRequestHandler.getChainId();
1944
- }
1945
- } catch (err) {
1946
- console.error(err);
1947
- }
1948
-
1949
- // Failed to set default network on open -- quit + close
1950
- if (!chainId || chainId <= 0) {
1951
- _this.notifyOpen({
1952
- sessionId: _this._sessionId,
1953
- error: `failed to open wallet on network ${networkId}`
1954
- });
1955
- return false;
1956
- }
1957
-
1958
1939
  // prompt user with a connect request. the options will be used as previously set above.
1959
1940
  // upon success, the walletRequestHandler will notify the dapp with the ConnectDetails.
1960
1941
  // upon cancellation by user, the walletRequestHandler will throw an error
1961
1942
 
1962
1943
  if (intent && intent.type === 'connect') {
1944
+ let chainId = undefined;
1945
+ try {
1946
+ if (networkId) {
1947
+ chainId = await _this.walletRequestHandler.setDefaultNetwork(networkId, false);
1948
+ } else {
1949
+ chainId = await _this.walletRequestHandler.getChainId();
1950
+ }
1951
+ } catch (err) {
1952
+ console.error(err);
1953
+ }
1954
+ // Failed to set default network on open
1955
+ // Fail silently here so we can continue with connect flow and ask
1956
+ // user to connect on a different network if necessary
1957
+ if (!chainId || chainId <= 0) {
1958
+ console.log('Failed to set default network on open');
1959
+ }
1960
+
1963
1961
  // notify wallet is opened, without session details
1964
1962
  _this.notifyOpen({
1965
1963
  sessionId: _this._sessionId
@@ -1978,6 +1976,27 @@ class BaseWalletTransport {
1978
1976
  }
1979
1977
  }
1980
1978
  } else {
1979
+ // Set default network, in case of error chainId will be undefined or 0
1980
+ let chainId = undefined;
1981
+ try {
1982
+ if (networkId) {
1983
+ chainId = await _this.walletRequestHandler.setDefaultNetwork(networkId, false);
1984
+ } else {
1985
+ chainId = await _this.walletRequestHandler.getChainId();
1986
+ }
1987
+ } catch (err) {
1988
+ console.error(err);
1989
+ }
1990
+
1991
+ // Failed to set default network on open -- quit + close
1992
+ if (!chainId || chainId <= 0) {
1993
+ _this.notifyOpen({
1994
+ sessionId: _this._sessionId,
1995
+ error: `failed to open wallet on network ${networkId}`
1996
+ });
1997
+ return false;
1998
+ }
1999
+
1981
2000
  // user is already connected, notify session details.
1982
2001
  // TODO: in future, keep list if 'connected' dapps / sessions in the session
1983
2002
  // controller, and only sync with allowed apps
@@ -3425,10 +3444,18 @@ class Wallet {
3425
3444
  type: 'connect',
3426
3445
  options
3427
3446
  });
3428
- const connectDetails = await _this.transport.messageProvider.waitUntilConnected().catch(_ => {
3429
- return {
3430
- connected: false
3431
- };
3447
+ const connectDetails = await _this.transport.messageProvider.waitUntilConnected().catch(error => {
3448
+ if (error instanceof Error) {
3449
+ return {
3450
+ connected: false,
3451
+ error: error.message
3452
+ };
3453
+ } else {
3454
+ return {
3455
+ connected: false,
3456
+ error: JSON.stringify(error)
3457
+ };
3458
+ }
3432
3459
  });
3433
3460
  if (connectDetails.connected) {
3434
3461
  if (!!connectDetails.session) {
@@ -1910,10 +1910,12 @@ class BaseWalletTransport {
1910
1910
  }
1911
1911
 
1912
1912
  // Set connect options on the walletRequestHandler as our primary
1913
- // wallet controller
1913
+ // wallet controller, and fall back to networkId if necessary
1914
1914
  _this.walletRequestHandler.setConnectOptions(connectOptions);
1915
1915
  if (connectOptions.networkId) {
1916
1916
  networkId = connectOptions.networkId;
1917
+ } else if (networkId) {
1918
+ connectOptions.networkId = networkId;
1917
1919
  }
1918
1920
  } else {
1919
1921
  _this.walletRequestHandler.setConnectOptions(undefined);
@@ -1930,32 +1932,28 @@ class BaseWalletTransport {
1930
1932
  });
1931
1933
  return true;
1932
1934
  } else {
1933
- // Set default network, in case of error chainId will be undefined or 0
1934
- let chainId = undefined;
1935
- try {
1936
- if (networkId) {
1937
- chainId = await _this.walletRequestHandler.setDefaultNetwork(networkId, false);
1938
- } else {
1939
- chainId = await _this.walletRequestHandler.getChainId();
1940
- }
1941
- } catch (err) {
1942
- console.error(err);
1943
- }
1944
-
1945
- // Failed to set default network on open -- quit + close
1946
- if (!chainId || chainId <= 0) {
1947
- _this.notifyOpen({
1948
- sessionId: _this._sessionId,
1949
- error: `failed to open wallet on network ${networkId}`
1950
- });
1951
- return false;
1952
- }
1953
-
1954
1935
  // prompt user with a connect request. the options will be used as previously set above.
1955
1936
  // upon success, the walletRequestHandler will notify the dapp with the ConnectDetails.
1956
1937
  // upon cancellation by user, the walletRequestHandler will throw an error
1957
1938
 
1958
1939
  if (intent && intent.type === 'connect') {
1940
+ let chainId = undefined;
1941
+ try {
1942
+ if (networkId) {
1943
+ chainId = await _this.walletRequestHandler.setDefaultNetwork(networkId, false);
1944
+ } else {
1945
+ chainId = await _this.walletRequestHandler.getChainId();
1946
+ }
1947
+ } catch (err) {
1948
+ console.error(err);
1949
+ }
1950
+ // Failed to set default network on open
1951
+ // Fail silently here so we can continue with connect flow and ask
1952
+ // user to connect on a different network if necessary
1953
+ if (!chainId || chainId <= 0) {
1954
+ console.log('Failed to set default network on open');
1955
+ }
1956
+
1959
1957
  // notify wallet is opened, without session details
1960
1958
  _this.notifyOpen({
1961
1959
  sessionId: _this._sessionId
@@ -1974,6 +1972,27 @@ class BaseWalletTransport {
1974
1972
  }
1975
1973
  }
1976
1974
  } else {
1975
+ // Set default network, in case of error chainId will be undefined or 0
1976
+ let chainId = undefined;
1977
+ try {
1978
+ if (networkId) {
1979
+ chainId = await _this.walletRequestHandler.setDefaultNetwork(networkId, false);
1980
+ } else {
1981
+ chainId = await _this.walletRequestHandler.getChainId();
1982
+ }
1983
+ } catch (err) {
1984
+ console.error(err);
1985
+ }
1986
+
1987
+ // Failed to set default network on open -- quit + close
1988
+ if (!chainId || chainId <= 0) {
1989
+ _this.notifyOpen({
1990
+ sessionId: _this._sessionId,
1991
+ error: `failed to open wallet on network ${networkId}`
1992
+ });
1993
+ return false;
1994
+ }
1995
+
1977
1996
  // user is already connected, notify session details.
1978
1997
  // TODO: in future, keep list if 'connected' dapps / sessions in the session
1979
1998
  // controller, and only sync with allowed apps
@@ -3421,10 +3440,18 @@ class Wallet {
3421
3440
  type: 'connect',
3422
3441
  options
3423
3442
  });
3424
- const connectDetails = await _this.transport.messageProvider.waitUntilConnected().catch(_ => {
3425
- return {
3426
- connected: false
3427
- };
3443
+ const connectDetails = await _this.transport.messageProvider.waitUntilConnected().catch(error => {
3444
+ if (error instanceof Error) {
3445
+ return {
3446
+ connected: false,
3447
+ error: error.message
3448
+ };
3449
+ } else {
3450
+ return {
3451
+ connected: false,
3452
+ error: JSON.stringify(error)
3453
+ };
3454
+ }
3428
3455
  });
3429
3456
  if (connectDetails.connected) {
3430
3457
  if (!!connectDetails.session) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xsequence/provider",
3
- "version": "0.43.4",
3
+ "version": "0.43.5",
4
4
  "description": "provider sub-package for Sequence",
5
5
  "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/provider",
6
6
  "source": "src/index.ts",
@@ -14,13 +14,13 @@
14
14
  "typecheck": "tsc --noEmit"
15
15
  },
16
16
  "dependencies": {
17
- "@0xsequence/abi": "^0.43.4",
18
- "@0xsequence/auth": "^0.43.4",
19
- "@0xsequence/config": "^0.43.4",
20
- "@0xsequence/network": "^0.43.4",
21
- "@0xsequence/transactions": "^0.43.4",
22
- "@0xsequence/utils": "^0.43.4",
23
- "@0xsequence/wallet": "^0.43.4",
17
+ "@0xsequence/abi": "^0.43.5",
18
+ "@0xsequence/auth": "^0.43.5",
19
+ "@0xsequence/config": "^0.43.5",
20
+ "@0xsequence/network": "^0.43.5",
21
+ "@0xsequence/transactions": "^0.43.5",
22
+ "@0xsequence/utils": "^0.43.5",
23
+ "@0xsequence/wallet": "^0.43.5",
24
24
  "eventemitter2": "^6.4.5",
25
25
  "webextension-polyfill-ts": "^0.26.0"
26
26
  },
@@ -356,10 +356,12 @@ export abstract class BaseWalletTransport implements WalletTransport {
356
356
  }
357
357
 
358
358
  // Set connect options on the walletRequestHandler as our primary
359
- // wallet controller
359
+ // wallet controller, and fall back to networkId if necessary
360
360
  this.walletRequestHandler.setConnectOptions(connectOptions)
361
361
  if (connectOptions.networkId) {
362
362
  networkId = connectOptions.networkId
363
+ } else if (networkId) {
364
+ connectOptions.networkId = networkId
363
365
  }
364
366
  } else {
365
367
  this.walletRequestHandler.setConnectOptions(undefined)
@@ -376,32 +378,28 @@ export abstract class BaseWalletTransport implements WalletTransport {
376
378
  })
377
379
  return true
378
380
  } else {
379
- // Set default network, in case of error chainId will be undefined or 0
380
- let chainId: number | undefined = undefined
381
- try {
382
- if (networkId) {
383
- chainId = await this.walletRequestHandler.setDefaultNetwork(networkId, false)
384
- } else {
385
- chainId = await this.walletRequestHandler.getChainId()
386
- }
387
- } catch (err) {
388
- console.error(err)
389
- }
390
-
391
- // Failed to set default network on open -- quit + close
392
- if (!chainId || chainId <= 0) {
393
- this.notifyOpen({
394
- sessionId: this._sessionId,
395
- error: `failed to open wallet on network ${networkId}`
396
- })
397
- return false
398
- }
399
-
400
381
  // prompt user with a connect request. the options will be used as previously set above.
401
382
  // upon success, the walletRequestHandler will notify the dapp with the ConnectDetails.
402
383
  // upon cancellation by user, the walletRequestHandler will throw an error
403
384
 
404
385
  if (intent && intent.type === 'connect') {
386
+ let chainId: number | undefined = undefined
387
+ try {
388
+ if (networkId) {
389
+ chainId = await this.walletRequestHandler.setDefaultNetwork(networkId, false)
390
+ } else {
391
+ chainId = await this.walletRequestHandler.getChainId()
392
+ }
393
+ } catch (err) {
394
+ console.error(err)
395
+ }
396
+ // Failed to set default network on open
397
+ // Fail silently here so we can continue with connect flow and ask
398
+ // user to connect on a different network if necessary
399
+ if (!chainId || chainId <= 0) {
400
+ console.log('Failed to set default network on open')
401
+ }
402
+
405
403
  // notify wallet is opened, without session details
406
404
  this.notifyOpen({
407
405
  sessionId: this._sessionId
@@ -421,6 +419,27 @@ export abstract class BaseWalletTransport implements WalletTransport {
421
419
  }
422
420
  }
423
421
  } else {
422
+ // Set default network, in case of error chainId will be undefined or 0
423
+ let chainId: number | undefined = undefined
424
+ try {
425
+ if (networkId) {
426
+ chainId = await this.walletRequestHandler.setDefaultNetwork(networkId, false)
427
+ } else {
428
+ chainId = await this.walletRequestHandler.getChainId()
429
+ }
430
+ } catch (err) {
431
+ console.error(err)
432
+ }
433
+
434
+ // Failed to set default network on open -- quit + close
435
+ if (!chainId || chainId <= 0) {
436
+ this.notifyOpen({
437
+ sessionId: this._sessionId,
438
+ error: `failed to open wallet on network ${networkId}`
439
+ })
440
+ return false
441
+ }
442
+
424
443
  // user is already connected, notify session details.
425
444
  // TODO: in future, keep list if 'connected' dapps / sessions in the session
426
445
  // controller, and only sync with allowed apps
package/src/wallet.ts CHANGED
@@ -291,8 +291,13 @@ export class Wallet implements WalletProvider {
291
291
  }
292
292
 
293
293
  await this.openWallet(undefined, { type: 'connect', options })
294
- const connectDetails = await this.transport.messageProvider!.waitUntilConnected().catch(_ => {
295
- return { connected: false } as ConnectDetails
294
+
295
+ const connectDetails = await this.transport.messageProvider!.waitUntilConnected().catch((error): ConnectDetails => {
296
+ if (error instanceof Error) {
297
+ return { connected: false, error: error.message }
298
+ } else {
299
+ return { connected: false, error: JSON.stringify(error) }
300
+ }
296
301
  })
297
302
 
298
303
  if (connectDetails.connected) {