-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathindex.ts
112 lines (103 loc) · 4.17 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { MultichainNetworkControllerState } from '@metamask/multichain-network-controller';
import { RootState } from '../../reducers';
import { createSelector } from 'reselect';
import { CaipChainId } from '@metamask/utils';
import { BtcScope, SolScope } from '@metamask/keyring-api';
import imageIcons from '../../images/image-icons';
import { ImageSourcePropType } from 'react-native';
export const selectMultichainNetworkControllerState = (state: RootState) =>
state.engine.backgroundState?.MultichainNetworkController;
export const selectIsEvmNetworkSelected = createSelector(
selectMultichainNetworkControllerState,
(multichainNetworkControllerState: MultichainNetworkControllerState) =>
multichainNetworkControllerState.isEvmSelected,
);
export const selectSelectedNonEvmNetworkChainId = createSelector(
selectMultichainNetworkControllerState,
(multichainNetworkControllerState: MultichainNetworkControllerState) =>
multichainNetworkControllerState.selectedMultichainNetworkChainId,
);
/**
* This selector is used to get the non-EVM network configurations by chain ID.
* It extends the network configurations with additional data for non-EVM networks that doens't have a source of truth source yet.
*
* @param state - The root state object.
* @returns An object where the keys are chain IDs and the values are network configurations.
*/
export const selectNonEvmNetworkConfigurationsByChainId = createSelector(
selectMultichainNetworkControllerState,
(multichainNetworkControllerState: MultichainNetworkControllerState) => {
const extendedNonEvmData: Record<
CaipChainId,
{
decimals: number;
imageSource: ImageSourcePropType;
ticker: string;
}
> = {
[SolScope.Mainnet]: {
decimals: 9,
imageSource: imageIcons.SOLANA,
ticker: 'SOL',
},
[BtcScope.Mainnet]: {
decimals: 8,
imageSource: imageIcons.BTC,
ticker: 'BTC',
},
};
return Object.fromEntries(
Object.entries(
multichainNetworkControllerState.multichainNetworkConfigurationsByChainId ||
{},
).map(([key, network]) => [
key,
{ ...network, ...extendedNonEvmData[network.chainId] },
]),
);
},
);
export const selectSelectedNonEvmNetworkDecimals = createSelector(
selectNonEvmNetworkConfigurationsByChainId,
selectSelectedNonEvmNetworkChainId,
(nonEvmNetworkConfigurationsByChainId, selectedMultichainNetworkChainId) =>
nonEvmNetworkConfigurationsByChainId[selectedMultichainNetworkChainId]
?.decimals,
);
export const selectSelectedNonEvmNetworkName = createSelector(
selectNonEvmNetworkConfigurationsByChainId,
selectSelectedNonEvmNetworkChainId,
(nonEvmNetworkConfigurationsByChainId, selectedMultichainNetworkChainId) => {
const network =
nonEvmNetworkConfigurationsByChainId[selectedMultichainNetworkChainId];
return network?.name;
},
);
export const selectSelectedNonEvmNativeCurrency = createSelector(
selectNonEvmNetworkConfigurationsByChainId,
selectSelectedNonEvmNetworkChainId,
(nonEvmNetworkConfigurationsByChainId, selectedMultichainNetworkChainId) => {
const network =
nonEvmNetworkConfigurationsByChainId[selectedMultichainNetworkChainId];
return network?.nativeCurrency;
},
);
export const selectSelectedNonEvmNetworkSymbol = createSelector(
selectSelectedNonEvmNetworkChainId,
selectNonEvmNetworkConfigurationsByChainId,
(selectedMultichainNetworkChainId, nonEvmNetworkConfigurationsByChainId) =>
nonEvmNetworkConfigurationsByChainId[selectedMultichainNetworkChainId]
?.ticker,
);
/**
* This selector is used to get the accounts with activity for EVM networks.
*
* @param state - The root state object.
* @returns An object where the keys are hex addresses and the values contain the namespace and an array of active chain IDs for that address.
* @returns {ActiveNetworksByAddress} Object mapping hex addresses to their network activity status.
*/
export const selectNetworksWithActivity = createSelector(
selectMultichainNetworkControllerState,
(multichainNetworkControllerState: MultichainNetworkControllerState) =>
multichainNetworkControllerState.networksWithTransactionActivity,
);