@metamask-previews/network-enablement-controller 0.1.0-preview-037d305

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +20 -0
  3. package/README.md +182 -0
  4. package/dist/NetworkEnablementController.cjs +178 -0
  5. package/dist/NetworkEnablementController.cjs.map +1 -0
  6. package/dist/NetworkEnablementController.d.cts +102 -0
  7. package/dist/NetworkEnablementController.d.cts.map +1 -0
  8. package/dist/NetworkEnablementController.d.mts +102 -0
  9. package/dist/NetworkEnablementController.d.mts.map +1 -0
  10. package/dist/NetworkEnablementController.mjs +174 -0
  11. package/dist/NetworkEnablementController.mjs.map +1 -0
  12. package/dist/constants.cjs +16 -0
  13. package/dist/constants.cjs.map +1 -0
  14. package/dist/constants.d.cts +2 -0
  15. package/dist/constants.d.cts.map +1 -0
  16. package/dist/constants.d.mts +2 -0
  17. package/dist/constants.d.mts.map +1 -0
  18. package/dist/constants.mjs +13 -0
  19. package/dist/constants.mjs.map +1 -0
  20. package/dist/index.cjs +14 -0
  21. package/dist/index.cjs.map +1 -0
  22. package/dist/index.d.cts +4 -0
  23. package/dist/index.d.cts.map +1 -0
  24. package/dist/index.d.mts +4 -0
  25. package/dist/index.d.mts.map +1 -0
  26. package/dist/index.mjs +3 -0
  27. package/dist/index.mjs.map +1 -0
  28. package/dist/selectors.cjs +87 -0
  29. package/dist/selectors.cjs.map +1 -0
  30. package/dist/selectors.d.cts +280 -0
  31. package/dist/selectors.d.cts.map +1 -0
  32. package/dist/selectors.d.mts +280 -0
  33. package/dist/selectors.d.mts.map +1 -0
  34. package/dist/selectors.mjs +81 -0
  35. package/dist/selectors.mjs.map +1 -0
  36. package/dist/types.cjs +13 -0
  37. package/dist/types.cjs.map +1 -0
  38. package/dist/types.d.cts +9 -0
  39. package/dist/types.d.cts.map +1 -0
  40. package/dist/types.d.mts +9 -0
  41. package/dist/types.d.mts.map +1 -0
  42. package/dist/types.mjs +10 -0
  43. package/dist/types.mjs.map +1 -0
  44. package/dist/utils.cjs +80 -0
  45. package/dist/utils.cjs.map +1 -0
  46. package/dist/utils.d.cts +43 -0
  47. package/dist/utils.d.cts.map +1 -0
  48. package/dist/utils.d.mts +43 -0
  49. package/dist/utils.d.mts.map +1 -0
  50. package/dist/utils.mjs +74 -0
  51. package/dist/utils.mjs.map +1 -0
  52. package/package.json +79 -0
@@ -0,0 +1,280 @@
1
+ import type { CaipChainId, CaipNamespace, Hex } from "@metamask/utils";
2
+ import type { NetworkEnablementControllerState } from "./NetworkEnablementController.cjs";
3
+ /**
4
+ * Base selector to get the enabled network map from the controller state.
5
+ *
6
+ * @param state - The NetworkEnablementController state
7
+ * @returns The enabled network map
8
+ */
9
+ export declare const selectEnabledNetworkMap: (state: NetworkEnablementControllerState) => {
10
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
11
+ };
12
+ /**
13
+ * Selector to check if a specific network is enabled.
14
+ *
15
+ * This selector accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID
16
+ * (for any blockchain network) and returns whether the network is currently enabled.
17
+ * It returns false for unknown networks or if there's an error parsing the chain ID.
18
+ *
19
+ * @param chainId - The chain ID to check (Hex or CAIP-2 format)
20
+ * @returns A selector function that returns true if the network is enabled, false otherwise
21
+ */
22
+ export declare const selectIsNetworkEnabled: (chainId: Hex | CaipChainId) => ((state: NetworkEnablementControllerState) => boolean) & {
23
+ clearCache: () => void;
24
+ resultsCount: () => number;
25
+ resetResultsCount: () => void;
26
+ } & {
27
+ resultFunc: (resultFuncArgs_0: {
28
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
29
+ }) => boolean;
30
+ memoizedResultFunc: ((resultFuncArgs_0: {
31
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
32
+ }) => boolean) & {
33
+ clearCache: () => void;
34
+ resultsCount: () => number;
35
+ resetResultsCount: () => void;
36
+ };
37
+ lastResult: () => boolean;
38
+ dependencies: [(state: NetworkEnablementControllerState) => {
39
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
40
+ }];
41
+ recomputations: () => number;
42
+ resetRecomputations: () => void;
43
+ dependencyRecomputations: () => number;
44
+ resetDependencyRecomputations: () => void;
45
+ } & {
46
+ argsMemoize: typeof import("reselect").weakMapMemoize;
47
+ memoize: typeof import("reselect").weakMapMemoize;
48
+ };
49
+ /**
50
+ * Selector builder to get all enabled networks for a specific namespace.
51
+ *
52
+ * The selector returned by this function returns an array of chain IDs (as strings) for all enabled networks
53
+ * within the specified namespace (e.g., 'eip155' for EVM networks, 'solana' for Solana).
54
+ *
55
+ * @param namespace - The CAIP namespace to get enabled networks for (e.g., 'eip155', 'solana')
56
+ * @returns A selector function that returns an array of chain ID strings for enabled networks in the namespace
57
+ */
58
+ export declare const createSelectorForEnabledNetworksForNamespace: (namespace: CaipNamespace) => ((state: NetworkEnablementControllerState) => string[]) & {
59
+ clearCache: () => void;
60
+ resultsCount: () => number;
61
+ resetResultsCount: () => void;
62
+ } & {
63
+ resultFunc: (resultFuncArgs_0: {
64
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
65
+ }) => string[];
66
+ memoizedResultFunc: ((resultFuncArgs_0: {
67
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
68
+ }) => string[]) & {
69
+ clearCache: () => void;
70
+ resultsCount: () => number;
71
+ resetResultsCount: () => void;
72
+ };
73
+ lastResult: () => string[];
74
+ dependencies: [(state: NetworkEnablementControllerState) => {
75
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
76
+ }];
77
+ recomputations: () => number;
78
+ resetRecomputations: () => void;
79
+ dependencyRecomputations: () => number;
80
+ resetDependencyRecomputations: () => void;
81
+ } & {
82
+ argsMemoize: typeof import("reselect").weakMapMemoize;
83
+ memoize: typeof import("reselect").weakMapMemoize;
84
+ };
85
+ /**
86
+ * Selector to get all enabled networks across all namespaces.
87
+ *
88
+ * This selector returns a record where keys are CAIP namespaces and values are arrays
89
+ * of enabled chain IDs within each namespace.
90
+ *
91
+ * @returns A selector function that returns a record mapping namespace to array of enabled chain IDs
92
+ */
93
+ export declare const selectAllEnabledNetworks: ((state: NetworkEnablementControllerState) => Record<string, string[]>) & {
94
+ clearCache: () => void;
95
+ resultsCount: () => number;
96
+ resetResultsCount: () => void;
97
+ } & {
98
+ resultFunc: (resultFuncArgs_0: {
99
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
100
+ }) => Record<string, string[]>;
101
+ memoizedResultFunc: ((resultFuncArgs_0: {
102
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
103
+ }) => Record<string, string[]>) & {
104
+ clearCache: () => void;
105
+ resultsCount: () => number;
106
+ resetResultsCount: () => void;
107
+ };
108
+ lastResult: () => Record<string, string[]>;
109
+ dependencies: [(state: NetworkEnablementControllerState) => {
110
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
111
+ }];
112
+ recomputations: () => number;
113
+ resetRecomputations: () => void;
114
+ dependencyRecomputations: () => number;
115
+ resetDependencyRecomputations: () => void;
116
+ } & {
117
+ argsMemoize: typeof import("reselect").weakMapMemoize;
118
+ memoize: typeof import("reselect").weakMapMemoize;
119
+ };
120
+ /**
121
+ * Selector to get the total count of enabled networks across all namespaces.
122
+ *
123
+ * @returns A selector function that returns the total number of enabled networks
124
+ */
125
+ export declare const selectEnabledNetworksCount: ((state: NetworkEnablementControllerState) => number) & {
126
+ clearCache: () => void;
127
+ resultsCount: () => number;
128
+ resetResultsCount: () => void;
129
+ } & {
130
+ resultFunc: (resultFuncArgs_0: Record<string, string[]>) => number;
131
+ memoizedResultFunc: ((resultFuncArgs_0: Record<string, string[]>) => number) & {
132
+ clearCache: () => void;
133
+ resultsCount: () => number;
134
+ resetResultsCount: () => void;
135
+ };
136
+ lastResult: () => number;
137
+ dependencies: [((state: NetworkEnablementControllerState) => Record<string, string[]>) & {
138
+ clearCache: () => void;
139
+ resultsCount: () => number;
140
+ resetResultsCount: () => void;
141
+ } & {
142
+ resultFunc: (resultFuncArgs_0: {
143
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
144
+ }) => Record<string, string[]>;
145
+ memoizedResultFunc: ((resultFuncArgs_0: {
146
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
147
+ }) => Record<string, string[]>) & {
148
+ clearCache: () => void;
149
+ resultsCount: () => number;
150
+ resetResultsCount: () => void;
151
+ };
152
+ lastResult: () => Record<string, string[]>;
153
+ dependencies: [(state: NetworkEnablementControllerState) => {
154
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
155
+ }];
156
+ recomputations: () => number;
157
+ resetRecomputations: () => void;
158
+ dependencyRecomputations: () => number;
159
+ resetDependencyRecomputations: () => void;
160
+ } & {
161
+ argsMemoize: typeof import("reselect").weakMapMemoize;
162
+ memoize: typeof import("reselect").weakMapMemoize;
163
+ }];
164
+ recomputations: () => number;
165
+ resetRecomputations: () => void;
166
+ dependencyRecomputations: () => number;
167
+ resetDependencyRecomputations: () => void;
168
+ } & {
169
+ argsMemoize: typeof import("reselect").weakMapMemoize;
170
+ memoize: typeof import("reselect").weakMapMemoize;
171
+ };
172
+ /**
173
+ * Selector to get all enabled EVM networks.
174
+ *
175
+ * This is a convenience selector that specifically targets EIP-155 networks.
176
+ *
177
+ * @returns A selector function that returns an array of enabled EVM chain IDs
178
+ */
179
+ export declare const selectEnabledEvmNetworks: ((state: NetworkEnablementControllerState) => string[]) & {
180
+ clearCache: () => void;
181
+ resultsCount: () => number;
182
+ resetResultsCount: () => void;
183
+ } & {
184
+ resultFunc: (resultFuncArgs_0: string[]) => string[];
185
+ memoizedResultFunc: ((resultFuncArgs_0: string[]) => string[]) & {
186
+ clearCache: () => void;
187
+ resultsCount: () => number;
188
+ resetResultsCount: () => void;
189
+ };
190
+ lastResult: () => string[];
191
+ dependencies: [((state: NetworkEnablementControllerState) => string[]) & {
192
+ clearCache: () => void;
193
+ resultsCount: () => number;
194
+ resetResultsCount: () => void;
195
+ } & {
196
+ resultFunc: (resultFuncArgs_0: {
197
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
198
+ }) => string[];
199
+ memoizedResultFunc: ((resultFuncArgs_0: {
200
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
201
+ }) => string[]) & {
202
+ clearCache: () => void;
203
+ resultsCount: () => number;
204
+ resetResultsCount: () => void;
205
+ };
206
+ lastResult: () => string[];
207
+ dependencies: [(state: NetworkEnablementControllerState) => {
208
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
209
+ }];
210
+ recomputations: () => number;
211
+ resetRecomputations: () => void;
212
+ dependencyRecomputations: () => number;
213
+ resetDependencyRecomputations: () => void;
214
+ } & {
215
+ argsMemoize: typeof import("reselect").weakMapMemoize;
216
+ memoize: typeof import("reselect").weakMapMemoize;
217
+ }];
218
+ recomputations: () => number;
219
+ resetRecomputations: () => void;
220
+ dependencyRecomputations: () => number;
221
+ resetDependencyRecomputations: () => void;
222
+ } & {
223
+ argsMemoize: typeof import("reselect").weakMapMemoize;
224
+ memoize: typeof import("reselect").weakMapMemoize;
225
+ };
226
+ /**
227
+ * Selector to get all enabled Solana networks.
228
+ *
229
+ * This is a convenience selector that specifically targets Solana networks.
230
+ *
231
+ * @returns A selector function that returns an array of enabled Solana chain IDs
232
+ */
233
+ export declare const selectEnabledSolanaNetworks: ((state: NetworkEnablementControllerState) => string[]) & {
234
+ clearCache: () => void;
235
+ resultsCount: () => number;
236
+ resetResultsCount: () => void;
237
+ } & {
238
+ resultFunc: (resultFuncArgs_0: string[]) => string[];
239
+ memoizedResultFunc: ((resultFuncArgs_0: string[]) => string[]) & {
240
+ clearCache: () => void;
241
+ resultsCount: () => number;
242
+ resetResultsCount: () => void;
243
+ };
244
+ lastResult: () => string[];
245
+ dependencies: [((state: NetworkEnablementControllerState) => string[]) & {
246
+ clearCache: () => void;
247
+ resultsCount: () => number;
248
+ resetResultsCount: () => void;
249
+ } & {
250
+ resultFunc: (resultFuncArgs_0: {
251
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
252
+ }) => string[];
253
+ memoizedResultFunc: ((resultFuncArgs_0: {
254
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
255
+ }) => string[]) & {
256
+ clearCache: () => void;
257
+ resultsCount: () => number;
258
+ resetResultsCount: () => void;
259
+ };
260
+ lastResult: () => string[];
261
+ dependencies: [(state: NetworkEnablementControllerState) => {
262
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
263
+ }];
264
+ recomputations: () => number;
265
+ resetRecomputations: () => void;
266
+ dependencyRecomputations: () => number;
267
+ resetDependencyRecomputations: () => void;
268
+ } & {
269
+ argsMemoize: typeof import("reselect").weakMapMemoize;
270
+ memoize: typeof import("reselect").weakMapMemoize;
271
+ }];
272
+ recomputations: () => number;
273
+ resetRecomputations: () => void;
274
+ dependencyRecomputations: () => number;
275
+ resetDependencyRecomputations: () => void;
276
+ } & {
277
+ argsMemoize: typeof import("reselect").weakMapMemoize;
278
+ memoize: typeof import("reselect").weakMapMemoize;
279
+ };
280
+ //# sourceMappingURL=selectors.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectors.d.cts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;AAIvE,OAAO,KAAK,EAAE,gCAAgC,EAAE,0CAAsC;AAGtF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,UAC3B,gCAAgC;;CACb,CAAC;AAE7B;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,YAAa,GAAG,GAAG,WAAW;;;;;;;;;;;;;;;;2BAbxD,gCAAgC;;;;;;;;;;CAsBrC,CAAC;AAEL;;;;;;;;GAQG;AACH,eAAO,MAAM,4CAA4C,cAC5C,aAAa;;;;;;;;;;;;;;;;2BAlCjB,gCAAgC;;;;;;;;;;CAwCrC,CAAC;AAEL;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;2BAlD5B,gCAAgC;;;;;;;;;;CA+DxC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAtE9B,gCAAgC;;;;;;;;;;;;;;;;;;CA2ExC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BApF5B,gCAAgC;;;;;;;;;;;;;;;;;;CAuFxC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAhG/B,gCAAgC;;;;;;;;;;;;;;;;;;CAmGxC,CAAC"}
@@ -0,0 +1,280 @@
1
+ import type { CaipChainId, CaipNamespace, Hex } from "@metamask/utils";
2
+ import type { NetworkEnablementControllerState } from "./NetworkEnablementController.mjs";
3
+ /**
4
+ * Base selector to get the enabled network map from the controller state.
5
+ *
6
+ * @param state - The NetworkEnablementController state
7
+ * @returns The enabled network map
8
+ */
9
+ export declare const selectEnabledNetworkMap: (state: NetworkEnablementControllerState) => {
10
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
11
+ };
12
+ /**
13
+ * Selector to check if a specific network is enabled.
14
+ *
15
+ * This selector accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID
16
+ * (for any blockchain network) and returns whether the network is currently enabled.
17
+ * It returns false for unknown networks or if there's an error parsing the chain ID.
18
+ *
19
+ * @param chainId - The chain ID to check (Hex or CAIP-2 format)
20
+ * @returns A selector function that returns true if the network is enabled, false otherwise
21
+ */
22
+ export declare const selectIsNetworkEnabled: (chainId: Hex | CaipChainId) => ((state: NetworkEnablementControllerState) => boolean) & {
23
+ clearCache: () => void;
24
+ resultsCount: () => number;
25
+ resetResultsCount: () => void;
26
+ } & {
27
+ resultFunc: (resultFuncArgs_0: {
28
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
29
+ }) => boolean;
30
+ memoizedResultFunc: ((resultFuncArgs_0: {
31
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
32
+ }) => boolean) & {
33
+ clearCache: () => void;
34
+ resultsCount: () => number;
35
+ resetResultsCount: () => void;
36
+ };
37
+ lastResult: () => boolean;
38
+ dependencies: [(state: NetworkEnablementControllerState) => {
39
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
40
+ }];
41
+ recomputations: () => number;
42
+ resetRecomputations: () => void;
43
+ dependencyRecomputations: () => number;
44
+ resetDependencyRecomputations: () => void;
45
+ } & {
46
+ argsMemoize: typeof import("reselect").weakMapMemoize;
47
+ memoize: typeof import("reselect").weakMapMemoize;
48
+ };
49
+ /**
50
+ * Selector builder to get all enabled networks for a specific namespace.
51
+ *
52
+ * The selector returned by this function returns an array of chain IDs (as strings) for all enabled networks
53
+ * within the specified namespace (e.g., 'eip155' for EVM networks, 'solana' for Solana).
54
+ *
55
+ * @param namespace - The CAIP namespace to get enabled networks for (e.g., 'eip155', 'solana')
56
+ * @returns A selector function that returns an array of chain ID strings for enabled networks in the namespace
57
+ */
58
+ export declare const createSelectorForEnabledNetworksForNamespace: (namespace: CaipNamespace) => ((state: NetworkEnablementControllerState) => string[]) & {
59
+ clearCache: () => void;
60
+ resultsCount: () => number;
61
+ resetResultsCount: () => void;
62
+ } & {
63
+ resultFunc: (resultFuncArgs_0: {
64
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
65
+ }) => string[];
66
+ memoizedResultFunc: ((resultFuncArgs_0: {
67
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
68
+ }) => string[]) & {
69
+ clearCache: () => void;
70
+ resultsCount: () => number;
71
+ resetResultsCount: () => void;
72
+ };
73
+ lastResult: () => string[];
74
+ dependencies: [(state: NetworkEnablementControllerState) => {
75
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
76
+ }];
77
+ recomputations: () => number;
78
+ resetRecomputations: () => void;
79
+ dependencyRecomputations: () => number;
80
+ resetDependencyRecomputations: () => void;
81
+ } & {
82
+ argsMemoize: typeof import("reselect").weakMapMemoize;
83
+ memoize: typeof import("reselect").weakMapMemoize;
84
+ };
85
+ /**
86
+ * Selector to get all enabled networks across all namespaces.
87
+ *
88
+ * This selector returns a record where keys are CAIP namespaces and values are arrays
89
+ * of enabled chain IDs within each namespace.
90
+ *
91
+ * @returns A selector function that returns a record mapping namespace to array of enabled chain IDs
92
+ */
93
+ export declare const selectAllEnabledNetworks: ((state: NetworkEnablementControllerState) => Record<string, string[]>) & {
94
+ clearCache: () => void;
95
+ resultsCount: () => number;
96
+ resetResultsCount: () => void;
97
+ } & {
98
+ resultFunc: (resultFuncArgs_0: {
99
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
100
+ }) => Record<string, string[]>;
101
+ memoizedResultFunc: ((resultFuncArgs_0: {
102
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
103
+ }) => Record<string, string[]>) & {
104
+ clearCache: () => void;
105
+ resultsCount: () => number;
106
+ resetResultsCount: () => void;
107
+ };
108
+ lastResult: () => Record<string, string[]>;
109
+ dependencies: [(state: NetworkEnablementControllerState) => {
110
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
111
+ }];
112
+ recomputations: () => number;
113
+ resetRecomputations: () => void;
114
+ dependencyRecomputations: () => number;
115
+ resetDependencyRecomputations: () => void;
116
+ } & {
117
+ argsMemoize: typeof import("reselect").weakMapMemoize;
118
+ memoize: typeof import("reselect").weakMapMemoize;
119
+ };
120
+ /**
121
+ * Selector to get the total count of enabled networks across all namespaces.
122
+ *
123
+ * @returns A selector function that returns the total number of enabled networks
124
+ */
125
+ export declare const selectEnabledNetworksCount: ((state: NetworkEnablementControllerState) => number) & {
126
+ clearCache: () => void;
127
+ resultsCount: () => number;
128
+ resetResultsCount: () => void;
129
+ } & {
130
+ resultFunc: (resultFuncArgs_0: Record<string, string[]>) => number;
131
+ memoizedResultFunc: ((resultFuncArgs_0: Record<string, string[]>) => number) & {
132
+ clearCache: () => void;
133
+ resultsCount: () => number;
134
+ resetResultsCount: () => void;
135
+ };
136
+ lastResult: () => number;
137
+ dependencies: [((state: NetworkEnablementControllerState) => Record<string, string[]>) & {
138
+ clearCache: () => void;
139
+ resultsCount: () => number;
140
+ resetResultsCount: () => void;
141
+ } & {
142
+ resultFunc: (resultFuncArgs_0: {
143
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
144
+ }) => Record<string, string[]>;
145
+ memoizedResultFunc: ((resultFuncArgs_0: {
146
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
147
+ }) => Record<string, string[]>) & {
148
+ clearCache: () => void;
149
+ resultsCount: () => number;
150
+ resetResultsCount: () => void;
151
+ };
152
+ lastResult: () => Record<string, string[]>;
153
+ dependencies: [(state: NetworkEnablementControllerState) => {
154
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
155
+ }];
156
+ recomputations: () => number;
157
+ resetRecomputations: () => void;
158
+ dependencyRecomputations: () => number;
159
+ resetDependencyRecomputations: () => void;
160
+ } & {
161
+ argsMemoize: typeof import("reselect").weakMapMemoize;
162
+ memoize: typeof import("reselect").weakMapMemoize;
163
+ }];
164
+ recomputations: () => number;
165
+ resetRecomputations: () => void;
166
+ dependencyRecomputations: () => number;
167
+ resetDependencyRecomputations: () => void;
168
+ } & {
169
+ argsMemoize: typeof import("reselect").weakMapMemoize;
170
+ memoize: typeof import("reselect").weakMapMemoize;
171
+ };
172
+ /**
173
+ * Selector to get all enabled EVM networks.
174
+ *
175
+ * This is a convenience selector that specifically targets EIP-155 networks.
176
+ *
177
+ * @returns A selector function that returns an array of enabled EVM chain IDs
178
+ */
179
+ export declare const selectEnabledEvmNetworks: ((state: NetworkEnablementControllerState) => string[]) & {
180
+ clearCache: () => void;
181
+ resultsCount: () => number;
182
+ resetResultsCount: () => void;
183
+ } & {
184
+ resultFunc: (resultFuncArgs_0: string[]) => string[];
185
+ memoizedResultFunc: ((resultFuncArgs_0: string[]) => string[]) & {
186
+ clearCache: () => void;
187
+ resultsCount: () => number;
188
+ resetResultsCount: () => void;
189
+ };
190
+ lastResult: () => string[];
191
+ dependencies: [((state: NetworkEnablementControllerState) => string[]) & {
192
+ clearCache: () => void;
193
+ resultsCount: () => number;
194
+ resetResultsCount: () => void;
195
+ } & {
196
+ resultFunc: (resultFuncArgs_0: {
197
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
198
+ }) => string[];
199
+ memoizedResultFunc: ((resultFuncArgs_0: {
200
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
201
+ }) => string[]) & {
202
+ clearCache: () => void;
203
+ resultsCount: () => number;
204
+ resetResultsCount: () => void;
205
+ };
206
+ lastResult: () => string[];
207
+ dependencies: [(state: NetworkEnablementControllerState) => {
208
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
209
+ }];
210
+ recomputations: () => number;
211
+ resetRecomputations: () => void;
212
+ dependencyRecomputations: () => number;
213
+ resetDependencyRecomputations: () => void;
214
+ } & {
215
+ argsMemoize: typeof import("reselect").weakMapMemoize;
216
+ memoize: typeof import("reselect").weakMapMemoize;
217
+ }];
218
+ recomputations: () => number;
219
+ resetRecomputations: () => void;
220
+ dependencyRecomputations: () => number;
221
+ resetDependencyRecomputations: () => void;
222
+ } & {
223
+ argsMemoize: typeof import("reselect").weakMapMemoize;
224
+ memoize: typeof import("reselect").weakMapMemoize;
225
+ };
226
+ /**
227
+ * Selector to get all enabled Solana networks.
228
+ *
229
+ * This is a convenience selector that specifically targets Solana networks.
230
+ *
231
+ * @returns A selector function that returns an array of enabled Solana chain IDs
232
+ */
233
+ export declare const selectEnabledSolanaNetworks: ((state: NetworkEnablementControllerState) => string[]) & {
234
+ clearCache: () => void;
235
+ resultsCount: () => number;
236
+ resetResultsCount: () => void;
237
+ } & {
238
+ resultFunc: (resultFuncArgs_0: string[]) => string[];
239
+ memoizedResultFunc: ((resultFuncArgs_0: string[]) => string[]) & {
240
+ clearCache: () => void;
241
+ resultsCount: () => number;
242
+ resetResultsCount: () => void;
243
+ };
244
+ lastResult: () => string[];
245
+ dependencies: [((state: NetworkEnablementControllerState) => string[]) & {
246
+ clearCache: () => void;
247
+ resultsCount: () => number;
248
+ resetResultsCount: () => void;
249
+ } & {
250
+ resultFunc: (resultFuncArgs_0: {
251
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
252
+ }) => string[];
253
+ memoizedResultFunc: ((resultFuncArgs_0: {
254
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
255
+ }) => string[]) & {
256
+ clearCache: () => void;
257
+ resultsCount: () => number;
258
+ resetResultsCount: () => void;
259
+ };
260
+ lastResult: () => string[];
261
+ dependencies: [(state: NetworkEnablementControllerState) => {
262
+ [x: string]: Record<`0x${string}` | `${string}:${string}`, boolean>;
263
+ }];
264
+ recomputations: () => number;
265
+ resetRecomputations: () => void;
266
+ dependencyRecomputations: () => number;
267
+ resetDependencyRecomputations: () => void;
268
+ } & {
269
+ argsMemoize: typeof import("reselect").weakMapMemoize;
270
+ memoize: typeof import("reselect").weakMapMemoize;
271
+ }];
272
+ recomputations: () => number;
273
+ resetRecomputations: () => void;
274
+ dependencyRecomputations: () => number;
275
+ resetDependencyRecomputations: () => void;
276
+ } & {
277
+ argsMemoize: typeof import("reselect").weakMapMemoize;
278
+ memoize: typeof import("reselect").weakMapMemoize;
279
+ };
280
+ //# sourceMappingURL=selectors.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectors.d.mts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;AAIvE,OAAO,KAAK,EAAE,gCAAgC,EAAE,0CAAsC;AAGtF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,UAC3B,gCAAgC;;CACb,CAAC;AAE7B;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,YAAa,GAAG,GAAG,WAAW;;;;;;;;;;;;;;;;2BAbxD,gCAAgC;;;;;;;;;;CAsBrC,CAAC;AAEL;;;;;;;;GAQG;AACH,eAAO,MAAM,4CAA4C,cAC5C,aAAa;;;;;;;;;;;;;;;;2BAlCjB,gCAAgC;;;;;;;;;;CAwCrC,CAAC;AAEL;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;2BAlD5B,gCAAgC;;;;;;;;;;CA+DxC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAtE9B,gCAAgC;;;;;;;;;;;;;;;;;;CA2ExC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BApF5B,gCAAgC;;;;;;;;;;;;;;;;;;CAuFxC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAhG/B,gCAAgC;;;;;;;;;;;;;;;;;;CAmGxC,CAAC"}
@@ -0,0 +1,81 @@
1
+ import { KnownCaipNamespace } from "@metamask/utils";
2
+ import { createSelector } from "reselect";
3
+ import { deriveKeys } from "./utils.mjs";
4
+ /**
5
+ * Base selector to get the enabled network map from the controller state.
6
+ *
7
+ * @param state - The NetworkEnablementController state
8
+ * @returns The enabled network map
9
+ */
10
+ export const selectEnabledNetworkMap = (state) => state.enabledNetworkMap;
11
+ /**
12
+ * Selector to check if a specific network is enabled.
13
+ *
14
+ * This selector accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID
15
+ * (for any blockchain network) and returns whether the network is currently enabled.
16
+ * It returns false for unknown networks or if there's an error parsing the chain ID.
17
+ *
18
+ * @param chainId - The chain ID to check (Hex or CAIP-2 format)
19
+ * @returns A selector function that returns true if the network is enabled, false otherwise
20
+ */
21
+ export const selectIsNetworkEnabled = (chainId) => createSelector(selectEnabledNetworkMap, (enabledNetworkMap) => {
22
+ const { namespace, storageKey } = deriveKeys(chainId);
23
+ return (namespace in enabledNetworkMap &&
24
+ storageKey in enabledNetworkMap[namespace] &&
25
+ enabledNetworkMap[namespace][storageKey]);
26
+ });
27
+ /**
28
+ * Selector builder to get all enabled networks for a specific namespace.
29
+ *
30
+ * The selector returned by this function returns an array of chain IDs (as strings) for all enabled networks
31
+ * within the specified namespace (e.g., 'eip155' for EVM networks, 'solana' for Solana).
32
+ *
33
+ * @param namespace - The CAIP namespace to get enabled networks for (e.g., 'eip155', 'solana')
34
+ * @returns A selector function that returns an array of chain ID strings for enabled networks in the namespace
35
+ */
36
+ export const createSelectorForEnabledNetworksForNamespace = (namespace) => createSelector(selectEnabledNetworkMap, (enabledNetworkMap) => {
37
+ return Object.entries(enabledNetworkMap[namespace] ?? {})
38
+ .filter(([, enabled]) => enabled)
39
+ .map(([id]) => id);
40
+ });
41
+ /**
42
+ * Selector to get all enabled networks across all namespaces.
43
+ *
44
+ * This selector returns a record where keys are CAIP namespaces and values are arrays
45
+ * of enabled chain IDs within each namespace.
46
+ *
47
+ * @returns A selector function that returns a record mapping namespace to array of enabled chain IDs
48
+ */
49
+ export const selectAllEnabledNetworks = createSelector(selectEnabledNetworkMap, (enabledNetworkMap) => {
50
+ return Object.keys(enabledNetworkMap).reduce((acc, ns) => {
51
+ acc[ns] = Object.entries(enabledNetworkMap[ns])
52
+ .filter(([, enabled]) => enabled)
53
+ .map(([id]) => id);
54
+ return acc;
55
+ }, {});
56
+ });
57
+ /**
58
+ * Selector to get the total count of enabled networks across all namespaces.
59
+ *
60
+ * @returns A selector function that returns the total number of enabled networks
61
+ */
62
+ export const selectEnabledNetworksCount = createSelector(selectAllEnabledNetworks, (allEnabledNetworks) => {
63
+ return Object.values(allEnabledNetworks).flat().length;
64
+ });
65
+ /**
66
+ * Selector to get all enabled EVM networks.
67
+ *
68
+ * This is a convenience selector that specifically targets EIP-155 networks.
69
+ *
70
+ * @returns A selector function that returns an array of enabled EVM chain IDs
71
+ */
72
+ export const selectEnabledEvmNetworks = createSelector(createSelectorForEnabledNetworksForNamespace(KnownCaipNamespace.Eip155), (enabledEvmNetworks) => enabledEvmNetworks);
73
+ /**
74
+ * Selector to get all enabled Solana networks.
75
+ *
76
+ * This is a convenience selector that specifically targets Solana networks.
77
+ *
78
+ * @returns A selector function that returns an array of enabled Solana chain IDs
79
+ */
80
+ export const selectEnabledSolanaNetworks = createSelector(createSelectorForEnabledNetworksForNamespace(KnownCaipNamespace.Solana), (enabledSolanaNetworks) => enabledSolanaNetworks);
81
+ //# sourceMappingURL=selectors.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectors.mjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AACrD,OAAO,EAAE,cAAc,EAAE,iBAAiB;AAG1C,OAAO,EAAE,UAAU,EAAE,oBAAgB;AAErC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,KAAuC,EACvC,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC;AAE7B;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,OAA0B,EAAE,EAAE,CACnE,cAAc,CAAC,uBAAuB,EAAE,CAAC,iBAAiB,EAAE,EAAE;IAC5D,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAEtD,OAAO,CACL,SAAS,IAAI,iBAAiB;QAC9B,UAAU,IAAI,iBAAiB,CAAC,SAAS,CAAC;QAC1C,iBAAiB,CAAC,SAAS,CAAC,CAAC,UAAU,CAAC,CACzC,CAAC;AACJ,CAAC,CAAC,CAAC;AAEL;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,4CAA4C,GAAG,CAC1D,SAAwB,EACxB,EAAE,CACF,cAAc,CAAC,uBAAuB,EAAE,CAAC,iBAAiB,EAAE,EAAE;IAC5D,OAAO,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;SACtD,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC;SAChC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC;AAEL;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,cAAc,CACpD,uBAAuB,EACvB,CAAC,iBAAiB,EAAE,EAAE;IACpB,OAAQ,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAqB,CAAC,MAAM,CAC/D,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE;QACV,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC;aAC5C,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC;aAChC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;QACrB,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAqC,CACtC,CAAC;AACJ,CAAC,CACF,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,cAAc,CACtD,wBAAwB,EACxB,CAAC,kBAAkB,EAAE,EAAE;IACrB,OAAO,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC;AACzD,CAAC,CACF,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,cAAc,CACpD,4CAA4C,CAAC,kBAAkB,CAAC,MAAM,CAAC,EACvE,CAAC,kBAAkB,EAAE,EAAE,CAAC,kBAAkB,CAC3C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,cAAc,CACvD,4CAA4C,CAAC,kBAAkB,CAAC,MAAM,CAAC,EACvE,CAAC,qBAAqB,EAAE,EAAE,CAAC,qBAAqB,CACjD,CAAC","sourcesContent":["import type { CaipChainId, CaipNamespace, Hex } from '@metamask/utils';\nimport { KnownCaipNamespace } from '@metamask/utils';\nimport { createSelector } from 'reselect';\n\nimport type { NetworkEnablementControllerState } from './NetworkEnablementController';\nimport { deriveKeys } from './utils';\n\n/**\n * Base selector to get the enabled network map from the controller state.\n *\n * @param state - The NetworkEnablementController state\n * @returns The enabled network map\n */\nexport const selectEnabledNetworkMap = (\n state: NetworkEnablementControllerState,\n) => state.enabledNetworkMap;\n\n/**\n * Selector to check if a specific network is enabled.\n *\n * This selector accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network) and returns whether the network is currently enabled.\n * It returns false for unknown networks or if there's an error parsing the chain ID.\n *\n * @param chainId - The chain ID to check (Hex or CAIP-2 format)\n * @returns A selector function that returns true if the network is enabled, false otherwise\n */\nexport const selectIsNetworkEnabled = (chainId: Hex | CaipChainId) =>\n createSelector(selectEnabledNetworkMap, (enabledNetworkMap) => {\n const { namespace, storageKey } = deriveKeys(chainId);\n\n return (\n namespace in enabledNetworkMap &&\n storageKey in enabledNetworkMap[namespace] &&\n enabledNetworkMap[namespace][storageKey]\n );\n });\n\n/**\n * Selector builder to get all enabled networks for a specific namespace.\n *\n * The selector returned by this function returns an array of chain IDs (as strings) for all enabled networks\n * within the specified namespace (e.g., 'eip155' for EVM networks, 'solana' for Solana).\n *\n * @param namespace - The CAIP namespace to get enabled networks for (e.g., 'eip155', 'solana')\n * @returns A selector function that returns an array of chain ID strings for enabled networks in the namespace\n */\nexport const createSelectorForEnabledNetworksForNamespace = (\n namespace: CaipNamespace,\n) =>\n createSelector(selectEnabledNetworkMap, (enabledNetworkMap) => {\n return Object.entries(enabledNetworkMap[namespace] ?? {})\n .filter(([, enabled]) => enabled)\n .map(([id]) => id);\n });\n\n/**\n * Selector to get all enabled networks across all namespaces.\n *\n * This selector returns a record where keys are CAIP namespaces and values are arrays\n * of enabled chain IDs within each namespace.\n *\n * @returns A selector function that returns a record mapping namespace to array of enabled chain IDs\n */\nexport const selectAllEnabledNetworks = createSelector(\n selectEnabledNetworkMap,\n (enabledNetworkMap) => {\n return (Object.keys(enabledNetworkMap) as CaipNamespace[]).reduce(\n (acc, ns) => {\n acc[ns] = Object.entries(enabledNetworkMap[ns])\n .filter(([, enabled]) => enabled)\n .map(([id]) => id);\n return acc;\n },\n {} as Record<CaipNamespace, string[]>,\n );\n },\n);\n\n/**\n * Selector to get the total count of enabled networks across all namespaces.\n *\n * @returns A selector function that returns the total number of enabled networks\n */\nexport const selectEnabledNetworksCount = createSelector(\n selectAllEnabledNetworks,\n (allEnabledNetworks) => {\n return Object.values(allEnabledNetworks).flat().length;\n },\n);\n\n/**\n * Selector to get all enabled EVM networks.\n *\n * This is a convenience selector that specifically targets EIP-155 networks.\n *\n * @returns A selector function that returns an array of enabled EVM chain IDs\n */\nexport const selectEnabledEvmNetworks = createSelector(\n createSelectorForEnabledNetworksForNamespace(KnownCaipNamespace.Eip155),\n (enabledEvmNetworks) => enabledEvmNetworks,\n);\n\n/**\n * Selector to get all enabled Solana networks.\n *\n * This is a convenience selector that specifically targets Solana networks.\n *\n * @returns A selector function that returns an array of enabled Solana chain IDs\n */\nexport const selectEnabledSolanaNetworks = createSelector(\n createSelectorForEnabledNetworksForNamespace(KnownCaipNamespace.Solana),\n (enabledSolanaNetworks) => enabledSolanaNetworks,\n);\n"]}
package/dist/types.cjs ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolScope = void 0;
4
+ /**
5
+ * Scopes for Solana account type. See {@link KeyringAccount.scopes}.
6
+ */
7
+ var SolScope;
8
+ (function (SolScope) {
9
+ SolScope["Devnet"] = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
10
+ SolScope["Mainnet"] = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
11
+ SolScope["Testnet"] = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z";
12
+ })(SolScope || (exports.SolScope = SolScope = {}));
13
+ //# sourceMappingURL=types.cjs.map