@metamask-previews/network-connection-banner-controller 0.2.1-preview-4f4c98e → 0.2.1-preview-eb263b0ee

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 (53) hide show
  1. package/CHANGELOG.md +0 -4
  2. package/dist/NetworkConnectionBannerController-method-action-types.cjs +7 -0
  3. package/dist/NetworkConnectionBannerController-method-action-types.cjs.map +1 -0
  4. package/dist/{NetworkConnectionBannerController-method-action-types.d.ts → NetworkConnectionBannerController-method-action-types.d.cts} +2 -2
  5. package/dist/NetworkConnectionBannerController-method-action-types.d.cts.map +1 -0
  6. package/dist/NetworkConnectionBannerController-method-action-types.d.mts +30 -0
  7. package/dist/NetworkConnectionBannerController-method-action-types.d.mts.map +1 -0
  8. package/dist/{NetworkConnectionBannerController-method-action-types.js → NetworkConnectionBannerController-method-action-types.mjs} +1 -1
  9. package/dist/NetworkConnectionBannerController-method-action-types.mjs.map +1 -0
  10. package/dist/NetworkConnectionBannerController.cjs +440 -0
  11. package/dist/NetworkConnectionBannerController.cjs.map +1 -0
  12. package/dist/{NetworkConnectionBannerController.d.ts → NetworkConnectionBannerController.d.cts} +11 -11
  13. package/dist/NetworkConnectionBannerController.d.cts.map +1 -0
  14. package/dist/NetworkConnectionBannerController.d.mts +202 -0
  15. package/dist/NetworkConnectionBannerController.d.mts.map +1 -0
  16. package/dist/{NetworkConnectionBannerController.js → NetworkConnectionBannerController.mjs} +9 -9
  17. package/dist/NetworkConnectionBannerController.mjs.map +1 -0
  18. package/dist/index.cjs +11 -0
  19. package/dist/index.cjs.map +1 -0
  20. package/dist/{index.d.ts → index.d.cts} +5 -5
  21. package/dist/index.d.cts.map +1 -0
  22. package/dist/index.d.mts +5 -0
  23. package/dist/index.d.mts.map +1 -0
  24. package/dist/index.mjs +3 -0
  25. package/dist/index.mjs.map +1 -0
  26. package/dist/selectors.cjs +37 -0
  27. package/dist/selectors.cjs.map +1 -0
  28. package/dist/{selectors.d.ts → selectors.d.cts} +5 -21
  29. package/dist/selectors.d.cts.map +1 -0
  30. package/dist/selectors.d.mts +31 -0
  31. package/dist/selectors.d.mts.map +1 -0
  32. package/dist/{selectors.js → selectors.mjs} +2 -2
  33. package/dist/selectors.mjs.map +1 -0
  34. package/dist/url-utils.cjs +28 -0
  35. package/dist/url-utils.cjs.map +1 -0
  36. package/dist/{url-utils.d.ts → url-utils.d.cts} +1 -1
  37. package/dist/url-utils.d.cts.map +1 -0
  38. package/dist/url-utils.d.mts +13 -0
  39. package/dist/url-utils.d.mts.map +1 -0
  40. package/dist/{url-utils.js → url-utils.mjs} +1 -1
  41. package/dist/url-utils.mjs.map +1 -0
  42. package/package.json +16 -12
  43. package/dist/NetworkConnectionBannerController-method-action-types.d.ts.map +0 -1
  44. package/dist/NetworkConnectionBannerController-method-action-types.js.map +0 -1
  45. package/dist/NetworkConnectionBannerController.d.ts.map +0 -1
  46. package/dist/NetworkConnectionBannerController.js.map +0 -1
  47. package/dist/index.d.ts.map +0 -1
  48. package/dist/index.js +0 -3
  49. package/dist/index.js.map +0 -1
  50. package/dist/selectors.d.ts.map +0 -1
  51. package/dist/selectors.js.map +0 -1
  52. package/dist/url-utils.d.ts.map +0 -1
  53. package/dist/url-utils.js.map +0 -1
@@ -1,13 +1,13 @@
1
- import type { ControllerGetStateAction, ControllerStateChangedEvent } from '@metamask/base-controller';
2
- import { BaseController } from '@metamask/base-controller';
3
- import type { ClientControllerStateChangeEvent } from '@metamask/client-controller';
4
- import type { ConnectivityControllerGetStateAction, ConnectivityControllerStateChangeEvent } from '@metamask/connectivity-controller';
5
- import type { KeyringControllerLockEvent, KeyringControllerUnlockEvent } from '@metamask/keyring-controller';
6
- import type { Messenger } from '@metamask/messenger';
7
- import type { NetworkControllerGetNetworkConfigurationByChainIdAction, NetworkControllerGetStateAction, NetworkControllerUpdateNetworkAction, NetworkControllerSetActiveNetworkAction, NetworkControllerStateChangeEvent } from '@metamask/network-controller';
8
- import type { NetworkEnablementControllerGetStateAction, NetworkEnablementControllerStateChangeEvent } from '@metamask/network-enablement-controller';
9
- import type { Hex } from '@metamask/utils';
10
- import type { NetworkConnectionBannerControllerMethodActions } from './NetworkConnectionBannerController-method-action-types.js';
1
+ import type { ControllerGetStateAction, ControllerStateChangedEvent } from "@metamask/base-controller";
2
+ import { BaseController } from "@metamask/base-controller";
3
+ import type { ClientControllerStateChangeEvent } from "@metamask/client-controller";
4
+ import type { ConnectivityControllerGetStateAction, ConnectivityControllerStateChangeEvent } from "@metamask/connectivity-controller";
5
+ import type { KeyringControllerLockEvent, KeyringControllerUnlockEvent } from "@metamask/keyring-controller";
6
+ import type { Messenger } from "@metamask/messenger";
7
+ import type { NetworkControllerGetNetworkConfigurationByChainIdAction, NetworkControllerGetStateAction, NetworkControllerUpdateNetworkAction, NetworkControllerSetActiveNetworkAction, NetworkControllerStateChangeEvent } from "@metamask/network-controller";
8
+ import type { NetworkEnablementControllerGetStateAction, NetworkEnablementControllerStateChangeEvent } from "@metamask/network-enablement-controller";
9
+ import type { Hex } from "@metamask/utils";
10
+ import type { NetworkConnectionBannerControllerMethodActions } from "./NetworkConnectionBannerController-method-action-types.cjs";
11
11
  /**
12
12
  * The name of the {@link NetworkConnectionBannerController}, used to namespace
13
13
  * the controller's actions and events and to namespace the controller's state
@@ -199,4 +199,4 @@ export declare class NetworkConnectionBannerController extends BaseController<ty
199
199
  switchToDefaultInfuraRpcEndpoint(chainId: Hex): Promise<void>;
200
200
  }
201
201
  export {};
202
- //# sourceMappingURL=NetworkConnectionBannerController.d.ts.map
202
+ //# sourceMappingURL=NetworkConnectionBannerController.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NetworkConnectionBannerController.d.cts","sourceRoot":"","sources":["../src/NetworkConnectionBannerController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,2BAA2B,EAE5B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,KAAK,EA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wCAAwC;IAqI3C;;OAEG;IACH,aAAa,IAAI,IAAI;IAIrB;;;;;;;;OAQG;IACG,gCAAgC,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;CA0SpE"}
@@ -0,0 +1,202 @@
1
+ import type { ControllerGetStateAction, ControllerStateChangedEvent } from "@metamask/base-controller";
2
+ import { BaseController } from "@metamask/base-controller";
3
+ import type { ClientControllerStateChangeEvent } from "@metamask/client-controller";
4
+ import type { ConnectivityControllerGetStateAction, ConnectivityControllerStateChangeEvent } from "@metamask/connectivity-controller";
5
+ import type { KeyringControllerLockEvent, KeyringControllerUnlockEvent } from "@metamask/keyring-controller";
6
+ import type { Messenger } from "@metamask/messenger";
7
+ import type { NetworkControllerGetNetworkConfigurationByChainIdAction, NetworkControllerGetStateAction, NetworkControllerUpdateNetworkAction, NetworkControllerSetActiveNetworkAction, NetworkControllerStateChangeEvent } from "@metamask/network-controller";
8
+ import type { NetworkEnablementControllerGetStateAction, NetworkEnablementControllerStateChangeEvent } from "@metamask/network-enablement-controller";
9
+ import type { Hex } from "@metamask/utils";
10
+ import type { NetworkConnectionBannerControllerMethodActions } from "./NetworkConnectionBannerController-method-action-types.mjs";
11
+ /**
12
+ * The name of the {@link NetworkConnectionBannerController}, used to namespace
13
+ * the controller's actions and events and to namespace the controller's state
14
+ * data when composed with other controllers.
15
+ */
16
+ declare const CONTROLLER_NAME = "NetworkConnectionBannerController";
17
+ /**
18
+ * Status the banner can be in. `available` means no banner is shown; the
19
+ * `degraded` and `unavailable` values mirror the two-tier escalation that the
20
+ * UI renders.
21
+ */
22
+ export type NetworkConnectionBannerStatus = 'available' | 'degraded' | 'unavailable';
23
+ /**
24
+ * Details of a failing network the banner describes.
25
+ */
26
+ export type FailedNetwork = {
27
+ /** The chain id of the failing network. */
28
+ chainId: Hex;
29
+ /** The `networkClientId` of the failing default RPC endpoint. */
30
+ networkClientId: string;
31
+ /** The display name for the failing network. */
32
+ name: string;
33
+ /** The URL of the failing default RPC endpoint. */
34
+ rpcUrl: string;
35
+ /** Whether the failing endpoint is a MetaMask Infura endpoint. */
36
+ isInfuraEndpoint: boolean;
37
+ /**
38
+ * The networkClientId of an Infura endpoint on the same chain that the user
39
+ * can switch to. `null` when the failing endpoint is already Infura or when
40
+ * no Infura alternative exists.
41
+ */
42
+ switchableInfuraNetworkClientId: string | null;
43
+ };
44
+ /**
45
+ * State for the {@link NetworkConnectionBannerController}.
46
+ *
47
+ * The keys carry the controller-domain prefix (like
48
+ * `ConnectivityController`'s `connectivityStatus`) because some clients merge
49
+ * all controller states into one flat object, where generic names like
50
+ * `status` collide across controllers.
51
+ */
52
+ export type NetworkConnectionBannerControllerState = {
53
+ networkConnectionBannerStatus: NetworkConnectionBannerStatus;
54
+ networkConnectionBannerNetwork: FailedNetwork | null;
55
+ };
56
+ /**
57
+ * Constructs the default {@link NetworkConnectionBannerController} state.
58
+ *
59
+ * @returns The default state.
60
+ */
61
+ export declare function getDefaultNetworkConnectionBannerControllerState(): NetworkConnectionBannerControllerState;
62
+ /**
63
+ * The default for how long (in milliseconds) a failing network must remain
64
+ * in a "failed" status ("degraded" or "unavailable") before the degraded
65
+ * banner appears.
66
+ */
67
+ export declare const DEFAULT_DEGRADED_BANNER_TIMEOUT = 5000;
68
+ /**
69
+ * The default for how long (in milliseconds) a failing network must remain
70
+ * in a "failed" status before the banner escalates to "unavailable".
71
+ */
72
+ export declare const DEFAULT_UNAVAILABLE_BANNER_TIMEOUT = 30000;
73
+ /**
74
+ * Retrieves the state of the {@link NetworkConnectionBannerController}.
75
+ */
76
+ export type NetworkConnectionBannerControllerGetStateAction = ControllerGetStateAction<typeof CONTROLLER_NAME, NetworkConnectionBannerControllerState>;
77
+ /**
78
+ * Actions that {@link NetworkConnectionBannerControllerMessenger} exposes to
79
+ * other consumers.
80
+ */
81
+ export type NetworkConnectionBannerControllerActions = NetworkConnectionBannerControllerGetStateAction | NetworkConnectionBannerControllerMethodActions;
82
+ /**
83
+ * Actions from other messengers that
84
+ * {@link NetworkConnectionBannerControllerMessenger} calls.
85
+ */
86
+ type AllowedActions = NetworkControllerGetStateAction | NetworkControllerGetNetworkConfigurationByChainIdAction | NetworkControllerUpdateNetworkAction | NetworkControllerSetActiveNetworkAction | NetworkEnablementControllerGetStateAction | ConnectivityControllerGetStateAction;
87
+ /**
88
+ * Published when the state of {@link NetworkConnectionBannerController}
89
+ * changes.
90
+ */
91
+ export type NetworkConnectionBannerControllerStateChangedEvent = ControllerStateChangedEvent<typeof CONTROLLER_NAME, NetworkConnectionBannerControllerState>;
92
+ /**
93
+ * Events that {@link NetworkConnectionBannerControllerMessenger} exposes to
94
+ * other consumers.
95
+ */
96
+ export type NetworkConnectionBannerControllerEvents = NetworkConnectionBannerControllerStateChangedEvent;
97
+ /**
98
+ * Events from other messengers that
99
+ * {@link NetworkConnectionBannerControllerMessenger} subscribes to.
100
+ */
101
+ type AllowedEvents = NetworkControllerStateChangeEvent | NetworkEnablementControllerStateChangeEvent | ConnectivityControllerStateChangeEvent | ClientControllerStateChangeEvent | KeyringControllerUnlockEvent | KeyringControllerLockEvent;
102
+ /**
103
+ * The messenger restricted to actions and events accessed by
104
+ * {@link NetworkConnectionBannerController}.
105
+ */
106
+ export type NetworkConnectionBannerControllerMessenger = Messenger<typeof CONTROLLER_NAME, NetworkConnectionBannerControllerActions | AllowedActions, NetworkConnectionBannerControllerEvents | AllowedEvents>;
107
+ /**
108
+ * Options for constructing the {@link NetworkConnectionBannerController}.
109
+ */
110
+ export type NetworkConnectionBannerControllerOptions = {
111
+ /**
112
+ * The messenger for inter-controller communication.
113
+ */
114
+ messenger: NetworkConnectionBannerControllerMessenger;
115
+ /**
116
+ * The wallet's Infura project id, used to recognize MetaMask Infura
117
+ * endpoints whose URL was persisted with the id already substituted.
118
+ */
119
+ infuraProjectId: string;
120
+ /**
121
+ * How long (in milliseconds) a failing network must remain in a "failed"
122
+ * status before the degraded banner appears. Defaults to
123
+ * {@link DEFAULT_DEGRADED_BANNER_TIMEOUT}.
124
+ */
125
+ degradedBannerTimeout?: number;
126
+ /**
127
+ * How long (in milliseconds), measured from the same failure start as
128
+ * `degradedBannerTimeout`, before the banner escalates to "unavailable".
129
+ * Must be greater than `degradedBannerTimeout`. Defaults to
130
+ * {@link DEFAULT_UNAVAILABLE_BANNER_TIMEOUT}.
131
+ */
132
+ unavailableBannerTimeout?: number;
133
+ };
134
+ /**
135
+ * Drives the "network connection banner", a notice that appears within clients
136
+ * whose goal is to inform users about networks which have exhibited repeated
137
+ * request failures and offer potential workarounds.
138
+ *
139
+ * Some terminology: A "network" in this case is an RPC endpoint, and a network
140
+ * that has exhibited repeated request failures has entered a "failed" state (or
141
+ * is a "failed network").
142
+ *
143
+ * For simplicity, the banner always represents a single failed network. If
144
+ * multiple networks are failing, the first custom network takes priority over
145
+ * the first Infura network.
146
+ *
147
+ * To ensure that the banner is actionable, the banner does not always appear
148
+ * even if there is a failed network to display. Instead it appears under these
149
+ * conditions:
150
+ *
151
+ * - The failed network is a custom (non-Infura) endpoint (we want to inform
152
+ * users about endpoints they've added so they don't cast blame on MetaMask).
153
+ * - Every enabled EVM network has entered a failed state (this indicates a
154
+ * broad connectivity issue).
155
+ *
156
+ * Assuming that these conditions have been met, there are two variants of the
157
+ * banner which will be displayed at different times.
158
+ *
159
+ * - A "degraded" variant which will appear when 5 seconds has elapsed and there
160
+ * is an eligible failed network to display
161
+ * - An "unavailable" variant which will appear when 30 seconds have elapsed and
162
+ * there is an eligible failed network to display
163
+ *
164
+ * Finally, the controller contains actions that drive interactions with the
165
+ * banner. Namely, if the banner represents a custom network, then it will offer
166
+ * the user a way to switch to the default Infura network. The controller
167
+ * contains the logic to carry out that action.
168
+ */
169
+ export declare class NetworkConnectionBannerController extends BaseController<typeof CONTROLLER_NAME, NetworkConnectionBannerControllerState, NetworkConnectionBannerControllerMessenger> {
170
+ #private;
171
+ /**
172
+ * Constructs a new {@link NetworkConnectionBannerController}.
173
+ *
174
+ * @param args - The arguments to this controller.
175
+ * @param args.messenger - The messenger suited for this controller.
176
+ * @param args.infuraProjectId - The wallet's Infura project id.
177
+ * @param args.degradedBannerTimeout - How long (in milliseconds) a failing
178
+ * network must remain failed before the degraded banner appears.
179
+ * @param args.unavailableBannerTimeout - How long (in milliseconds) before
180
+ * the banner escalates to "unavailable". Must be greater than
181
+ * `degradedBannerTimeout`.
182
+ * @throws If `unavailableBannerTimeout` is not greater than
183
+ * `degradedBannerTimeout`.
184
+ */
185
+ constructor({ messenger, infuraProjectId, degradedBannerTimeout, unavailableBannerTimeout, }: NetworkConnectionBannerControllerOptions);
186
+ /**
187
+ * Clears the banner state such that the banner will be hidden.
188
+ */
189
+ dismissBanner(): void;
190
+ /**
191
+ * Switches the chain's default RPC endpoint to its Infura endpoint and
192
+ * makes it the active network, causing the banner to clear once the
193
+ * network becomes available again.
194
+ *
195
+ * @param chainId - The chain whose default RPC endpoint should be switched.
196
+ * @throws If the chain configuration cannot be found, or if it has no
197
+ * Infura endpoint to switch to, or if the default is already Infura.
198
+ */
199
+ switchToDefaultInfuraRpcEndpoint(chainId: Hex): Promise<void>;
200
+ }
201
+ export {};
202
+ //# sourceMappingURL=NetworkConnectionBannerController.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NetworkConnectionBannerController.d.mts","sourceRoot":"","sources":["../src/NetworkConnectionBannerController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,2BAA2B,EAE5B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,KAAK,EAAE,gCAAgC,EAAE,oCAAoC;AAKpF,OAAO,KAAK,EACV,oCAAoC,EAEpC,sCAAsC,EACvC,0CAA0C;AAC3C,OAAO,KAAK,EACV,0BAA0B,EAC1B,4BAA4B,EAC7B,qCAAqC;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAEV,uDAAuD,EACvD,+BAA+B,EAC/B,oCAAoC,EACpC,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,GACpC,uCAAuC,GACvC,yCAAyC,GACzC,oCAAoC,CAAC;AAEzC;;;GAGG;AACH,MAAM,MAAM,kDAAkD,GAC5D,2BAA2B,CACzB,OAAO,eAAe,EACtB,sCAAsC,CACvC,CAAC;AAEJ;;;GAGG;AACH,MAAM,MAAM,uCAAuC,GACjD,kDAAkD,CAAC;AAErD;;;GAGG;AACH,KAAK,aAAa,GACd,iCAAiC,GACjC,2CAA2C,GAC3C,sCAAsC,GACtC,gCAAgC,GAChC,4BAA4B,GAC5B,0BAA0B,CAAC;AAE/B;;;GAGG;AACH,MAAM,MAAM,0CAA0C,GAAG,SAAS,CAChE,OAAO,eAAe,EACtB,wCAAwC,GAAG,cAAc,EACzD,uCAAuC,GAAG,aAAa,CACxD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,wCAAwC,GAAG;IACrD;;OAEG;IACH,SAAS,EAAE,0CAA0C,CAAC;IAEtD;;;OAGG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B;;;;;OAKG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAC;CACnC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,qBAAa,iCAAkC,SAAQ,cAAc,CACnE,OAAO,eAAe,EACtB,sCAAsC,EACtC,0CAA0C,CAC3C;;IAqBC;;;;;;;;;;;;;OAaG;gBACS,EACV,SAAS,EACT,eAAe,EACf,qBAAuD,EACvD,wBAA6D,GAC9D,EAAE,wCAAwC;IAqI3C;;OAEG;IACH,aAAa,IAAI,IAAI;IAIrB;;;;;;;;OAQG;IACG,gCAAgC,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;CA0SpE"}
@@ -10,14 +10,14 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _NetworkConnectionBannerController_instances, _NetworkConnectionBannerController_degradedTimer, _NetworkConnectionBannerController_unavailableTimer, _NetworkConnectionBannerController_pendingNetworkClientId, _NetworkConnectionBannerController_isStarted, _NetworkConnectionBannerController_isUiOpen, _NetworkConnectionBannerController_isUnlocked, _NetworkConnectionBannerController_infuraProjectId, _NetworkConnectionBannerController_degradedBannerTimeout, _NetworkConnectionBannerController_unavailableBannerTimeout, _NetworkConnectionBannerController_updateLifecycle, _NetworkConnectionBannerController_start, _NetworkConnectionBannerController_stop, _NetworkConnectionBannerController_refreshState, _NetworkConnectionBannerController_resetBanner, _NetworkConnectionBannerController_clearTimers, _NetworkConnectionBannerController_findFailedNetwork, _NetworkConnectionBannerController_getEnabledEvmChainIds, _NetworkConnectionBannerController_collectEnabledNetworks, _NetworkConnectionBannerController_buildFailedNetwork, _NetworkConnectionBannerController_pickFailedNetworkToDisplay;
13
- import { BaseController } from '@metamask/base-controller';
14
- import { clientControllerSelectors } from '@metamask/client-controller';
15
- import { CONNECTIVITY_STATUSES, connectivityControllerSelectors, } from '@metamask/connectivity-controller';
16
- import { NetworkStatus } from '@metamask/network-controller';
17
- import { selectEnabledNetworkMap } from '@metamask/network-enablement-controller';
18
- import { KnownCaipNamespace } from '@metamask/utils';
19
- import { createSelector } from 'reselect';
20
- import { getIsInfuraEndpoint } from './url-utils.js';
13
+ import { BaseController } from "@metamask/base-controller";
14
+ import { clientControllerSelectors } from "@metamask/client-controller";
15
+ import { CONNECTIVITY_STATUSES, connectivityControllerSelectors } from "@metamask/connectivity-controller";
16
+ import { NetworkStatus } from "@metamask/network-controller";
17
+ import { selectEnabledNetworkMap } from "@metamask/network-enablement-controller";
18
+ import { KnownCaipNamespace } from "@metamask/utils";
19
+ import { createSelector } from "reselect";
20
+ import { getIsInfuraEndpoint } from "./url-utils.mjs";
21
21
  /**
22
22
  * The name of the {@link NetworkConnectionBannerController}, used to namespace
23
23
  * the controller's actions and events and to namespace the controller's state
@@ -432,4 +432,4 @@ _NetworkConnectionBannerController_degradedTimer = new WeakMap(), _NetworkConnec
432
432
  }
433
433
  return firstCustomFailed ?? failedNetworks[0];
434
434
  };
435
- //# sourceMappingURL=NetworkConnectionBannerController.js.map
435
+ //# sourceMappingURL=NetworkConnectionBannerController.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NetworkConnectionBannerController.mjs","sourceRoot":"","sources":["../src/NetworkConnectionBannerController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EAAE,yBAAyB,EAAE,oCAAoC;AAExE,OAAO,EACL,qBAAqB,EACrB,+BAA+B,EAChC,0CAA0C;AAqB3C,OAAO,EAAE,aAAa,EAAE,qCAAqC;AAM7D,OAAO,EAAE,uBAAuB,EAAE,gDAAgD;AAElF,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AACrD,OAAO,EAAE,cAAc,EAAE,iBAAiB;AAG1C,OAAO,EAAE,mBAAmB,EAAE,wBAAuB;AAErD;;;;GAIG;AACH,MAAM,eAAe,GAAG,mCAAmC,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,sBAAsB,GAAG,CAC7B,KAAmB,EACe,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC;AAE9D;;;;;;GAMG;AACH,MAAM,oCAAoC,GAAG,CAC3C,KAAmB,EAC6B,EAAE,CAClD,KAAK,CAAC,8BAA8B,CAAC;AAEvC;;;;;;;;GAQG;AACH,MAAM,6BAA6B,GAAG,cAAc,CAClD,CAAC,sBAAsB,EAAE,oCAAoC,CAAC,EAC9D,CAAC,gBAAgB,EAAE,8BAA8B,EAAE,EAAE,CAAC,CAAC;IACrD,gBAAgB;IAChB,8BAA8B;CAC/B,CAAC,CACH,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,uCAAuC,GAAG,cAAc,CAC5D,CAAC,uBAAuB,CAAC,EACzB,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAA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OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,iBAAiB,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangedEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { clientControllerSelectors } from '@metamask/client-controller';\nimport type { ClientControllerStateChangeEvent } from '@metamask/client-controller';\nimport {\n CONNECTIVITY_STATUSES,\n connectivityControllerSelectors,\n} from '@metamask/connectivity-controller';\nimport type {\n ConnectivityControllerGetStateAction,\n ConnectivityControllerState,\n ConnectivityControllerStateChangeEvent,\n} from '@metamask/connectivity-controller';\nimport type {\n KeyringControllerLockEvent,\n KeyringControllerUnlockEvent,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkConfiguration,\n NetworkControllerGetNetworkConfigurationByChainIdAction,\n NetworkControllerGetStateAction,\n NetworkControllerUpdateNetworkAction,\n NetworkControllerSetActiveNetworkAction,\n NetworkControllerStateChangeEvent,\n NetworkMetadata,\n NetworkState,\n} from '@metamask/network-controller';\nimport { NetworkStatus } from '@metamask/network-controller';\nimport type {\n NetworkEnablementControllerGetStateAction,\n NetworkEnablementControllerState,\n NetworkEnablementControllerStateChangeEvent,\n} from '@metamask/network-enablement-controller';\nimport { selectEnabledNetworkMap } from '@metamask/network-enablement-controller';\nimport type { Hex } from '@metamask/utils';\nimport { KnownCaipNamespace } from '@metamask/utils';\nimport { createSelector } from 'reselect';\n\nimport type { NetworkConnectionBannerControllerMethodActions } from './NetworkConnectionBannerController-method-action-types.js';\nimport { getIsInfuraEndpoint } from './url-utils.js';\n\n/**\n * The name of the {@link NetworkConnectionBannerController}, used to namespace\n * the controller's actions and events and to namespace the controller's state\n * data when composed with other controllers.\n */\nconst CONTROLLER_NAME = 'NetworkConnectionBannerController';\n\n/**\n * Selects `networksMetadata` from the `NetworkController` state.\n *\n * @param state - The `NetworkController` state.\n * @returns The networks metadata map keyed by network client id.\n */\nconst selectNetworksMetadata = (\n state: NetworkState,\n): NetworkState['networksMetadata'] => state.networksMetadata;\n\n/**\n * Selects `networkConfigurationsByChainId` from the `NetworkController`\n * state.\n *\n * @param state - The `NetworkController` state.\n * @returns The network configurations keyed by chain id.\n */\nconst selectNetworkConfigurationsByChainId = (\n state: NetworkState,\n): NetworkState['networkConfigurationsByChainId'] =>\n state.networkConfigurationsByChainId;\n\n/**\n * Selects the `NetworkController` state fields that influence the banner\n * rule. Composed with `createSelector` so the return object stays reference\n * stable while unrelated `NetworkController` state (e.g.\n * `selectedNetworkClientId`) changes.\n *\n * @param state - The `NetworkController` state.\n * @returns The relevant network fields.\n */\nconst selectNetworkControllerFields = createSelector(\n [selectNetworksMetadata, selectNetworkConfigurationsByChainId],\n (networksMetadata, networkConfigurationsByChainId) => ({\n networksMetadata,\n networkConfigurationsByChainId,\n }),\n);\n\n/**\n * Selects the `NetworkEnablementController` state field that influences the\n * banner rule.\n *\n * @param state - The `NetworkEnablementController` state.\n * @returns The relevant enablement fields.\n */\nconst selectNetworkEnablementControllerFields = createSelector(\n [selectEnabledNetworkMap],\n (enabledNetworkMap) => ({ enabledNetworkMap }),\n);\n\n/**\n * Selects the `ConnectivityController` state field that influences the\n * banner rule.\n *\n * @param state - The `ConnectivityController` state.\n * @returns The relevant connectivity fields.\n */\nconst selectConnectivityControllerFields = createSelector(\n [connectivityControllerSelectors.selectConnectivityStatus],\n (connectivityStatus) => ({ connectivityStatus }),\n);\n\n/**\n * Status the banner can be in. `available` means no banner is shown; the\n * `degraded` and `unavailable` values mirror the two-tier escalation that the\n * UI renders.\n */\nexport type NetworkConnectionBannerStatus =\n | 'available'\n | 'degraded'\n | 'unavailable';\n\n/**\n * An enabled network from `NetworkController` state with a default RPC\n * endpoint. Used as the input to the failed-network detection pipeline.\n * `metadata` is missing until the network's connectivity has been looked up.\n */\ntype EnabledNetwork = {\n chainId: Hex;\n name: string;\n rpcEndpoints: NetworkConfiguration['rpcEndpoints'];\n defaultRpcEndpointIndex: number;\n defaultRpcEndpoint: NetworkConfiguration['rpcEndpoints'][number];\n metadata: NetworkMetadata | undefined;\n};\n\n/**\n * Details of a failing network the banner describes.\n */\nexport type FailedNetwork = {\n /** The chain id of the failing network. */\n chainId: Hex;\n /** The `networkClientId` of the failing default RPC endpoint. */\n networkClientId: string;\n /** The display name for the failing network. */\n name: string;\n /** The URL of the failing default RPC endpoint. */\n rpcUrl: string;\n /** Whether the failing endpoint is a MetaMask Infura endpoint. */\n isInfuraEndpoint: boolean;\n /**\n * The networkClientId of an Infura endpoint on the same chain that the user\n * can switch to. `null` when the failing endpoint is already Infura or when\n * no Infura alternative exists.\n */\n switchableInfuraNetworkClientId: string | null;\n};\n\n/**\n * State for the {@link NetworkConnectionBannerController}.\n *\n * The keys carry the controller-domain prefix (like\n * `ConnectivityController`'s `connectivityStatus`) because some clients merge\n * all controller states into one flat object, where generic names like\n * `status` collide across controllers.\n */\nexport type NetworkConnectionBannerControllerState = {\n networkConnectionBannerStatus: NetworkConnectionBannerStatus;\n networkConnectionBannerNetwork: FailedNetwork | null;\n};\n\nconst networkConnectionBannerControllerMetadata = {\n networkConnectionBannerStatus: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n networkConnectionBannerNetwork: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n} satisfies StateMetadata<NetworkConnectionBannerControllerState>;\n\n/**\n * Constructs the default {@link NetworkConnectionBannerController} state.\n *\n * @returns The default state.\n */\nexport function getDefaultNetworkConnectionBannerControllerState(): NetworkConnectionBannerControllerState {\n return {\n networkConnectionBannerStatus: 'available',\n networkConnectionBannerNetwork: null,\n };\n}\n\n/**\n * The default for how long (in milliseconds) a failing network must remain\n * in a \"failed\" status (\"degraded\" or \"unavailable\") before the degraded\n * banner appears.\n */\nexport const DEFAULT_DEGRADED_BANNER_TIMEOUT = 5_000;\n\n/**\n * The default for how long (in milliseconds) a failing network must remain\n * in a \"failed\" status before the banner escalates to \"unavailable\".\n */\nexport const DEFAULT_UNAVAILABLE_BANNER_TIMEOUT = 30_000;\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'dismissBanner',\n 'switchToDefaultInfuraRpcEndpoint',\n] as const;\n\n/**\n * Retrieves the state of the {@link NetworkConnectionBannerController}.\n */\nexport type NetworkConnectionBannerControllerGetStateAction =\n ControllerGetStateAction<\n typeof CONTROLLER_NAME,\n NetworkConnectionBannerControllerState\n >;\n\n/**\n * Actions that {@link NetworkConnectionBannerControllerMessenger} exposes to\n * other consumers.\n */\nexport type NetworkConnectionBannerControllerActions =\n | NetworkConnectionBannerControllerGetStateAction\n | NetworkConnectionBannerControllerMethodActions;\n\n/**\n * Actions from other messengers that\n * {@link NetworkConnectionBannerControllerMessenger} calls.\n */\ntype AllowedActions =\n | NetworkControllerGetStateAction\n | NetworkControllerGetNetworkConfigurationByChainIdAction\n | NetworkControllerUpdateNetworkAction\n | NetworkControllerSetActiveNetworkAction\n | NetworkEnablementControllerGetStateAction\n | ConnectivityControllerGetStateAction;\n\n/**\n * Published when the state of {@link NetworkConnectionBannerController}\n * changes.\n */\nexport type NetworkConnectionBannerControllerStateChangedEvent =\n ControllerStateChangedEvent<\n typeof CONTROLLER_NAME,\n NetworkConnectionBannerControllerState\n >;\n\n/**\n * Events that {@link NetworkConnectionBannerControllerMessenger} exposes to\n * other consumers.\n */\nexport type NetworkConnectionBannerControllerEvents =\n NetworkConnectionBannerControllerStateChangedEvent;\n\n/**\n * Events from other messengers that\n * {@link NetworkConnectionBannerControllerMessenger} subscribes to.\n */\ntype AllowedEvents =\n | NetworkControllerStateChangeEvent\n | NetworkEnablementControllerStateChangeEvent\n | ConnectivityControllerStateChangeEvent\n | ClientControllerStateChangeEvent\n | KeyringControllerUnlockEvent\n | KeyringControllerLockEvent;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link NetworkConnectionBannerController}.\n */\nexport type NetworkConnectionBannerControllerMessenger = Messenger<\n typeof CONTROLLER_NAME,\n NetworkConnectionBannerControllerActions | AllowedActions,\n NetworkConnectionBannerControllerEvents | AllowedEvents\n>;\n\n/**\n * Options for constructing the {@link NetworkConnectionBannerController}.\n */\nexport type NetworkConnectionBannerControllerOptions = {\n /**\n * The messenger for inter-controller communication.\n */\n messenger: NetworkConnectionBannerControllerMessenger;\n\n /**\n * The wallet's Infura project id, used to recognize MetaMask Infura\n * endpoints whose URL was persisted with the id already substituted.\n */\n infuraProjectId: string;\n\n /**\n * How long (in milliseconds) a failing network must remain in a \"failed\"\n * status before the degraded banner appears. Defaults to\n * {@link DEFAULT_DEGRADED_BANNER_TIMEOUT}.\n */\n degradedBannerTimeout?: number;\n\n /**\n * How long (in milliseconds), measured from the same failure start as\n * `degradedBannerTimeout`, before the banner escalates to \"unavailable\".\n * Must be greater than `degradedBannerTimeout`. Defaults to\n * {@link DEFAULT_UNAVAILABLE_BANNER_TIMEOUT}.\n */\n unavailableBannerTimeout?: number;\n};\n\n/**\n * Drives the \"network connection banner\", a notice that appears within clients\n * whose goal is to inform users about networks which have exhibited repeated\n * request failures and offer potential workarounds.\n *\n * Some terminology: A \"network\" in this case is an RPC endpoint, and a network\n * that has exhibited repeated request failures has entered a \"failed\" state (or\n * is a \"failed network\").\n *\n * For simplicity, the banner always represents a single failed network. If\n * multiple networks are failing, the first custom network takes priority over\n * the first Infura network.\n *\n * To ensure that the banner is actionable, the banner does not always appear\n * even if there is a failed network to display. Instead it appears under these\n * conditions:\n *\n * - The failed network is a custom (non-Infura) endpoint (we want to inform\n * users about endpoints they've added so they don't cast blame on MetaMask).\n * - Every enabled EVM network has entered a failed state (this indicates a\n * broad connectivity issue).\n *\n * Assuming that these conditions have been met, there are two variants of the\n * banner which will be displayed at different times.\n *\n * - A \"degraded\" variant which will appear when 5 seconds has elapsed and there\n * is an eligible failed network to display\n * - An \"unavailable\" variant which will appear when 30 seconds have elapsed and\n * there is an eligible failed network to display\n *\n * Finally, the controller contains actions that drive interactions with the\n * banner. Namely, if the banner represents a custom network, then it will offer\n * the user a way to switch to the default Infura network. The controller\n * contains the logic to carry out that action.\n */\nexport class NetworkConnectionBannerController extends BaseController<\n typeof CONTROLLER_NAME,\n NetworkConnectionBannerControllerState,\n NetworkConnectionBannerControllerMessenger\n> {\n #degradedTimer: ReturnType<typeof setTimeout> | undefined;\n\n #unavailableTimer: ReturnType<typeof setTimeout> | undefined;\n\n #pendingNetworkClientId: string | undefined;\n\n #isStarted = false;\n\n /** Whether the client UI is open. Combined with {@link #isUnlocked}. */\n #isUiOpen = false;\n\n /** Whether the keyring is unlocked. Combined with {@link #isUiOpen}. */\n #isUnlocked = false;\n\n readonly #infuraProjectId: string;\n\n readonly #degradedBannerTimeout: number;\n\n readonly #unavailableBannerTimeout: number;\n\n /**\n * Constructs a new {@link NetworkConnectionBannerController}.\n *\n * @param args - The arguments to this controller.\n * @param args.messenger - The messenger suited for this controller.\n * @param args.infuraProjectId - The wallet's Infura project id.\n * @param args.degradedBannerTimeout - How long (in milliseconds) a failing\n * network must remain failed before the degraded banner appears.\n * @param args.unavailableBannerTimeout - How long (in milliseconds) before\n * the banner escalates to \"unavailable\". Must be greater than\n * `degradedBannerTimeout`.\n * @throws If `unavailableBannerTimeout` is not greater than\n * `degradedBannerTimeout`.\n */\n constructor({\n messenger,\n infuraProjectId,\n degradedBannerTimeout = DEFAULT_DEGRADED_BANNER_TIMEOUT,\n unavailableBannerTimeout = DEFAULT_UNAVAILABLE_BANNER_TIMEOUT,\n }: NetworkConnectionBannerControllerOptions) {\n super({\n messenger,\n metadata: networkConnectionBannerControllerMetadata,\n name: CONTROLLER_NAME,\n state: getDefaultNetworkConnectionBannerControllerState(),\n });\n\n if (unavailableBannerTimeout <= degradedBannerTimeout) {\n throw new Error(\n `\\`unavailableBannerTimeout\\` (${unavailableBannerTimeout}) must be greater than \\`degradedBannerTimeout\\` (${degradedBannerTimeout}).`,\n );\n }\n\n this.#infuraProjectId = infuraProjectId;\n this.#degradedBannerTimeout = degradedBannerTimeout;\n this.#unavailableBannerTimeout = unavailableBannerTimeout;\n\n // Upstream controllers still expose :stateChange; switch to :stateChanged\n // once those packages migrate their event types.\n /* eslint-disable no-restricted-syntax -- awaiting upstream :stateChanged migration */\n this.messenger.subscribe(\n 'NetworkController:stateChange',\n (networkControllerState) =>\n this.#refreshState({\n networkControllerState,\n networkEnablementControllerState: this.messenger.call(\n 'NetworkEnablementController:getState',\n ),\n connectivityControllerState: this.messenger.call(\n 'ConnectivityController:getState',\n ),\n }),\n selectNetworkControllerFields,\n );\n this.messenger.subscribe(\n 'NetworkEnablementController:stateChange',\n (networkEnablementControllerState) =>\n this.#refreshState({\n networkControllerState: this.messenger.call(\n 'NetworkController:getState',\n ),\n networkEnablementControllerState,\n connectivityControllerState: this.messenger.call(\n 'ConnectivityController:getState',\n ),\n }),\n selectNetworkEnablementControllerFields,\n );\n this.messenger.subscribe(\n 'ConnectivityController:stateChange',\n (connectivityControllerState) =>\n this.#refreshState({\n networkControllerState: this.messenger.call(\n 'NetworkController:getState',\n ),\n networkEnablementControllerState: this.messenger.call(\n 'NetworkEnablementController:getState',\n ),\n connectivityControllerState,\n }),\n selectConnectivityControllerFields,\n );\n /* eslint-enable no-restricted-syntax */\n\n // Lifecycle: evaluate RPC health (and run the banner escalation timers)\n // only while the client UI is open on an unlocked wallet.\n this.messenger.subscribe(\n // eslint-disable-next-line no-restricted-syntax -- awaiting upstream :stateChanged migration\n 'ClientController:stateChange',\n (isUiOpen) => {\n this.#isUiOpen = isUiOpen;\n this.#updateLifecycle();\n },\n clientControllerSelectors.selectIsUiOpen,\n );\n this.messenger.subscribe('KeyringController:unlock', () => {\n this.#isUnlocked = true;\n this.#updateLifecycle();\n });\n this.messenger.subscribe('KeyringController:lock', () => {\n this.#isUnlocked = false;\n this.#updateLifecycle();\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n #updateLifecycle(): void {\n if (this.#isUiOpen && this.#isUnlocked) {\n this.#start();\n } else {\n this.#stop();\n }\n }\n\n /**\n * Look for a failed network, if any, and populate the initial state of the\n * banner. Reacts to upstream state changes from this point on. Idempotent.\n */\n #start(): void {\n if (this.#isStarted) {\n return;\n }\n\n this.#isStarted = true;\n this.#refreshState({\n networkControllerState: this.messenger.call('NetworkController:getState'),\n networkEnablementControllerState: this.messenger.call(\n 'NetworkEnablementController:getState',\n ),\n connectivityControllerState: this.messenger.call(\n 'ConnectivityController:getState',\n ),\n });\n }\n\n /**\n * Stops evaluating network connection state. Clears any pending banner\n * timers and resets state to `available`. Idempotent.\n */\n #stop(): void {\n if (!this.#isStarted) {\n return;\n }\n\n this.#isStarted = false;\n this.#resetBanner();\n }\n\n /**\n * Clears the banner state such that the banner will be hidden.\n */\n dismissBanner(): void {\n this.#resetBanner();\n }\n\n /**\n * Switches the chain's default RPC endpoint to its Infura endpoint and\n * makes it the active network, causing the banner to clear once the\n * network becomes available again.\n *\n * @param chainId - The chain whose default RPC endpoint should be switched.\n * @throws If the chain configuration cannot be found, or if it has no\n * Infura endpoint to switch to, or if the default is already Infura.\n */\n async switchToDefaultInfuraRpcEndpoint(chainId: Hex): Promise<void> {\n const networkConfiguration = this.messenger.call(\n 'NetworkController:getNetworkConfigurationByChainId',\n chainId,\n );\n if (!networkConfiguration) {\n throw new Error(\n `No network configuration found for chain ID \"${chainId}\".`,\n );\n }\n\n const infuraEndpointIndex = networkConfiguration.rpcEndpoints.findIndex(\n (endpoint) => getIsInfuraEndpoint(endpoint.url, this.#infuraProjectId),\n );\n if (infuraEndpointIndex === -1) {\n throw new Error(\n `No Infura endpoint available for chain ID \"${chainId}\".`,\n );\n }\n if (infuraEndpointIndex === networkConfiguration.defaultRpcEndpointIndex) {\n // The default is already Infura; nothing to do.\n return;\n }\n\n // Move the active connection onto the Infura endpoint first, then make\n // it the default. In this order a partial failure leaves the failing\n // default in place and the banner visible, rather than hiding the banner\n // while the wallet is still connected to the broken endpoint.\n const infuraNetworkClientId =\n networkConfiguration.rpcEndpoints[infuraEndpointIndex].networkClientId;\n const { selectedNetworkClientId } = this.messenger.call(\n 'NetworkController:getState',\n );\n if (infuraNetworkClientId !== selectedNetworkClientId) {\n await this.messenger.call(\n 'NetworkController:setActiveNetwork',\n infuraNetworkClientId,\n );\n }\n\n await this.messenger.call('NetworkController:updateNetwork', chainId, {\n ...networkConfiguration,\n defaultRpcEndpointIndex: infuraEndpointIndex,\n });\n }\n\n #refreshState({\n networkControllerState,\n networkEnablementControllerState,\n connectivityControllerState,\n }: {\n networkControllerState: Pick<\n NetworkState,\n 'networkConfigurationsByChainId' | 'networksMetadata'\n >;\n networkEnablementControllerState: Pick<\n NetworkEnablementControllerState,\n 'enabledNetworkMap'\n >;\n connectivityControllerState: Pick<\n ConnectivityControllerState,\n 'connectivityStatus'\n >;\n }): void {\n if (!this.#isStarted) {\n return;\n }\n\n if (\n connectivityControllerState.connectivityStatus ===\n CONNECTIVITY_STATUSES.Offline\n ) {\n this.#resetBanner();\n return;\n }\n\n const failedNetwork = this.#findFailedNetwork(\n networkControllerState,\n networkEnablementControllerState,\n );\n if (!failedNetwork) {\n this.#resetBanner();\n return;\n }\n\n if (\n this.state.networkConnectionBannerStatus !== 'available' &&\n this.state.networkConnectionBannerNetwork?.networkClientId ===\n failedNetwork.networkClientId\n ) {\n this.update((state) => {\n // Even if the network client ID has not changed, save the current\n // version of the failed network to state in case the user has updated\n // its RPC URL.\n state.networkConnectionBannerNetwork = failedNetwork;\n });\n return;\n }\n\n // A degraded timer is already counting down for this same network.\n // Repeated `stateChange` events must not clear and restart it, or a\n // steady stream of updates could postpone the banner indefinitely.\n if (this.#pendingNetworkClientId === failedNetwork.networkClientId) {\n return;\n }\n\n this.#clearTimers();\n this.update((state) => {\n state.networkConnectionBannerStatus = 'available';\n state.networkConnectionBannerNetwork = null;\n });\n\n // If `stop` is called before scheduling timers, bail early.\n if (!this.#isStarted) {\n return;\n }\n\n // Remember which network the pending timer is for (see the guard above)\n // and capture the failing network at schedule time. If the failure\n // resolves or a different network becomes the banner target while we\n // wait, the subscription handlers re-enter this method and cancel or\n // replace the timer before it fires.\n this.#pendingNetworkClientId = failedNetwork.networkClientId;\n this.#degradedTimer = setTimeout(() => {\n this.#degradedTimer = undefined;\n this.#pendingNetworkClientId = undefined;\n this.update((state) => {\n state.networkConnectionBannerStatus = 'degraded';\n state.networkConnectionBannerNetwork = failedNetwork;\n });\n // If `stop` is called before scheduling timers, bail early.\n if (!this.#isStarted) {\n return;\n }\n this.#unavailableTimer = setTimeout(() => {\n this.#unavailableTimer = undefined;\n this.update((state) => {\n state.networkConnectionBannerStatus = 'unavailable';\n state.networkConnectionBannerNetwork = failedNetwork;\n });\n }, this.#unavailableBannerTimeout - this.#degradedBannerTimeout);\n }, this.#degradedBannerTimeout);\n }\n\n /**\n * Clears timers and resets banner state to {@link NetworkConnectionBannerStatus|`available`}\n * if it isn't there already.\n */\n #resetBanner(): void {\n this.#clearTimers();\n this.#pendingNetworkClientId = undefined;\n if (\n this.state.networkConnectionBannerStatus !== 'available' ||\n this.state.networkConnectionBannerNetwork !== null\n ) {\n this.update((state) => {\n state.networkConnectionBannerStatus = 'available';\n state.networkConnectionBannerNetwork = null;\n });\n }\n }\n\n #clearTimers(): void {\n if (this.#degradedTimer !== undefined) {\n clearTimeout(this.#degradedTimer);\n this.#degradedTimer = undefined;\n }\n if (this.#unavailableTimer !== undefined) {\n clearTimeout(this.#unavailableTimer);\n this.#unavailableTimer = undefined;\n }\n }\n\n #findFailedNetwork(\n networkState: Pick<\n NetworkState,\n 'networkConfigurationsByChainId' | 'networksMetadata'\n >,\n enablementState: Pick<\n NetworkEnablementControllerState,\n 'enabledNetworkMap'\n >,\n ): FailedNetwork | null {\n const enabledNetworks = this.#collectEnabledNetworks(\n networkState,\n enablementState,\n );\n // Networks whose connectivity has not been looked up yet are not failed.\n const failedNetworks = enabledNetworks\n .filter(\n ({ metadata }) =>\n metadata !== undefined && metadata.status !== NetworkStatus.Available,\n )\n .map((network) => this.#buildFailedNetwork(network));\n return this.#pickFailedNetworkToDisplay(\n failedNetworks,\n enabledNetworks.length,\n );\n }\n\n #getEnabledEvmChainIds(\n enabledNetworkMap: NetworkEnablementControllerState['enabledNetworkMap'],\n ): Hex[] {\n return Object.entries(enabledNetworkMap[KnownCaipNamespace.Eip155] ?? {})\n .filter(([, enabled]) => enabled)\n .map(([chainId]) => chainId as Hex);\n }\n\n #collectEnabledNetworks(\n {\n networkConfigurationsByChainId,\n networksMetadata,\n }: Pick<\n NetworkState,\n 'networkConfigurationsByChainId' | 'networksMetadata'\n >,\n {\n enabledNetworkMap,\n }: Pick<NetworkEnablementControllerState, 'enabledNetworkMap'>,\n ): EnabledNetwork[] {\n return this.#getEnabledEvmChainIds(enabledNetworkMap).flatMap((chainId) => {\n const networkConfiguration = networkConfigurationsByChainId[chainId];\n if (!networkConfiguration) {\n return [];\n }\n const { rpcEndpoints, defaultRpcEndpointIndex, name } =\n networkConfiguration;\n const defaultRpcEndpoint = rpcEndpoints[defaultRpcEndpointIndex];\n if (!defaultRpcEndpoint) {\n return [];\n }\n return [\n {\n chainId,\n name,\n rpcEndpoints,\n defaultRpcEndpointIndex,\n defaultRpcEndpoint,\n metadata: networksMetadata[defaultRpcEndpoint.networkClientId],\n },\n ];\n });\n }\n\n #buildFailedNetwork({\n chainId,\n name,\n rpcEndpoints,\n defaultRpcEndpointIndex,\n defaultRpcEndpoint,\n }: EnabledNetwork): FailedNetwork {\n const isInfuraEndpoint = getIsInfuraEndpoint(\n defaultRpcEndpoint.url,\n this.#infuraProjectId,\n );\n\n // For custom endpoints (non-Infura), find an Infura endpoint on this\n // chain that we could offer to switch to.\n let switchableInfuraNetworkClientId: string | null = null;\n if (!isInfuraEndpoint) {\n const infuraEndpoint = rpcEndpoints.find(\n (endpoint, index) =>\n index !== defaultRpcEndpointIndex &&\n getIsInfuraEndpoint(endpoint.url, this.#infuraProjectId),\n );\n switchableInfuraNetworkClientId = infuraEndpoint?.networkClientId ?? null;\n }\n\n return {\n chainId,\n networkClientId: defaultRpcEndpoint.networkClientId,\n name,\n rpcUrl: defaultRpcEndpoint.url,\n isInfuraEndpoint,\n switchableInfuraNetworkClientId,\n };\n }\n\n #pickFailedNetworkToDisplay(\n failedNetworks: FailedNetwork[],\n totalEnabledNetworks: number,\n ): FailedNetwork | null {\n if (failedNetworks.length === 0) {\n return null;\n }\n\n const firstCustomFailed = failedNetworks.find(\n (entry) => !entry.isInfuraEndpoint,\n );\n const areAllEnabledNetworksFailed =\n failedNetworks.length === totalEnabledNetworks;\n\n if (!firstCustomFailed && !areAllEnabledNetworksFailed) {\n return null;\n }\n\n return firstCustomFailed ?? failedNetworks[0];\n }\n}\n"]}
package/dist/index.cjs ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.networkConnectionBannerControllerSelectors = exports.DEFAULT_UNAVAILABLE_BANNER_TIMEOUT = exports.DEFAULT_DEGRADED_BANNER_TIMEOUT = exports.getDefaultNetworkConnectionBannerControllerState = exports.NetworkConnectionBannerController = void 0;
4
+ var NetworkConnectionBannerController_js_1 = require("./NetworkConnectionBannerController.cjs");
5
+ Object.defineProperty(exports, "NetworkConnectionBannerController", { enumerable: true, get: function () { return NetworkConnectionBannerController_js_1.NetworkConnectionBannerController; } });
6
+ Object.defineProperty(exports, "getDefaultNetworkConnectionBannerControllerState", { enumerable: true, get: function () { return NetworkConnectionBannerController_js_1.getDefaultNetworkConnectionBannerControllerState; } });
7
+ Object.defineProperty(exports, "DEFAULT_DEGRADED_BANNER_TIMEOUT", { enumerable: true, get: function () { return NetworkConnectionBannerController_js_1.DEFAULT_DEGRADED_BANNER_TIMEOUT; } });
8
+ Object.defineProperty(exports, "DEFAULT_UNAVAILABLE_BANNER_TIMEOUT", { enumerable: true, get: function () { return NetworkConnectionBannerController_js_1.DEFAULT_UNAVAILABLE_BANNER_TIMEOUT; } });
9
+ var selectors_js_1 = require("./selectors.cjs");
10
+ Object.defineProperty(exports, "networkConnectionBannerControllerSelectors", { enumerable: true, get: function () { return selectors_js_1.networkConnectionBannerControllerSelectors; } });
11
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAeA,gGAKgD;AAJ9C,yJAAA,iCAAiC,OAAA;AACjC,wKAAA,gDAAgD,OAAA;AAChD,uJAAA,+BAA+B,OAAA;AAC/B,0JAAA,kCAAkC,OAAA;AAEpC,gDAA4E;AAAnE,0IAAA,0CAA0C,OAAA","sourcesContent":["export type {\n NetworkConnectionBannerControllerState,\n NetworkConnectionBannerControllerGetStateAction,\n NetworkConnectionBannerControllerActions,\n NetworkConnectionBannerControllerStateChangedEvent,\n NetworkConnectionBannerControllerEvents,\n NetworkConnectionBannerControllerMessenger,\n NetworkConnectionBannerControllerOptions,\n FailedNetwork,\n NetworkConnectionBannerStatus,\n} from './NetworkConnectionBannerController.js';\nexport type {\n NetworkConnectionBannerControllerDismissBannerAction,\n NetworkConnectionBannerControllerSwitchToDefaultInfuraRpcEndpointAction,\n} from './NetworkConnectionBannerController-method-action-types.js';\nexport {\n NetworkConnectionBannerController,\n getDefaultNetworkConnectionBannerControllerState,\n DEFAULT_DEGRADED_BANNER_TIMEOUT,\n DEFAULT_UNAVAILABLE_BANNER_TIMEOUT,\n} from './NetworkConnectionBannerController.js';\nexport { networkConnectionBannerControllerSelectors } from './selectors.js';\n"]}
@@ -1,5 +1,5 @@
1
- export type { NetworkConnectionBannerControllerState, NetworkConnectionBannerControllerGetStateAction, NetworkConnectionBannerControllerActions, NetworkConnectionBannerControllerStateChangedEvent, NetworkConnectionBannerControllerEvents, NetworkConnectionBannerControllerMessenger, NetworkConnectionBannerControllerOptions, FailedNetwork, NetworkConnectionBannerStatus, } from './NetworkConnectionBannerController.js';
2
- export type { NetworkConnectionBannerControllerDismissBannerAction, NetworkConnectionBannerControllerSwitchToDefaultInfuraRpcEndpointAction, } from './NetworkConnectionBannerController-method-action-types.js';
3
- export { NetworkConnectionBannerController, getDefaultNetworkConnectionBannerControllerState, DEFAULT_DEGRADED_BANNER_TIMEOUT, DEFAULT_UNAVAILABLE_BANNER_TIMEOUT, } from './NetworkConnectionBannerController.js';
4
- export { networkConnectionBannerControllerSelectors } from './selectors.js';
5
- //# sourceMappingURL=index.d.ts.map
1
+ export type { NetworkConnectionBannerControllerState, NetworkConnectionBannerControllerGetStateAction, NetworkConnectionBannerControllerActions, NetworkConnectionBannerControllerStateChangedEvent, NetworkConnectionBannerControllerEvents, NetworkConnectionBannerControllerMessenger, NetworkConnectionBannerControllerOptions, FailedNetwork, NetworkConnectionBannerStatus, } from "./NetworkConnectionBannerController.cjs";
2
+ export type { NetworkConnectionBannerControllerDismissBannerAction, NetworkConnectionBannerControllerSwitchToDefaultInfuraRpcEndpointAction, } from "./NetworkConnectionBannerController-method-action-types.cjs";
3
+ export { NetworkConnectionBannerController, getDefaultNetworkConnectionBannerControllerState, DEFAULT_DEGRADED_BANNER_TIMEOUT, DEFAULT_UNAVAILABLE_BANNER_TIMEOUT, } from "./NetworkConnectionBannerController.cjs";
4
+ export { networkConnectionBannerControllerSelectors } from "./selectors.cjs";
5
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,sCAAsC,EACtC,+CAA+C,EAC/C,wCAAwC,EACxC,kDAAkD,EAClD,uCAAuC,EACvC,0CAA0C,EAC1C,wCAAwC,EACxC,aAAa,EACb,6BAA6B,GAC9B,gDAA+C;AAChD,YAAY,EACV,oDAAoD,EACpD,uEAAuE,GACxE,oEAAmE;AACpE,OAAO,EACL,iCAAiC,EACjC,gDAAgD,EAChD,+BAA+B,EAC/B,kCAAkC,GACnC,gDAA+C;AAChD,OAAO,EAAE,0CAA0C,EAAE,wBAAuB"}
@@ -0,0 +1,5 @@
1
+ export type { NetworkConnectionBannerControllerState, NetworkConnectionBannerControllerGetStateAction, NetworkConnectionBannerControllerActions, NetworkConnectionBannerControllerStateChangedEvent, NetworkConnectionBannerControllerEvents, NetworkConnectionBannerControllerMessenger, NetworkConnectionBannerControllerOptions, FailedNetwork, NetworkConnectionBannerStatus, } from "./NetworkConnectionBannerController.mjs";
2
+ export type { NetworkConnectionBannerControllerDismissBannerAction, NetworkConnectionBannerControllerSwitchToDefaultInfuraRpcEndpointAction, } from "./NetworkConnectionBannerController-method-action-types.mjs";
3
+ export { NetworkConnectionBannerController, getDefaultNetworkConnectionBannerControllerState, DEFAULT_DEGRADED_BANNER_TIMEOUT, DEFAULT_UNAVAILABLE_BANNER_TIMEOUT, } from "./NetworkConnectionBannerController.mjs";
4
+ export { networkConnectionBannerControllerSelectors } from "./selectors.mjs";
5
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,sCAAsC,EACtC,+CAA+C,EAC/C,wCAAwC,EACxC,kDAAkD,EAClD,uCAAuC,EACvC,0CAA0C,EAC1C,wCAAwC,EACxC,aAAa,EACb,6BAA6B,GAC9B,gDAA+C;AAChD,YAAY,EACV,oDAAoD,EACpD,uEAAuE,GACxE,oEAAmE;AACpE,OAAO,EACL,iCAAiC,EACjC,gDAAgD,EAChD,+BAA+B,EAC/B,kCAAkC,GACnC,gDAA+C;AAChD,OAAO,EAAE,0CAA0C,EAAE,wBAAuB"}
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ export { NetworkConnectionBannerController, getDefaultNetworkConnectionBannerControllerState, DEFAULT_DEGRADED_BANNER_TIMEOUT, DEFAULT_UNAVAILABLE_BANNER_TIMEOUT } from "./NetworkConnectionBannerController.mjs";
2
+ export { networkConnectionBannerControllerSelectors } from "./selectors.mjs";
3
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAeA,OAAO,EACL,iCAAiC,EACjC,gDAAgD,EAChD,+BAA+B,EAC/B,kCAAkC,EACnC,gDAA+C;AAChD,OAAO,EAAE,0CAA0C,EAAE,wBAAuB","sourcesContent":["export type {\n NetworkConnectionBannerControllerState,\n NetworkConnectionBannerControllerGetStateAction,\n NetworkConnectionBannerControllerActions,\n NetworkConnectionBannerControllerStateChangedEvent,\n NetworkConnectionBannerControllerEvents,\n NetworkConnectionBannerControllerMessenger,\n NetworkConnectionBannerControllerOptions,\n FailedNetwork,\n NetworkConnectionBannerStatus,\n} from './NetworkConnectionBannerController.js';\nexport type {\n NetworkConnectionBannerControllerDismissBannerAction,\n NetworkConnectionBannerControllerSwitchToDefaultInfuraRpcEndpointAction,\n} from './NetworkConnectionBannerController-method-action-types.js';\nexport {\n NetworkConnectionBannerController,\n getDefaultNetworkConnectionBannerControllerState,\n DEFAULT_DEGRADED_BANNER_TIMEOUT,\n DEFAULT_UNAVAILABLE_BANNER_TIMEOUT,\n} from './NetworkConnectionBannerController.js';\nexport { networkConnectionBannerControllerSelectors } from './selectors.js';\n"]}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.networkConnectionBannerControllerSelectors = void 0;
4
+ const reselect_1 = require("reselect");
5
+ /**
6
+ * Selects the banner status from the controller state.
7
+ *
8
+ * @param state - The controller state
9
+ * @returns The banner status
10
+ */
11
+ const selectNetworkConnectionBannerStatus = (state) => state.networkConnectionBannerStatus;
12
+ /**
13
+ * Selects the failing network the banner describes, or `null` when no banner
14
+ * is shown.
15
+ *
16
+ * @param state - The controller state
17
+ * @returns The failing network details, or `null`
18
+ */
19
+ const selectNetworkConnectionBannerNetwork = (state) => state.networkConnectionBannerNetwork;
20
+ /**
21
+ * Selects whether the banner is visible (status is `degraded` or
22
+ * `unavailable`).
23
+ *
24
+ * @param state - The controller state
25
+ * @returns Whether the banner is visible
26
+ */
27
+ const selectIsNetworkConnectionBannerVisible = (0, reselect_1.createSelector)([selectNetworkConnectionBannerStatus], (status) => status === 'degraded' || status === 'unavailable');
28
+ /**
29
+ * Selectors for the NetworkConnectionBannerController state.
30
+ * These can be used with Redux or directly with controller state.
31
+ */
32
+ exports.networkConnectionBannerControllerSelectors = {
33
+ selectNetworkConnectionBannerStatus,
34
+ selectNetworkConnectionBannerNetwork,
35
+ selectIsNetworkConnectionBannerVisible,
36
+ };
37
+ //# sourceMappingURL=selectors.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectors.cjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":";;;AAAA,uCAA0C;AAQ1C;;;;;GAKG;AACH,MAAM,mCAAmC,GAAG,CAC1C,KAA6C,EACd,EAAE,CAAC,KAAK,CAAC,6BAA6B,CAAC;AAExE;;;;;;GAMG;AACH,MAAM,oCAAoC,GAAG,CAC3C,KAA6C,EACvB,EAAE,CAAC,KAAK,CAAC,8BAA8B,CAAC;AAEhE;;;;;;GAMG;AACH,MAAM,sCAAsC,GAAG,IAAA,yBAAc,EAC3D,CAAC,mCAAmC,CAAC,EACrC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,UAAU,IAAI,MAAM,KAAK,aAAa,CAC9D,CAAC;AAEF;;;GAGG;AACU,QAAA,0CAA0C,GAAG;IACxD,mCAAmC;IACnC,oCAAoC;IACpC,sCAAsC;CACvC,CAAC","sourcesContent":["import { createSelector } from 'reselect';\n\nimport type {\n NetworkConnectionBannerControllerState,\n FailedNetwork,\n NetworkConnectionBannerStatus,\n} from './NetworkConnectionBannerController.js';\n\n/**\n * Selects the banner status from the controller state.\n *\n * @param state - The controller state\n * @returns The banner status\n */\nconst selectNetworkConnectionBannerStatus = (\n state: NetworkConnectionBannerControllerState,\n): NetworkConnectionBannerStatus => state.networkConnectionBannerStatus;\n\n/**\n * Selects the failing network the banner describes, or `null` when no banner\n * is shown.\n *\n * @param state - The controller state\n * @returns The failing network details, or `null`\n */\nconst selectNetworkConnectionBannerNetwork = (\n state: NetworkConnectionBannerControllerState,\n): FailedNetwork | null => state.networkConnectionBannerNetwork;\n\n/**\n * Selects whether the banner is visible (status is `degraded` or\n * `unavailable`).\n *\n * @param state - The controller state\n * @returns Whether the banner is visible\n */\nconst selectIsNetworkConnectionBannerVisible = createSelector(\n [selectNetworkConnectionBannerStatus],\n (status) => status === 'degraded' || status === 'unavailable',\n);\n\n/**\n * Selectors for the NetworkConnectionBannerController state.\n * These can be used with Redux or directly with controller state.\n */\nexport const networkConnectionBannerControllerSelectors = {\n selectNetworkConnectionBannerStatus,\n selectNetworkConnectionBannerNetwork,\n selectIsNetworkConnectionBannerVisible,\n};\n"]}
@@ -1,26 +1,11 @@
1
- import type { NetworkConnectionBannerControllerState, FailedNetwork, NetworkConnectionBannerStatus } from './NetworkConnectionBannerController.js';
2
- /**
3
- * Selects the banner status from the controller state.
4
- *
5
- * @param state - The controller state
6
- * @returns The banner status
7
- */
8
- declare const selectNetworkConnectionBannerStatus: (state: NetworkConnectionBannerControllerState) => NetworkConnectionBannerStatus;
9
- /**
10
- * Selects the failing network the banner describes, or `null` when no banner
11
- * is shown.
12
- *
13
- * @param state - The controller state
14
- * @returns The failing network details, or `null`
15
- */
16
- declare const selectNetworkConnectionBannerNetwork: (state: NetworkConnectionBannerControllerState) => FailedNetwork | null;
1
+ import type { NetworkConnectionBannerControllerState, FailedNetwork, NetworkConnectionBannerStatus } from "./NetworkConnectionBannerController.cjs";
17
2
  /**
18
3
  * Selectors for the NetworkConnectionBannerController state.
19
4
  * These can be used with Redux or directly with controller state.
20
5
  */
21
6
  export declare const networkConnectionBannerControllerSelectors: {
22
- selectNetworkConnectionBannerStatus: typeof selectNetworkConnectionBannerStatus;
23
- selectNetworkConnectionBannerNetwork: typeof selectNetworkConnectionBannerNetwork;
7
+ selectNetworkConnectionBannerStatus: (state: NetworkConnectionBannerControllerState) => NetworkConnectionBannerStatus;
8
+ selectNetworkConnectionBannerNetwork: (state: NetworkConnectionBannerControllerState) => FailedNetwork | null;
24
9
  selectIsNetworkConnectionBannerVisible: ((state: NetworkConnectionBannerControllerState) => boolean) & {
25
10
  clearCache: () => void;
26
11
  resultsCount: () => number;
@@ -33,7 +18,7 @@ export declare const networkConnectionBannerControllerSelectors: {
33
18
  resetResultsCount: () => void;
34
19
  };
35
20
  lastResult: () => boolean;
36
- dependencies: [typeof selectNetworkConnectionBannerStatus];
21
+ dependencies: [(state: NetworkConnectionBannerControllerState) => NetworkConnectionBannerStatus];
37
22
  recomputations: () => number;
38
23
  resetRecomputations: () => void;
39
24
  dependencyRecomputations: () => number;
@@ -43,5 +28,4 @@ export declare const networkConnectionBannerControllerSelectors: {
43
28
  argsMemoize: typeof import("reselect").weakMapMemoize;
44
29
  };
45
30
  };
46
- export {};
47
- //# sourceMappingURL=selectors.d.ts.map
31
+ //# sourceMappingURL=selectors.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectors.d.cts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,sCAAsC,EACtC,aAAa,EACb,6BAA6B,EAC9B,gDAA+C;AAmChD;;;GAGG;AACH,eAAO,MAAM,0CAA0C;iDA9B9C,sCAAsC,KAC5C,6BAA6B;kDAUvB,sCAAsC,KAC5C,aAAa,GAAG,IAAI;;;;;;;;;;;;;+BAZd,sCAAsC,KAC5C,6BAA6B;;;;;;;;;CAiC/B,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { NetworkConnectionBannerControllerState, FailedNetwork, NetworkConnectionBannerStatus } from "./NetworkConnectionBannerController.mjs";
2
+ /**
3
+ * Selectors for the NetworkConnectionBannerController state.
4
+ * These can be used with Redux or directly with controller state.
5
+ */
6
+ export declare const networkConnectionBannerControllerSelectors: {
7
+ selectNetworkConnectionBannerStatus: (state: NetworkConnectionBannerControllerState) => NetworkConnectionBannerStatus;
8
+ selectNetworkConnectionBannerNetwork: (state: NetworkConnectionBannerControllerState) => FailedNetwork | null;
9
+ selectIsNetworkConnectionBannerVisible: ((state: NetworkConnectionBannerControllerState) => boolean) & {
10
+ clearCache: () => void;
11
+ resultsCount: () => number;
12
+ resetResultsCount: () => void;
13
+ } & {
14
+ resultFunc: (resultFuncArgs_0: NetworkConnectionBannerStatus) => boolean;
15
+ memoizedResultFunc: ((resultFuncArgs_0: NetworkConnectionBannerStatus) => boolean) & {
16
+ clearCache: () => void;
17
+ resultsCount: () => number;
18
+ resetResultsCount: () => void;
19
+ };
20
+ lastResult: () => boolean;
21
+ dependencies: [(state: NetworkConnectionBannerControllerState) => NetworkConnectionBannerStatus];
22
+ recomputations: () => number;
23
+ resetRecomputations: () => void;
24
+ dependencyRecomputations: () => number;
25
+ resetDependencyRecomputations: () => void;
26
+ } & {
27
+ memoize: typeof import("reselect").weakMapMemoize;
28
+ argsMemoize: typeof import("reselect").weakMapMemoize;
29
+ };
30
+ };
31
+ //# sourceMappingURL=selectors.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectors.d.mts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,sCAAsC,EACtC,aAAa,EACb,6BAA6B,EAC9B,gDAA+C;AAmChD;;;GAGG;AACH,eAAO,MAAM,0CAA0C;iDA9B9C,sCAAsC,KAC5C,6BAA6B;kDAUvB,sCAAsC,KAC5C,aAAa,GAAG,IAAI;;;;;;;;;;;;;+BAZd,sCAAsC,KAC5C,6BAA6B;;;;;;;;;CAiC/B,CAAC"}
@@ -1,4 +1,4 @@
1
- import { createSelector } from 'reselect';
1
+ import { createSelector } from "reselect";
2
2
  /**
3
3
  * Selects the banner status from the controller state.
4
4
  *
@@ -31,4 +31,4 @@ export const networkConnectionBannerControllerSelectors = {
31
31
  selectNetworkConnectionBannerNetwork,
32
32
  selectIsNetworkConnectionBannerVisible,
33
33
  };
34
- //# sourceMappingURL=selectors.js.map
34
+ //# sourceMappingURL=selectors.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectors.mjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB;AAQ1C;;;;;GAKG;AACH,MAAM,mCAAmC,GAAG,CAC1C,KAA6C,EACd,EAAE,CAAC,KAAK,CAAC,6BAA6B,CAAC;AAExE;;;;;;GAMG;AACH,MAAM,oCAAoC,GAAG,CAC3C,KAA6C,EACvB,EAAE,CAAC,KAAK,CAAC,8BAA8B,CAAC;AAEhE;;;;;;GAMG;AACH,MAAM,sCAAsC,GAAG,cAAc,CAC3D,CAAC,mCAAmC,CAAC,EACrC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,UAAU,IAAI,MAAM,KAAK,aAAa,CAC9D,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,0CAA0C,GAAG;IACxD,mCAAmC;IACnC,oCAAoC;IACpC,sCAAsC;CACvC,CAAC","sourcesContent":["import { createSelector } from 'reselect';\n\nimport type {\n NetworkConnectionBannerControllerState,\n FailedNetwork,\n NetworkConnectionBannerStatus,\n} from './NetworkConnectionBannerController.js';\n\n/**\n * Selects the banner status from the controller state.\n *\n * @param state - The controller state\n * @returns The banner status\n */\nconst selectNetworkConnectionBannerStatus = (\n state: NetworkConnectionBannerControllerState,\n): NetworkConnectionBannerStatus => state.networkConnectionBannerStatus;\n\n/**\n * Selects the failing network the banner describes, or `null` when no banner\n * is shown.\n *\n * @param state - The controller state\n * @returns The failing network details, or `null`\n */\nconst selectNetworkConnectionBannerNetwork = (\n state: NetworkConnectionBannerControllerState,\n): FailedNetwork | null => state.networkConnectionBannerNetwork;\n\n/**\n * Selects whether the banner is visible (status is `degraded` or\n * `unavailable`).\n *\n * @param state - The controller state\n * @returns Whether the banner is visible\n */\nconst selectIsNetworkConnectionBannerVisible = createSelector(\n [selectNetworkConnectionBannerStatus],\n (status) => status === 'degraded' || status === 'unavailable',\n);\n\n/**\n * Selectors for the NetworkConnectionBannerController state.\n * These can be used with Redux or directly with controller state.\n */\nexport const networkConnectionBannerControllerSelectors = {\n selectNetworkConnectionBannerStatus,\n selectNetworkConnectionBannerNetwork,\n selectIsNetworkConnectionBannerVisible,\n};\n"]}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getIsInfuraEndpoint = void 0;
4
+ /**
5
+ * Escape a string for literal use inside a regular expression.
6
+ *
7
+ * @param value - The string to escape.
8
+ * @returns The escaped string.
9
+ */
10
+ function escapeRegExp(value) {
11
+ return value.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
12
+ }
13
+ /**
14
+ * Whether an RPC URL is a MetaMask Infura endpoint. Built-in network
15
+ * configurations keep the `{infuraProjectId}` placeholder (substitution
16
+ * happens at request time), while some flows (e.g. adding a popular network)
17
+ * persist the URL with the wallet's own project id already substituted, so
18
+ * both shapes are matched.
19
+ *
20
+ * @param url - The RPC URL to check.
21
+ * @param infuraProjectId - The wallet's Infura project id.
22
+ * @returns True if the URL is a MetaMask Infura endpoint.
23
+ */
24
+ function getIsInfuraEndpoint(url, infuraProjectId) {
25
+ return new RegExp(`^https://[^./]+\\.infura\\.io/v3/(?:\\{infuraProjectId\\}|${escapeRegExp(infuraProjectId)})$`, 'u').test(url);
26
+ }
27
+ exports.getIsInfuraEndpoint = getIsInfuraEndpoint;
28
+ //# sourceMappingURL=url-utils.cjs.map