@@ -27,52 +27,45 @@ export default class WebClient extends Client {
2727 */
2828 constructor ( props ) {
2929 super ( props ) ;
30+
3031 if ( props != null ) {
3132 if ( typeof props . network === "string" ) {
32- switch ( props . network ) {
33+ this . _setNetworkFromName ( props . network ) ;
34+ } else if ( props . network != null ) {
35+ Client . _validateNetworkConsistency ( props . network ) ;
36+
37+ const { shard, realm } = Client . _extractShardRealm (
38+ props . network ,
39+ ) ;
40+
41+ // Shard and realm are inferred from the network, so we need to set them here
42+ // to ensure that the client is properly configured.
43+ this . _shard = shard ;
44+ this . _realm = realm ;
45+
46+ this . setNetwork ( props . network ) ;
47+ }
48+
49+ if ( typeof props . mirrorNetwork === "string" ) {
50+ switch ( props . mirrorNetwork ) {
3351 case "mainnet" :
34- this . setNetwork ( WebNetwork . MAINNET ) ;
3552 this . setMirrorNetwork ( WebMirrorNetwork . MAINNET ) ;
36- this . setLedgerId ( LedgerId . MAINNET ) ;
3753 break ;
3854
3955 case "testnet" :
40- this . setNetwork ( WebNetwork . TESTNET ) ;
41- this . setLedgerId ( LedgerId . TESTNET ) ;
4256 this . setMirrorNetwork ( WebMirrorNetwork . TESTNET ) ;
4357 break ;
4458
4559 case "previewnet" :
46- this . setNetwork ( WebNetwork . PREVIEWNET ) ;
47- this . setLedgerId ( LedgerId . PREVIEWNET ) ;
4860 this . setMirrorNetwork ( WebMirrorNetwork . PREVIEWNET ) ;
4961 break ;
5062
51- case "local-node" :
52- this . setNetwork ( WebNetwork . LOCAL_NODE ) ;
53- this . setLedgerId ( LedgerId . LOCAL_NODE ) ;
54- this . setMirrorNetwork ( WebMirrorNetwork . LOCAL_NODE ) ;
55- break ;
56-
5763 default :
58- throw new Error (
59- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
60- `unknown network: ${ props . network } ` ,
61- ) ;
64+ this . setMirrorNetwork ( [ props . mirrorNetwork ] ) ;
65+ break ;
6266 }
63- } else if ( props . network != null ) {
64- Client . _validateNetworkConsistency ( props . network ) ;
65-
66- const { shard, realm } = Client . _extractShardRealm (
67- props . network ,
68- ) ;
69-
70- // Shard and realm are inferred from the network, so we need to set them here
71- // to ensure that the client is properly configured.
72- this . _shard = shard ;
73- this . _realm = realm ;
74-
75- this . setNetwork ( props . network ) ;
67+ } else if ( props . mirrorNetwork != null ) {
68+ this . setMirrorNetwork ( props . mirrorNetwork ) ;
7669 }
7770 }
7871 }
@@ -295,6 +288,46 @@ export default class WebClient extends Client {
295288 return this ;
296289 }
297290
291+ /**
292+ * @private
293+ * @param {string } name
294+ * @returns {this }
295+ */
296+ _setNetworkFromName ( name ) {
297+ switch ( name ) {
298+ case "mainnet" :
299+ this . setNetwork ( WebNetwork . MAINNET ) ;
300+ this . setMirrorNetwork ( WebMirrorNetwork . MAINNET ) ;
301+ this . setLedgerId ( LedgerId . MAINNET ) ;
302+ break ;
303+
304+ case "testnet" :
305+ this . setNetwork ( WebNetwork . TESTNET ) ;
306+ this . setMirrorNetwork ( WebMirrorNetwork . TESTNET ) ;
307+ this . setLedgerId ( LedgerId . TESTNET ) ;
308+ break ;
309+
310+ case "previewnet" :
311+ this . setNetwork ( WebNetwork . PREVIEWNET ) ;
312+ this . setMirrorNetwork ( WebMirrorNetwork . PREVIEWNET ) ;
313+ this . setLedgerId ( LedgerId . PREVIEWNET ) ;
314+ break ;
315+
316+ case "local-node" :
317+ this . setNetwork ( WebNetwork . LOCAL_NODE ) ;
318+ this . setMirrorNetwork ( WebMirrorNetwork . LOCAL_NODE ) ;
319+ this . setLedgerId ( LedgerId . LOCAL_NODE ) ;
320+ break ;
321+
322+ default :
323+ throw new Error (
324+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
325+ `unknown network: ${ name } ` ,
326+ ) ;
327+ }
328+ return this ;
329+ }
330+
298331 /**
299332 * @override
300333 * @returns {Promise<this> }
0 commit comments