@0xsequence/provider 0.36.11 → 0.37.0

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.
@@ -1214,8 +1214,12 @@ class WalletRequestHandler {
1214
1214
  const n = networks || (await this.getNetworks(true));
1215
1215
  this.events.emit('networks', n);
1216
1216
 
1217
- if (n && n.length > 0) {
1218
- this.events.emit('chainChanged', ethers.ethers.utils.hexlify(n[0].chainId));
1217
+ if (n.length > 0) {
1218
+ const defaultNetwork = n.find(network => network.isDefaultChain);
1219
+
1220
+ if (defaultNetwork) {
1221
+ this.events.emit('chainChanged', ethers.ethers.utils.hexlify(defaultNetwork.chainId));
1222
+ }
1219
1223
  } else {
1220
1224
  this.events.emit('chainChanged', '0x0');
1221
1225
  }
@@ -2085,7 +2089,7 @@ class BaseWalletTransport {
2085
2089
  if (!networks || networks.length === 0) {
2086
2090
  this.notifyChainChanged('0x0');
2087
2091
  } else {
2088
- this.notifyChainChanged(ethers.ethers.utils.hexlify(networks[0].chainId));
2092
+ this.notifyChainChanged(ethers.ethers.utils.hexlify(networks.find(network => network.isDefaultChain).chainId));
2089
2093
  }
2090
2094
  });
2091
2095
  this.walletRequestHandler.on('walletContext', walletContext => {
@@ -3265,7 +3269,7 @@ class Wallet {
3265
3269
  // return stub chainId of 0 when not connected to any
3266
3270
  if (!this.networks || this.networks.length === 0) return 0; // return the default chainId as we're connected
3267
3271
 
3268
- return this.networks[0].chainId;
3272
+ return this.networks.find(network => network.isDefaultChain).chainId;
3269
3273
  }); // Provider proxy to support middleware stack of logging, caching and read-only rpc calls
3270
3274
 
3271
3275
  this.transport.cachedProvider = new network.CachedProvider();
@@ -3412,13 +3416,12 @@ class Wallet {
3412
3416
  this.getChainId = async function () {
3413
3417
  if (!_this.networks || _this.networks.length < 1) {
3414
3418
  throw new Error('networks have not been set by session. connect first.');
3415
- } // default chain id is first one in the list, by design
3416
-
3419
+ }
3417
3420
 
3418
- const network = _this.networks[0];
3421
+ const network = _this.networks.find(network => network.isDefaultChain);
3419
3422
 
3420
- if (!network.isDefaultChain) {
3421
- throw new Error('expecting first network in list to be default chain');
3423
+ if (!network) {
3424
+ throw new Error('networks must have a default chain specified');
3422
3425
  }
3423
3426
 
3424
3427
  return network.chainId;
@@ -3427,24 +3430,15 @@ class Wallet {
3427
3430
  this.getAuthChainId = async function () {
3428
3431
  if (!_this.networks || _this.networks.length < 1) {
3429
3432
  throw new Error('networks have not been set by session. connect first.');
3430
- } // auth chain is first or second one in the list, by design
3431
-
3432
-
3433
- const network0 = _this.networks[0];
3434
-
3435
- if (network0.isAuthChain) {
3436
- return network0.chainId;
3437
3433
  }
3438
3434
 
3439
- if (_this.networks.length > 1) {
3440
- const network1 = _this.networks[1];
3435
+ const network = _this.networks.find(network => network.isAuthChain);
3441
3436
 
3442
- if (network1.isAuthChain) {
3443
- return network1.chainId;
3444
- }
3437
+ if (!network) {
3438
+ throw new Error('networks must have an auth chain specified');
3445
3439
  }
3446
3440
 
3447
- throw new Error('expecting first or second network in list to be the auth chain');
3441
+ return network.chainId;
3448
3442
  };
3449
3443
 
3450
3444
  this.openWallet = async function (path, intent, networkId) {
@@ -3607,7 +3601,7 @@ class Wallet {
3607
3601
  }
3608
3602
  }
3609
3603
 
3610
- let network$1 = this.networks[0];
3604
+ let network$1 = this.networks.find(network => network.isDefaultChain);
3611
3605
 
3612
3606
  if (chainId) {
3613
3607
  network$1 = network.findNetworkConfig(this.networks, chainId);
@@ -3728,7 +3722,7 @@ class Wallet {
3728
3722
 
3729
3723
 
3730
3724
  if (this.config.networkRpcUrl) {
3731
- this.networks[0].rpcUrl = this.config.networkRpcUrl;
3725
+ this.networks.find(network => network.isDefaultChain).rpcUrl = this.config.networkRpcUrl;
3732
3726
  }
3733
3727
  }
3734
3728
 
@@ -1214,8 +1214,12 @@ class WalletRequestHandler {
1214
1214
  const n = networks || (await this.getNetworks(true));
1215
1215
  this.events.emit('networks', n);
1216
1216
 
1217
- if (n && n.length > 0) {
1218
- this.events.emit('chainChanged', ethers.ethers.utils.hexlify(n[0].chainId));
1217
+ if (n.length > 0) {
1218
+ const defaultNetwork = n.find(network => network.isDefaultChain);
1219
+
1220
+ if (defaultNetwork) {
1221
+ this.events.emit('chainChanged', ethers.ethers.utils.hexlify(defaultNetwork.chainId));
1222
+ }
1219
1223
  } else {
1220
1224
  this.events.emit('chainChanged', '0x0');
1221
1225
  }
@@ -2085,7 +2089,7 @@ class BaseWalletTransport {
2085
2089
  if (!networks || networks.length === 0) {
2086
2090
  this.notifyChainChanged('0x0');
2087
2091
  } else {
2088
- this.notifyChainChanged(ethers.ethers.utils.hexlify(networks[0].chainId));
2092
+ this.notifyChainChanged(ethers.ethers.utils.hexlify(networks.find(network => network.isDefaultChain).chainId));
2089
2093
  }
2090
2094
  });
2091
2095
  this.walletRequestHandler.on('walletContext', walletContext => {
@@ -3265,7 +3269,7 @@ class Wallet {
3265
3269
  // return stub chainId of 0 when not connected to any
3266
3270
  if (!this.networks || this.networks.length === 0) return 0; // return the default chainId as we're connected
3267
3271
 
3268
- return this.networks[0].chainId;
3272
+ return this.networks.find(network => network.isDefaultChain).chainId;
3269
3273
  }); // Provider proxy to support middleware stack of logging, caching and read-only rpc calls
3270
3274
 
3271
3275
  this.transport.cachedProvider = new network.CachedProvider();
@@ -3412,13 +3416,12 @@ class Wallet {
3412
3416
  this.getChainId = async function () {
3413
3417
  if (!_this.networks || _this.networks.length < 1) {
3414
3418
  throw new Error('networks have not been set by session. connect first.');
3415
- } // default chain id is first one in the list, by design
3416
-
3419
+ }
3417
3420
 
3418
- const network = _this.networks[0];
3421
+ const network = _this.networks.find(network => network.isDefaultChain);
3419
3422
 
3420
- if (!network.isDefaultChain) {
3421
- throw new Error('expecting first network in list to be default chain');
3423
+ if (!network) {
3424
+ throw new Error('networks must have a default chain specified');
3422
3425
  }
3423
3426
 
3424
3427
  return network.chainId;
@@ -3427,24 +3430,15 @@ class Wallet {
3427
3430
  this.getAuthChainId = async function () {
3428
3431
  if (!_this.networks || _this.networks.length < 1) {
3429
3432
  throw new Error('networks have not been set by session. connect first.');
3430
- } // auth chain is first or second one in the list, by design
3431
-
3432
-
3433
- const network0 = _this.networks[0];
3434
-
3435
- if (network0.isAuthChain) {
3436
- return network0.chainId;
3437
3433
  }
3438
3434
 
3439
- if (_this.networks.length > 1) {
3440
- const network1 = _this.networks[1];
3435
+ const network = _this.networks.find(network => network.isAuthChain);
3441
3436
 
3442
- if (network1.isAuthChain) {
3443
- return network1.chainId;
3444
- }
3437
+ if (!network) {
3438
+ throw new Error('networks must have an auth chain specified');
3445
3439
  }
3446
3440
 
3447
- throw new Error('expecting first or second network in list to be the auth chain');
3441
+ return network.chainId;
3448
3442
  };
3449
3443
 
3450
3444
  this.openWallet = async function (path, intent, networkId) {
@@ -3607,7 +3601,7 @@ class Wallet {
3607
3601
  }
3608
3602
  }
3609
3603
 
3610
- let network$1 = this.networks[0];
3604
+ let network$1 = this.networks.find(network => network.isDefaultChain);
3611
3605
 
3612
3606
  if (chainId) {
3613
3607
  network$1 = network.findNetworkConfig(this.networks, chainId);
@@ -3728,7 +3722,7 @@ class Wallet {
3728
3722
 
3729
3723
 
3730
3724
  if (this.config.networkRpcUrl) {
3731
- this.networks[0].rpcUrl = this.config.networkRpcUrl;
3725
+ this.networks.find(network => network.isDefaultChain).rpcUrl = this.config.networkRpcUrl;
3732
3726
  }
3733
3727
  }
3734
3728
 
@@ -1210,8 +1210,12 @@ class WalletRequestHandler {
1210
1210
  const n = networks || (await this.getNetworks(true));
1211
1211
  this.events.emit('networks', n);
1212
1212
 
1213
- if (n && n.length > 0) {
1214
- this.events.emit('chainChanged', ethers.utils.hexlify(n[0].chainId));
1213
+ if (n.length > 0) {
1214
+ const defaultNetwork = n.find(network => network.isDefaultChain);
1215
+
1216
+ if (defaultNetwork) {
1217
+ this.events.emit('chainChanged', ethers.utils.hexlify(defaultNetwork.chainId));
1218
+ }
1215
1219
  } else {
1216
1220
  this.events.emit('chainChanged', '0x0');
1217
1221
  }
@@ -2081,7 +2085,7 @@ class BaseWalletTransport {
2081
2085
  if (!networks || networks.length === 0) {
2082
2086
  this.notifyChainChanged('0x0');
2083
2087
  } else {
2084
- this.notifyChainChanged(ethers.utils.hexlify(networks[0].chainId));
2088
+ this.notifyChainChanged(ethers.utils.hexlify(networks.find(network => network.isDefaultChain).chainId));
2085
2089
  }
2086
2090
  });
2087
2091
  this.walletRequestHandler.on('walletContext', walletContext => {
@@ -3261,7 +3265,7 @@ class Wallet {
3261
3265
  // return stub chainId of 0 when not connected to any
3262
3266
  if (!this.networks || this.networks.length === 0) return 0; // return the default chainId as we're connected
3263
3267
 
3264
- return this.networks[0].chainId;
3268
+ return this.networks.find(network => network.isDefaultChain).chainId;
3265
3269
  }); // Provider proxy to support middleware stack of logging, caching and read-only rpc calls
3266
3270
 
3267
3271
  this.transport.cachedProvider = new CachedProvider();
@@ -3408,13 +3412,12 @@ class Wallet {
3408
3412
  this.getChainId = async function () {
3409
3413
  if (!_this.networks || _this.networks.length < 1) {
3410
3414
  throw new Error('networks have not been set by session. connect first.');
3411
- } // default chain id is first one in the list, by design
3412
-
3415
+ }
3413
3416
 
3414
- const network = _this.networks[0];
3417
+ const network = _this.networks.find(network => network.isDefaultChain);
3415
3418
 
3416
- if (!network.isDefaultChain) {
3417
- throw new Error('expecting first network in list to be default chain');
3419
+ if (!network) {
3420
+ throw new Error('networks must have a default chain specified');
3418
3421
  }
3419
3422
 
3420
3423
  return network.chainId;
@@ -3423,24 +3426,15 @@ class Wallet {
3423
3426
  this.getAuthChainId = async function () {
3424
3427
  if (!_this.networks || _this.networks.length < 1) {
3425
3428
  throw new Error('networks have not been set by session. connect first.');
3426
- } // auth chain is first or second one in the list, by design
3427
-
3428
-
3429
- const network0 = _this.networks[0];
3430
-
3431
- if (network0.isAuthChain) {
3432
- return network0.chainId;
3433
3429
  }
3434
3430
 
3435
- if (_this.networks.length > 1) {
3436
- const network1 = _this.networks[1];
3431
+ const network = _this.networks.find(network => network.isAuthChain);
3437
3432
 
3438
- if (network1.isAuthChain) {
3439
- return network1.chainId;
3440
- }
3433
+ if (!network) {
3434
+ throw new Error('networks must have an auth chain specified');
3441
3435
  }
3442
3436
 
3443
- throw new Error('expecting first or second network in list to be the auth chain');
3437
+ return network.chainId;
3444
3438
  };
3445
3439
 
3446
3440
  this.openWallet = async function (path, intent, networkId) {
@@ -3603,7 +3597,7 @@ class Wallet {
3603
3597
  }
3604
3598
  }
3605
3599
 
3606
- let network = this.networks[0];
3600
+ let network = this.networks.find(network => network.isDefaultChain);
3607
3601
 
3608
3602
  if (chainId) {
3609
3603
  network = findNetworkConfig(this.networks, chainId);
@@ -3724,7 +3718,7 @@ class Wallet {
3724
3718
 
3725
3719
 
3726
3720
  if (this.config.networkRpcUrl) {
3727
- this.networks[0].rpcUrl = this.config.networkRpcUrl;
3721
+ this.networks.find(network => network.isDefaultChain).rpcUrl = this.config.networkRpcUrl;
3728
3722
  }
3729
3723
  }
3730
3724
 
@@ -2,7 +2,7 @@ import { ethers } from 'ethers';
2
2
  import { BytesLike, Bytes } from '@ethersproject/bytes';
3
3
  import { Web3Provider as EthersWeb3Provider, JsonRpcProvider } from '@ethersproject/providers';
4
4
  import { TypedDataDomain, TypedDataField, TypedDataSigner } from '@ethersproject/abstract-signer';
5
- import { NetworkConfig, Networks, WalletContext, ChainIdLike, JsonRpcHandler, JsonRpcFetchFunc, JsonRpcRequest, JsonRpcResponseCallback, JsonRpcSender } from '@0xsequence/network';
5
+ import { NetworkConfig, WalletContext, ChainIdLike, JsonRpcHandler, JsonRpcFetchFunc, JsonRpcRequest, JsonRpcResponseCallback, JsonRpcSender } from '@0xsequence/network';
6
6
  import { Signer } from '@0xsequence/wallet';
7
7
  import { WalletConfig, WalletState } from '@0xsequence/config';
8
8
  import { Relayer } from '@0xsequence/relayer';
@@ -21,7 +21,7 @@ export declare class Web3Provider extends EthersWeb3Provider implements JsonRpcH
21
21
  }
22
22
  export declare function isSequenceProvider(provider: any): provider is Web3Provider;
23
23
  export declare class LocalWeb3Provider extends Web3Provider {
24
- constructor(signer: Signer, networks?: Networks);
24
+ constructor(signer: Signer, networks?: NetworkConfig[]);
25
25
  }
26
26
  export declare class Web3Signer extends Signer implements TypedDataSigner {
27
27
  readonly provider: Web3Provider;
@@ -46,7 +46,7 @@ export declare class Web3Signer extends Signer implements TypedDataSigner {
46
46
  signMessage(message: BytesLike, chainId?: ChainIdLike, allSigners?: boolean): Promise<string>;
47
47
  signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>, chainId?: ChainIdLike, allSigners?: boolean): Promise<string>;
48
48
  sendTransaction(transaction: Deferrable<TransactionRequest>, chainId?: ChainIdLike, allSigners?: boolean): Promise<TransactionResponse>;
49
- sendTransactionBatch(transactions: Deferrable<Forbid<TransactionRequest, "wait">[]>, chainId?: ChainIdLike, allSigners?: boolean): Promise<TransactionResponse>;
49
+ sendTransactionBatch(transactions: Deferrable<Forbid<TransactionRequest, 'wait'>[]>, chainId?: ChainIdLike, allSigners?: boolean): Promise<TransactionResponse>;
50
50
  signTransactions(transaction: Deferrable<TransactionRequest>, chainId?: ChainIdLike, allSigners?: boolean): Promise<SignedTransactions>;
51
51
  sendSignedTransactions(signedTxs: SignedTransactions, chainId?: ChainIdLike): Promise<TransactionResponse>;
52
52
  updateConfig(newConfig?: WalletConfig): Promise<[WalletConfig, TransactionResponse | undefined]>;
@@ -1,12 +1,12 @@
1
1
  import { ProviderMessageRequest, ProviderMessageResponse, ProviderMessageRequestHandler, MessageToSign, ProviderRpcError, ConnectOptions, ConnectDetails, PromptConnectDetails, WalletSession, OpenWalletIntent, ProviderEventTypes } from '../types';
2
2
  import { ExternalProvider } from '@ethersproject/providers';
3
- import { Networks, NetworkConfig, JsonRpcHandler, JsonRpcRequest, JsonRpcResponseCallback } from '@0xsequence/network';
3
+ import { NetworkConfig, JsonRpcHandler, JsonRpcRequest, JsonRpcResponseCallback } from '@0xsequence/network';
4
4
  import { Signer } from '@0xsequence/wallet';
5
5
  import { TransactionRequest } from '@0xsequence/transactions';
6
6
  export interface WalletSignInOptions {
7
7
  connect?: boolean;
8
- mainnetNetworks?: Networks;
9
- testnetNetworks?: Networks;
8
+ mainnetNetworks?: NetworkConfig[];
9
+ testnetNetworks?: NetworkConfig[];
10
10
  defaultNetworkId?: string | number;
11
11
  }
12
12
  export declare class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, ProviderMessageRequestHandler {
@@ -20,7 +20,7 @@ export declare class WalletRequestHandler implements ExternalProvider, JsonRpcHa
20
20
  private _defaultNetworkId?;
21
21
  private _chainId?;
22
22
  private events;
23
- constructor(signer: Signer | null | undefined, prompter: WalletUserPrompter | null, mainnetNetworks: Networks, testnetNetworks?: Networks);
23
+ constructor(signer: Signer | null | undefined, prompter: WalletUserPrompter | null, mainnetNetworks: NetworkConfig[], testnetNetworks?: NetworkConfig[]);
24
24
  signIn(signer: Signer | null, options?: WalletSignInOptions): Promise<void>;
25
25
  signOut(): void;
26
26
  signerReset(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xsequence/provider",
3
- "version": "0.36.11",
3
+ "version": "0.37.0",
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",
@@ -13,13 +13,13 @@
13
13
  "typecheck": "tsc --noEmit"
14
14
  },
15
15
  "dependencies": {
16
- "@0xsequence/abi": "^0.36.11",
17
- "@0xsequence/auth": "^0.36.11",
18
- "@0xsequence/config": "^0.36.11",
19
- "@0xsequence/network": "^0.36.11",
20
- "@0xsequence/transactions": "^0.36.11",
21
- "@0xsequence/utils": "^0.36.11",
22
- "@0xsequence/wallet": "^0.36.11",
16
+ "@0xsequence/abi": "^0.37.0",
17
+ "@0xsequence/auth": "^0.37.0",
18
+ "@0xsequence/config": "^0.37.0",
19
+ "@0xsequence/network": "^0.37.0",
20
+ "@0xsequence/transactions": "^0.37.0",
21
+ "@0xsequence/utils": "^0.37.0",
22
+ "@0xsequence/wallet": "^0.37.0",
23
23
  "@ethersproject/abstract-signer": "^5.5.0",
24
24
  "@ethersproject/hash": "^5.5.0",
25
25
  "@ethersproject/providers": "^5.5.1",
package/src/provider.ts CHANGED
@@ -4,7 +4,6 @@ import { Web3Provider as EthersWeb3Provider, ExternalProvider, JsonRpcProvider,
4
4
  import { TypedDataDomain, TypedDataField, TypedDataSigner } from '@ethersproject/abstract-signer'
5
5
  import {
6
6
  NetworkConfig,
7
- Networks,
8
7
  WalletContext,
9
8
  ChainIdLike,
10
9
  JsonRpcHandler,
@@ -90,7 +89,7 @@ export function isSequenceProvider(provider: any): provider is Web3Provider {
90
89
  }
91
90
 
92
91
  export class LocalWeb3Provider extends Web3Provider {
93
- constructor(signer: Signer, networks?: Networks) {
92
+ constructor(signer: Signer, networks?: NetworkConfig[]) {
94
93
  const walletRequestHandler = new WalletRequestHandler(signer, null, networks || [])
95
94
  super(walletRequestHandler)
96
95
  }
@@ -293,17 +292,17 @@ export class Web3Signer extends Signer implements TypedDataSigner {
293
292
  // sendTransactionBatch is a convenience method to call sendTransaction in a batch format, allowing you to
294
293
  // send multiple transaction as a single payload and just one on-chain transaction.
295
294
  async sendTransactionBatch(
296
- transactions: Deferrable<Forbid<TransactionRequest, "wait">[]>,
295
+ transactions: Deferrable<Forbid<TransactionRequest, 'wait'>[]>,
297
296
  chainId?: ChainIdLike,
298
297
  allSigners?: boolean
299
298
  ): Promise<TransactionResponse> {
300
- const batch = await resolveArrayProperties<Forbid<TransactionRequest, "wait">[]>(transactions)
299
+ const batch = await resolveArrayProperties<Forbid<TransactionRequest, 'wait'>[]>(transactions)
301
300
  if (!batch || batch.length === 0) {
302
301
  throw new Error('cannot send empty batch')
303
302
  }
304
303
 
305
304
  // sendTransactionBatch only accepts TransactionRequest, not TransactionResponses
306
- if (batch.find((v) => v.wait !== undefined && v.wait !== null)) {
305
+ if (batch.find(v => v.wait !== undefined && v.wait !== null)) {
307
306
  throw new Error('transaction request expected for sendTransactionBatch, transaction response found')
308
307
  }
309
308
 
@@ -66,7 +66,7 @@ export abstract class BaseWalletTransport implements WalletTransport {
66
66
  if (!networks || networks.length === 0) {
67
67
  this.notifyChainChanged('0x0')
68
68
  } else {
69
- this.notifyChainChanged(ethers.utils.hexlify(networks[0].chainId))
69
+ this.notifyChainChanged(ethers.utils.hexlify(networks.find(network => network.isDefaultChain)!.chainId))
70
70
  }
71
71
  })
72
72
 
@@ -19,14 +19,7 @@ import {
19
19
  import { BigNumber, ethers } from 'ethers'
20
20
  import { ExternalProvider } from '@ethersproject/providers'
21
21
 
22
- import {
23
- Networks,
24
- NetworkConfig,
25
- JsonRpcHandler,
26
- JsonRpcRequest,
27
- JsonRpcResponseCallback,
28
- JsonRpcResponse
29
- } from '@0xsequence/network'
22
+ import { NetworkConfig, JsonRpcHandler, JsonRpcRequest, JsonRpcResponseCallback, JsonRpcResponse } from '@0xsequence/network'
30
23
  import { Signer } from '@0xsequence/wallet'
31
24
  import { isSignedTransactions, TransactionRequest } from '@0xsequence/transactions'
32
25
  import { signAuthorization, AuthorizationOptions } from '@0xsequence/auth'
@@ -38,8 +31,8 @@ const SIGNER_READY_TIMEOUT = 10000
38
31
 
39
32
  export interface WalletSignInOptions {
40
33
  connect?: boolean
41
- mainnetNetworks?: Networks
42
- testnetNetworks?: Networks
34
+ mainnetNetworks?: NetworkConfig[]
35
+ testnetNetworks?: NetworkConfig[]
43
36
  defaultNetworkId?: string | number
44
37
  }
45
38
 
@@ -64,8 +57,8 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
64
57
  constructor(
65
58
  signer: Signer | null | undefined,
66
59
  prompter: WalletUserPrompter | null,
67
- mainnetNetworks: Networks,
68
- testnetNetworks: Networks = []
60
+ mainnetNetworks: NetworkConfig[],
61
+ testnetNetworks: NetworkConfig[] = []
69
62
  ) {
70
63
  this.signer = signer
71
64
  this.prompter = prompter
@@ -725,8 +718,11 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
725
718
  async notifyNetworks(networks?: NetworkConfig[]) {
726
719
  const n = networks || (await this.getNetworks(true))
727
720
  this.events.emit('networks', n)
728
- if (n && n.length > 0) {
729
- this.events.emit('chainChanged', ethers.utils.hexlify(n[0].chainId))
721
+ if (n.length > 0) {
722
+ const defaultNetwork = n.find(network => network.isDefaultChain)
723
+ if (defaultNetwork) {
724
+ this.events.emit('chainChanged', ethers.utils.hexlify(defaultNetwork.chainId))
725
+ }
730
726
  } else {
731
727
  this.events.emit('chainChanged', '0x0')
732
728
  }
package/src/wallet.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import {
2
- Networks,
3
2
  NetworkConfig,
4
3
  WalletContext,
5
4
  sequenceContext,
@@ -143,7 +142,7 @@ export class Wallet implements WalletProvider {
143
142
  this.transport.extensionMessageProvider = new ExtensionMessageProvider(this.config.transports.extensionTransport.runtime)
144
143
  // this.transport.extensionMessageProvider.register()
145
144
  this.transport.messageProvider.add(this.transport.extensionMessageProvider)
146
-
145
+
147
146
  // NOTE/REVIEW: see note in mux-message-provider
148
147
  //
149
148
  // We don't add the extensionMessageProvider here because we don't send requests to it anyways, we seem to
@@ -171,7 +170,7 @@ export class Wallet implements WalletProvider {
171
170
  if (!this.networks || this.networks.length === 0) return 0
172
171
 
173
172
  // return the default chainId as we're connected
174
- return this.networks[0].chainId
173
+ return this.networks.find(network => network.isDefaultChain)!.chainId
175
174
  })
176
175
 
177
176
  // Provider proxy to support middleware stack of logging, caching and read-only rpc calls
@@ -379,11 +378,13 @@ export class Wallet implements WalletProvider {
379
378
  if (!this.networks || this.networks.length < 1) {
380
379
  throw new Error('networks have not been set by session. connect first.')
381
380
  }
382
- // default chain id is first one in the list, by design
383
- const network = this.networks[0]
384
- if (!network.isDefaultChain) {
385
- throw new Error('expecting first network in list to be default chain')
381
+
382
+ const network = this.networks.find(network => network.isDefaultChain)
383
+
384
+ if (!network) {
385
+ throw new Error('networks must have a default chain specified')
386
386
  }
387
+
387
388
  return network.chainId
388
389
  }
389
390
 
@@ -391,18 +392,14 @@ export class Wallet implements WalletProvider {
391
392
  if (!this.networks || this.networks.length < 1) {
392
393
  throw new Error('networks have not been set by session. connect first.')
393
394
  }
394
- // auth chain is first or second one in the list, by design
395
- const network0 = this.networks[0]
396
- if (network0.isAuthChain) {
397
- return network0.chainId
398
- }
399
- if (this.networks.length > 1) {
400
- const network1 = this.networks[1]
401
- if (network1.isAuthChain) {
402
- return network1.chainId
403
- }
395
+
396
+ const network = this.networks.find(network => network.isAuthChain)
397
+
398
+ if (!network) {
399
+ throw new Error('networks must have an auth chain specified')
404
400
  }
405
- throw new Error('expecting first or second network in list to be the auth chain')
401
+
402
+ return network.chainId
406
403
  }
407
404
 
408
405
  openWallet = async (path?: string, intent?: OpenWalletIntent, networkId?: string | number): Promise<boolean> => {
@@ -439,7 +436,7 @@ export class Wallet implements WalletProvider {
439
436
  }
440
437
  }
441
438
 
442
- let network: NetworkConfig | undefined = this.networks[0]
439
+ let network: NetworkConfig | undefined = this.networks.find(network => network.isDefaultChain)!
443
440
  if (chainId) {
444
441
  network = findNetworkConfig(this.networks, chainId)
445
442
  if (!network) {
@@ -628,7 +625,7 @@ export class Wallet implements WalletProvider {
628
625
 
629
626
  // an extra override for convenience
630
627
  if (this.config.networkRpcUrl) {
631
- this.networks[0].rpcUrl = this.config.networkRpcUrl
628
+ this.networks.find(network => network.isDefaultChain)!.rpcUrl = this.config.networkRpcUrl
632
629
  }
633
630
  }
634
631