1- const { isMainnet, isTestnet } = global . environment ;
1+ // @flow
2+ import { get , map } from 'lodash' ;
3+ import { NetworkMagics } from '../../../common/types/cardano-node.types' ;
4+ import type { NetworkMagicType } from '../../../common/types/cardano-node.types' ;
5+ import type { Network } from '../../../common/types/environment.types' ;
26
37export const HARDENED_HEX = 0x80000000 ;
48export const HARDENED = 2147483648 ;
@@ -7,25 +11,18 @@ export const BYRON_PURPOSE_INDEX = 44;
711export const ADA_COIN_TYPE = 1815 ;
812export const DEFAULT_ADDRESS_INDEX = 0 ;
913
14+ const { isMainnet, isStaging, isSelfnode } = global . environment ;
15+ const hardwareWalletNetworksConfig = { } ;
16+ map ( NetworkMagics , ( networkMagic : NetworkMagicType , network : Network ) => {
17+ const isMainnetLikeNetwork = isMainnet || isSelfnode || isStaging ;
18+ hardwareWalletNetworksConfig [ network ] = {
19+ networkId : isMainnetLikeNetwork ? 1 : networkMagic [ 1 ] ,
20+ protocolMagic : isMainnetLikeNetwork ? 764824073 : networkMagic [ 0 ] ,
21+ } ;
22+ } ) ;
23+
1024export const HW_SHELLEY_CONFIG = {
11- NETWORK : {
12- MAINNET : {
13- name : 'mainnet' ,
14- networkId : 1 ,
15- protocolMagic : 764824073 ,
16- trezorProtocolMagic : 764824073 ,
17- eraStartSlot : 4492800 ,
18- ttl : 3600 ,
19- } ,
20- TESTNET : {
21- name : 'testnet' ,
22- networkId : 0 ,
23- protocolMagic : 1097911063 ,
24- trezorProtocolMagic : 1097911063 ,
25- eraStartSlot : 4492800 ,
26- ttl : 3600 ,
27- } ,
28- } ,
25+ NETWORK : hardwareWalletNetworksConfig ,
2926 DEFAULT_DERIVATION_PATH : [
3027 HARDENED + SHELLEY_PURPOSE_INDEX ,
3128 HARDENED + ADA_COIN_TYPE ,
@@ -41,13 +38,7 @@ export const HW_SHELLEY_CONFIG = {
4138} ;
4239
4340export const HW_BYRON_CONFIG = {
44- NETWORK : {
45- MAINNET : {
46- name : 'mainnet' ,
47- networkId : 1 ,
48- protocolMagic : 764824073 ,
49- } ,
50- } ,
41+ NETWORK : hardwareWalletNetworksConfig ,
5142 DEFAULT_DERIVATION_PATH : [
5243 HARDENED + BYRON_PURPOSE_INDEX ,
5344 HARDENED + ADA_COIN_TYPE ,
@@ -80,6 +71,11 @@ export const isTrezorEnabled = true;
8071export const isLedgerEnabled = true ;
8172
8273export const isHardwareWalletSupportEnabled =
83- ( isMainnet || isTestnet ) && ( isTrezorEnabled || isLedgerEnabled ) ;
74+ isTrezorEnabled || isLedgerEnabled ;
8475
8576export const isHardwareWalletIndicatorEnabled = false ;
77+
78+ export const getHardwareWalletsNetworkConfig = ( network : Network ) => {
79+ const networkConfig = get ( HW_SHELLEY_CONFIG , [ 'NETWORK' , network ] , { } ) ;
80+ return networkConfig ;
81+ } ;
0 commit comments