@metamask-previews/network-connection-banner-controller 0.1.0-preview-fe651cdb3 → 0.1.0-preview-cadd612bb
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.
- package/CHANGELOG.md +4 -1
- package/README.md +21 -0
- package/dist/NetworkConnectionBannerController-method-action-types.cjs.map +1 -1
- package/dist/NetworkConnectionBannerController-method-action-types.d.cts +30 -10
- package/dist/NetworkConnectionBannerController-method-action-types.d.cts.map +1 -1
- package/dist/NetworkConnectionBannerController-method-action-types.d.mts +30 -10
- package/dist/NetworkConnectionBannerController-method-action-types.d.mts.map +1 -1
- package/dist/NetworkConnectionBannerController-method-action-types.mjs.map +1 -1
- package/dist/NetworkConnectionBannerController.cjs +200 -103
- package/dist/NetworkConnectionBannerController.cjs.map +1 -1
- package/dist/NetworkConnectionBannerController.d.cts +47 -26
- package/dist/NetworkConnectionBannerController.d.cts.map +1 -1
- package/dist/NetworkConnectionBannerController.d.mts +47 -26
- package/dist/NetworkConnectionBannerController.d.mts.map +1 -1
- package/dist/NetworkConnectionBannerController.mjs +201 -104
- package/dist/NetworkConnectionBannerController.mjs.map +1 -1
- package/dist/index.cjs +1 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +0 -1
- package/dist/index.mjs.map +1 -1
- package/dist/selectors.cjs.map +1 -1
- package/dist/selectors.d.cts +2 -2
- package/dist/selectors.d.cts.map +1 -1
- package/dist/selectors.d.mts +2 -2
- package/dist/selectors.d.mts.map +1 -1
- package/dist/selectors.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Added
|
|
11
11
|
|
|
12
|
-
-
|
|
12
|
+
- Add `NetworkConnectionBannerController`, which evaluates enabled network RPC
|
|
13
|
+
health after initialization and manages degraded and unavailable banner state,
|
|
14
|
+
dismissal, and switching custom RPC endpoints to an available Infura endpoint
|
|
15
|
+
([#9041](https://github.com/MetaMask/core/pull/9041))
|
|
13
16
|
|
|
14
17
|
[Unreleased]: https://github.com/MetaMask/core/
|
package/README.md
CHANGED
|
@@ -5,6 +5,27 @@ connection banner based on RPC endpoint health. It encapsulates the shared
|
|
|
5
5
|
rule, the 5s/30s timer state machine, and the eTLD+1 grouping previously
|
|
6
6
|
duplicated across MetaMask clients.
|
|
7
7
|
|
|
8
|
+
## Lifecycle
|
|
9
|
+
|
|
10
|
+
The controller stays dormant after construction so the 5s / 30s escalation
|
|
11
|
+
timers do not run before a user is actually looking at the wallet (e.g. while
|
|
12
|
+
the app is still on the lock screen). The UI that renders the banner is
|
|
13
|
+
responsible for driving the lifecycle:
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
// When the wallet UI that shows the banner becomes active
|
|
17
|
+
// (e.g. the home surface mounts after unlock):
|
|
18
|
+
networkConnectionBannerController.start();
|
|
19
|
+
|
|
20
|
+
// When it goes away:
|
|
21
|
+
networkConnectionBannerController.stop();
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Both methods are idempotent. `start` runs the initial evaluation immediately
|
|
25
|
+
and enables reactions to upstream state changes. `stop` cancels any pending
|
|
26
|
+
timers and resets the banner state to `available`. Upstream state changes are
|
|
27
|
+
ignored while stopped.
|
|
28
|
+
|
|
8
29
|
## Installation
|
|
9
30
|
|
|
10
31
|
`yarn add @metamask/network-connection-banner-controller`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkConnectionBannerController-method-action-types.cjs","sourceRoot":"","sources":["../src/NetworkConnectionBannerController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { NetworkConnectionBannerController } from './NetworkConnectionBannerController';\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"NetworkConnectionBannerController-method-action-types.cjs","sourceRoot":"","sources":["../src/NetworkConnectionBannerController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { NetworkConnectionBannerController } from './NetworkConnectionBannerController';\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.\n *\n * Call this when the wallet UI that consumes the banner becomes active\n * (typically when the wallet is unlocked and the home surface mounts) so\n * timers do not run while the user is not looking at the wallet. Should\n * be called after `NetworkController`, `NetworkEnablementController`, and\n * `ConnectivityController` have been initialized. Idempotent.\n */\nexport type NetworkConnectionBannerControllerStartAction = {\n type: `NetworkConnectionBannerController:start`;\n handler: NetworkConnectionBannerController['start'];\n};\n\n/**\n * Stops evaluating network connection state. Clears any pending banner\n * timers and resets state to `available`. Call this when the UI\n * consuming the banner is no longer active. Idempotent.\n */\nexport type NetworkConnectionBannerControllerStopAction = {\n type: `NetworkConnectionBannerController:stop`;\n handler: NetworkConnectionBannerController['stop'];\n};\n\n/**\n * Clears the banner state such that the banner will be hidden.\n */\nexport type NetworkConnectionBannerControllerDismissBannerAction = {\n type: `NetworkConnectionBannerController:dismissBanner`;\n handler: NetworkConnectionBannerController['dismissBanner'];\n};\n\n/**\n * Switches the chain's default RPC endpoint to its Infura endpoint,\n * causing the banner to clear once the 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 */\nexport type NetworkConnectionBannerControllerSwitchToDefaultInfuraRpcEndpointAction =\n {\n type: `NetworkConnectionBannerController:switchToDefaultInfuraRpcEndpoint`;\n handler: NetworkConnectionBannerController['switchToDefaultInfuraRpcEndpoint'];\n };\n\n/**\n * Union of all NetworkConnectionBannerController action types.\n */\nexport type NetworkConnectionBannerControllerMethodActions =\n | NetworkConnectionBannerControllerStartAction\n | NetworkConnectionBannerControllerStopAction\n | NetworkConnectionBannerControllerDismissBannerAction\n | NetworkConnectionBannerControllerSwitchToDefaultInfuraRpcEndpointAction;\n"]}
|
|
@@ -4,29 +4,49 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { NetworkConnectionBannerController } from "./NetworkConnectionBannerController.cjs";
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Look for a failed network, if any, and populate the initial state of the
|
|
8
|
+
* banner. Reacts to upstream state changes from this point on.
|
|
9
|
+
*
|
|
10
|
+
* Call this when the wallet UI that consumes the banner becomes active
|
|
11
|
+
* (typically when the wallet is unlocked and the home surface mounts) so
|
|
12
|
+
* timers do not run while the user is not looking at the wallet. Should
|
|
13
|
+
* be called after `NetworkController`, `NetworkEnablementController`, and
|
|
14
|
+
* `ConnectivityController` have been initialized. Idempotent.
|
|
15
|
+
*/
|
|
16
|
+
export type NetworkConnectionBannerControllerStartAction = {
|
|
17
|
+
type: `NetworkConnectionBannerController:start`;
|
|
18
|
+
handler: NetworkConnectionBannerController['start'];
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Stops evaluating network connection state. Clears any pending banner
|
|
22
|
+
* timers and resets state to `available`. Call this when the UI
|
|
23
|
+
* consuming the banner is no longer active. Idempotent.
|
|
24
|
+
*/
|
|
25
|
+
export type NetworkConnectionBannerControllerStopAction = {
|
|
26
|
+
type: `NetworkConnectionBannerController:stop`;
|
|
27
|
+
handler: NetworkConnectionBannerController['stop'];
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Clears the banner state such that the banner will be hidden.
|
|
10
31
|
*/
|
|
11
32
|
export type NetworkConnectionBannerControllerDismissBannerAction = {
|
|
12
33
|
type: `NetworkConnectionBannerController:dismissBanner`;
|
|
13
34
|
handler: NetworkConnectionBannerController['dismissBanner'];
|
|
14
35
|
};
|
|
15
36
|
/**
|
|
16
|
-
* Switches the chain's default RPC endpoint to its
|
|
37
|
+
* Switches the chain's default RPC endpoint to its Infura endpoint,
|
|
17
38
|
* causing the banner to clear once the network becomes available again.
|
|
18
39
|
*
|
|
19
|
-
* @param
|
|
20
|
-
* @param args.chainId - The chain whose default RPC should be switched.
|
|
40
|
+
* @param chainId - The chain whose default RPC endpoint should be switched.
|
|
21
41
|
* @throws If the chain configuration cannot be found, or if it has no
|
|
22
42
|
* Infura endpoint to switch to, or if the default is already Infura.
|
|
23
43
|
*/
|
|
24
|
-
export type
|
|
25
|
-
type: `NetworkConnectionBannerController:
|
|
26
|
-
handler: NetworkConnectionBannerController['
|
|
44
|
+
export type NetworkConnectionBannerControllerSwitchToDefaultInfuraRpcEndpointAction = {
|
|
45
|
+
type: `NetworkConnectionBannerController:switchToDefaultInfuraRpcEndpoint`;
|
|
46
|
+
handler: NetworkConnectionBannerController['switchToDefaultInfuraRpcEndpoint'];
|
|
27
47
|
};
|
|
28
48
|
/**
|
|
29
49
|
* Union of all NetworkConnectionBannerController action types.
|
|
30
50
|
*/
|
|
31
|
-
export type NetworkConnectionBannerControllerMethodActions = NetworkConnectionBannerControllerDismissBannerAction |
|
|
51
|
+
export type NetworkConnectionBannerControllerMethodActions = NetworkConnectionBannerControllerStartAction | NetworkConnectionBannerControllerStopAction | NetworkConnectionBannerControllerDismissBannerAction | NetworkConnectionBannerControllerSwitchToDefaultInfuraRpcEndpointAction;
|
|
32
52
|
//# sourceMappingURL=NetworkConnectionBannerController-method-action-types.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkConnectionBannerController-method-action-types.d.cts","sourceRoot":"","sources":["../src/NetworkConnectionBannerController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iCAAiC,EAAE,gDAA4C;AAE7F;;;;GAIG;AACH,MAAM,MAAM,oDAAoD,GAAG;IACjE,IAAI,EAAE,iDAAiD,CAAC;IACxD,OAAO,EAAE,iCAAiC,CAAC,eAAe,CAAC,CAAC;CAC7D,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"NetworkConnectionBannerController-method-action-types.d.cts","sourceRoot":"","sources":["../src/NetworkConnectionBannerController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iCAAiC,EAAE,gDAA4C;AAE7F;;;;;;;;;GASG;AACH,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,iCAAiC,CAAC,OAAO,CAAC,CAAC;CACrD,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,iCAAiC,CAAC,MAAM,CAAC,CAAC;CACpD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oDAAoD,GAAG;IACjE,IAAI,EAAE,iDAAiD,CAAC;IACxD,OAAO,EAAE,iCAAiC,CAAC,eAAe,CAAC,CAAC;CAC7D,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,uEAAuE,GACjF;IACE,IAAI,EAAE,oEAAoE,CAAC;IAC3E,OAAO,EAAE,iCAAiC,CAAC,kCAAkC,CAAC,CAAC;CAChF,CAAC;AAEJ;;GAEG;AACH,MAAM,MAAM,8CAA8C,GACtD,4CAA4C,GAC5C,2CAA2C,GAC3C,oDAAoD,GACpD,uEAAuE,CAAC"}
|
|
@@ -4,29 +4,49 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { NetworkConnectionBannerController } from "./NetworkConnectionBannerController.mjs";
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Look for a failed network, if any, and populate the initial state of the
|
|
8
|
+
* banner. Reacts to upstream state changes from this point on.
|
|
9
|
+
*
|
|
10
|
+
* Call this when the wallet UI that consumes the banner becomes active
|
|
11
|
+
* (typically when the wallet is unlocked and the home surface mounts) so
|
|
12
|
+
* timers do not run while the user is not looking at the wallet. Should
|
|
13
|
+
* be called after `NetworkController`, `NetworkEnablementController`, and
|
|
14
|
+
* `ConnectivityController` have been initialized. Idempotent.
|
|
15
|
+
*/
|
|
16
|
+
export type NetworkConnectionBannerControllerStartAction = {
|
|
17
|
+
type: `NetworkConnectionBannerController:start`;
|
|
18
|
+
handler: NetworkConnectionBannerController['start'];
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Stops evaluating network connection state. Clears any pending banner
|
|
22
|
+
* timers and resets state to `available`. Call this when the UI
|
|
23
|
+
* consuming the banner is no longer active. Idempotent.
|
|
24
|
+
*/
|
|
25
|
+
export type NetworkConnectionBannerControllerStopAction = {
|
|
26
|
+
type: `NetworkConnectionBannerController:stop`;
|
|
27
|
+
handler: NetworkConnectionBannerController['stop'];
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Clears the banner state such that the banner will be hidden.
|
|
10
31
|
*/
|
|
11
32
|
export type NetworkConnectionBannerControllerDismissBannerAction = {
|
|
12
33
|
type: `NetworkConnectionBannerController:dismissBanner`;
|
|
13
34
|
handler: NetworkConnectionBannerController['dismissBanner'];
|
|
14
35
|
};
|
|
15
36
|
/**
|
|
16
|
-
* Switches the chain's default RPC endpoint to its
|
|
37
|
+
* Switches the chain's default RPC endpoint to its Infura endpoint,
|
|
17
38
|
* causing the banner to clear once the network becomes available again.
|
|
18
39
|
*
|
|
19
|
-
* @param
|
|
20
|
-
* @param args.chainId - The chain whose default RPC should be switched.
|
|
40
|
+
* @param chainId - The chain whose default RPC endpoint should be switched.
|
|
21
41
|
* @throws If the chain configuration cannot be found, or if it has no
|
|
22
42
|
* Infura endpoint to switch to, or if the default is already Infura.
|
|
23
43
|
*/
|
|
24
|
-
export type
|
|
25
|
-
type: `NetworkConnectionBannerController:
|
|
26
|
-
handler: NetworkConnectionBannerController['
|
|
44
|
+
export type NetworkConnectionBannerControllerSwitchToDefaultInfuraRpcEndpointAction = {
|
|
45
|
+
type: `NetworkConnectionBannerController:switchToDefaultInfuraRpcEndpoint`;
|
|
46
|
+
handler: NetworkConnectionBannerController['switchToDefaultInfuraRpcEndpoint'];
|
|
27
47
|
};
|
|
28
48
|
/**
|
|
29
49
|
* Union of all NetworkConnectionBannerController action types.
|
|
30
50
|
*/
|
|
31
|
-
export type NetworkConnectionBannerControllerMethodActions = NetworkConnectionBannerControllerDismissBannerAction |
|
|
51
|
+
export type NetworkConnectionBannerControllerMethodActions = NetworkConnectionBannerControllerStartAction | NetworkConnectionBannerControllerStopAction | NetworkConnectionBannerControllerDismissBannerAction | NetworkConnectionBannerControllerSwitchToDefaultInfuraRpcEndpointAction;
|
|
32
52
|
//# sourceMappingURL=NetworkConnectionBannerController-method-action-types.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkConnectionBannerController-method-action-types.d.mts","sourceRoot":"","sources":["../src/NetworkConnectionBannerController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iCAAiC,EAAE,gDAA4C;AAE7F;;;;GAIG;AACH,MAAM,MAAM,oDAAoD,GAAG;IACjE,IAAI,EAAE,iDAAiD,CAAC;IACxD,OAAO,EAAE,iCAAiC,CAAC,eAAe,CAAC,CAAC;CAC7D,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"NetworkConnectionBannerController-method-action-types.d.mts","sourceRoot":"","sources":["../src/NetworkConnectionBannerController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iCAAiC,EAAE,gDAA4C;AAE7F;;;;;;;;;GASG;AACH,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,iCAAiC,CAAC,OAAO,CAAC,CAAC;CACrD,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,iCAAiC,CAAC,MAAM,CAAC,CAAC;CACpD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oDAAoD,GAAG;IACjE,IAAI,EAAE,iDAAiD,CAAC;IACxD,OAAO,EAAE,iCAAiC,CAAC,eAAe,CAAC,CAAC;CAC7D,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,uEAAuE,GACjF;IACE,IAAI,EAAE,oEAAoE,CAAC;IAC3E,OAAO,EAAE,iCAAiC,CAAC,kCAAkC,CAAC,CAAC;CAChF,CAAC;AAEJ;;GAEG;AACH,MAAM,MAAM,8CAA8C,GACtD,4CAA4C,GAC5C,2CAA2C,GAC3C,oDAAoD,GACpD,uEAAuE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkConnectionBannerController-method-action-types.mjs","sourceRoot":"","sources":["../src/NetworkConnectionBannerController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { NetworkConnectionBannerController } from './NetworkConnectionBannerController';\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"NetworkConnectionBannerController-method-action-types.mjs","sourceRoot":"","sources":["../src/NetworkConnectionBannerController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { NetworkConnectionBannerController } from './NetworkConnectionBannerController';\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.\n *\n * Call this when the wallet UI that consumes the banner becomes active\n * (typically when the wallet is unlocked and the home surface mounts) so\n * timers do not run while the user is not looking at the wallet. Should\n * be called after `NetworkController`, `NetworkEnablementController`, and\n * `ConnectivityController` have been initialized. Idempotent.\n */\nexport type NetworkConnectionBannerControllerStartAction = {\n type: `NetworkConnectionBannerController:start`;\n handler: NetworkConnectionBannerController['start'];\n};\n\n/**\n * Stops evaluating network connection state. Clears any pending banner\n * timers and resets state to `available`. Call this when the UI\n * consuming the banner is no longer active. Idempotent.\n */\nexport type NetworkConnectionBannerControllerStopAction = {\n type: `NetworkConnectionBannerController:stop`;\n handler: NetworkConnectionBannerController['stop'];\n};\n\n/**\n * Clears the banner state such that the banner will be hidden.\n */\nexport type NetworkConnectionBannerControllerDismissBannerAction = {\n type: `NetworkConnectionBannerController:dismissBanner`;\n handler: NetworkConnectionBannerController['dismissBanner'];\n};\n\n/**\n * Switches the chain's default RPC endpoint to its Infura endpoint,\n * causing the banner to clear once the 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 */\nexport type NetworkConnectionBannerControllerSwitchToDefaultInfuraRpcEndpointAction =\n {\n type: `NetworkConnectionBannerController:switchToDefaultInfuraRpcEndpoint`;\n handler: NetworkConnectionBannerController['switchToDefaultInfuraRpcEndpoint'];\n };\n\n/**\n * Union of all NetworkConnectionBannerController action types.\n */\nexport type NetworkConnectionBannerControllerMethodActions =\n | NetworkConnectionBannerControllerStartAction\n | NetworkConnectionBannerControllerStopAction\n | NetworkConnectionBannerControllerDismissBannerAction\n | NetworkConnectionBannerControllerSwitchToDefaultInfuraRpcEndpointAction;\n"]}
|