@metamask-previews/sample-controllers 1.0.0-preview-9a5f096 → 1.0.0-preview-f3f2e8c8
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 +1 -24
- package/dist/index.cjs +4 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -7
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -7
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +1 -1
- package/dist/network-controller-types.cjs +20 -0
- package/dist/network-controller-types.cjs.map +1 -0
- package/dist/network-controller-types.d.cts +34 -0
- package/dist/network-controller-types.d.cts.map +1 -0
- package/dist/network-controller-types.d.mts +34 -0
- package/dist/network-controller-types.d.mts.map +1 -0
- package/dist/network-controller-types.mjs +16 -0
- package/dist/network-controller-types.mjs.map +1 -0
- package/dist/sample-gas-prices-controller.cjs +41 -83
- package/dist/sample-gas-prices-controller.cjs.map +1 -1
- package/dist/sample-gas-prices-controller.d.cts +61 -78
- package/dist/sample-gas-prices-controller.d.cts.map +1 -1
- package/dist/sample-gas-prices-controller.d.mts +61 -78
- package/dist/sample-gas-prices-controller.d.mts.map +1 -1
- package/dist/sample-gas-prices-controller.mjs +41 -83
- package/dist/sample-gas-prices-controller.mjs.map +1 -1
- package/dist/sample-gas-prices-service/index.cjs +6 -0
- package/dist/sample-gas-prices-service/index.cjs.map +1 -0
- package/dist/sample-gas-prices-service/index.d.cts +3 -0
- package/dist/sample-gas-prices-service/index.d.cts.map +1 -0
- package/dist/sample-gas-prices-service/index.d.mts +3 -0
- package/dist/sample-gas-prices-service/index.d.mts.map +1 -0
- package/dist/sample-gas-prices-service/index.mjs +2 -0
- package/dist/sample-gas-prices-service/index.mjs.map +1 -0
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.cjs +3 -0
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.cjs.map +1 -0
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.cts +7 -0
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.cts.map +1 -0
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.mts +7 -0
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.mts.map +1 -0
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.mjs +2 -0
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.mjs.map +1 -0
- package/dist/sample-gas-prices-service/sample-gas-prices-service.cjs +29 -136
- package/dist/sample-gas-prices-service/sample-gas-prices-service.cjs.map +1 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service.d.cts +28 -123
- package/dist/sample-gas-prices-service/sample-gas-prices-service.d.cts.map +1 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service.d.mts +28 -123
- package/dist/sample-gas-prices-service/sample-gas-prices-service.d.mts.map +1 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service.mjs +28 -135
- package/dist/sample-gas-prices-service/sample-gas-prices-service.mjs.map +1 -1
- package/dist/sample-petnames-controller.cjs +14 -27
- package/dist/sample-petnames-controller.cjs.map +1 -1
- package/dist/sample-petnames-controller.d.cts +24 -39
- package/dist/sample-petnames-controller.d.cts.map +1 -1
- package/dist/sample-petnames-controller.d.mts +24 -39
- package/dist/sample-petnames-controller.d.mts.map +1 -1
- package/dist/sample-petnames-controller.mjs +14 -26
- package/dist/sample-petnames-controller.mjs.map +1 -1
- package/package.json +2 -3
- package/dist/sample-gas-prices-controller-method-action-types.cjs +0 -7
- package/dist/sample-gas-prices-controller-method-action-types.cjs.map +0 -1
- package/dist/sample-gas-prices-controller-method-action-types.d.cts +0 -21
- package/dist/sample-gas-prices-controller-method-action-types.d.cts.map +0 -1
- package/dist/sample-gas-prices-controller-method-action-types.d.mts +0 -21
- package/dist/sample-gas-prices-controller-method-action-types.d.mts.map +0 -1
- package/dist/sample-gas-prices-controller-method-action-types.mjs +0 -6
- package/dist/sample-gas-prices-controller-method-action-types.mjs.map +0 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.cjs +0 -7
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.cjs.map +0 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.cts +0 -21
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.cts.map +0 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.mts +0 -21
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.mts.map +0 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.mjs +0 -6
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.mjs.map +0 -1
- package/dist/sample-petnames-controller-method-action-types.cjs +0 -7
- package/dist/sample-petnames-controller-method-action-types.cjs.map +0 -1
- package/dist/sample-petnames-controller-method-action-types.d.cts +0 -22
- package/dist/sample-petnames-controller-method-action-types.d.cts.map +0 -1
- package/dist/sample-petnames-controller-method-action-types.d.mts +0 -22
- package/dist/sample-petnames-controller-method-action-types.d.mts.map +0 -1
- package/dist/sample-petnames-controller-method-action-types.mjs +0 -6
- package/dist/sample-petnames-controller-method-action-types.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,33 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
### Added
|
|
11
|
-
|
|
12
|
-
- `SampleGasPricesController.updateGasPrices` is now callable via the messaging system ([#6168](https://github.com/MetaMask/core/pull/6168))
|
|
13
|
-
- An action type, `SampleGasPricesControllerUpdateGasPricesAction`, is now available for use
|
|
14
|
-
- `SamplePetnamesController.assignPetname` is now callable via the messaging system ([#6168](https://github.com/MetaMask/core/pull/6168))
|
|
15
|
-
- An action type, `SamplePetnamesControllerAssignPetnameAction`, is now available for use
|
|
16
|
-
- Export new types for `SampleGasPricesService` ([#6168](https://github.com/MetaMask/core/pull/6168))
|
|
17
|
-
- `SampleGasPricesServiceActions`
|
|
18
|
-
- `SampleGasPricesServiceEvents`
|
|
19
|
-
- `SampleGasPricesServiceFetchGasPricesAction`
|
|
20
|
-
- `SampleGasPricesServiceMessenger`
|
|
21
|
-
- Export `getDefaultPetnamesControllerState` ([#6168](https://github.com/MetaMask/core/pull/6168))
|
|
22
|
-
- Add two new controller state metadata properties: `includeInStateLogs` and `usedInUi` ([#6471](https://github.com/MetaMask/core/pull/6471))
|
|
23
|
-
|
|
24
10
|
### Changed
|
|
25
11
|
|
|
26
|
-
- **BREAKING:** The messenger for `SampleGasPricesController` now expects `NetworkController:getNetworkClientById` to be allowed, and no longer expects `NetworkController:getState` to be allowed ([#6168](https://github.com/MetaMask/core/pull/6168))
|
|
27
|
-
- **BREAKING:** `SampleGasPricesController.updateGasPrices` now takes a required `chainId` option ([#6168](https://github.com/MetaMask/core/pull/6168))
|
|
28
|
-
- `SampleGasPricesController` will now automatically update gas prices when the globally selected chain changes ([#6168](https://github.com/MetaMask/core/pull/6168))
|
|
29
|
-
- Bump `@metamask/base-controller` from `^8.0.1` to `^8.3.0` ([#6284](https://github.com/MetaMask/core/pull/6284), [#6355](https://github.com/MetaMask/core/pull/6355), [#6465](https://github.com/MetaMask/core/pull/6465))
|
|
30
12
|
- Bump `@metamask/utils` from `^11.2.0` to `^11.4.2` ([#6054](https://github.com/MetaMask/core/pull/6054))
|
|
31
|
-
|
|
32
|
-
### Removed
|
|
33
|
-
|
|
34
|
-
- **BREAKING:** `SampleGasPricesController` no longer takes a `gasPricesService` option ([#6168](https://github.com/MetaMask/core/pull/6168))
|
|
35
|
-
- The controller now expects `SampleGasPricesService` to have been instantiated ahead of time
|
|
36
|
-
- **BREAKING:** Remove `SampleAbstractGasPricesService` ([#6168](https://github.com/MetaMask/core/pull/6168))
|
|
13
|
+
- Bump `@metamask/base-controller` from `^8.0.1` to `^8.1.0` ([#6284](https://github.com/MetaMask/core/pull/6284))
|
|
37
14
|
|
|
38
15
|
## [1.0.0]
|
|
39
16
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var sample_gas_prices_service_1 = require("./sample-gas-prices-service/sample-gas-prices-service.cjs");
|
|
5
|
-
Object.defineProperty(exports, "SampleGasPricesService", { enumerable: true, get: function () { return sample_gas_prices_service_1.SampleGasPricesService; } });
|
|
3
|
+
exports.SampleGasPricesService = exports.SamplePetnamesController = exports.SampleGasPricesController = exports.getDefaultSampleGasPricesControllerState = void 0;
|
|
6
4
|
var sample_gas_prices_controller_1 = require("./sample-gas-prices-controller.cjs");
|
|
7
|
-
Object.defineProperty(exports, "SampleGasPricesController", { enumerable: true, get: function () { return sample_gas_prices_controller_1.SampleGasPricesController; } });
|
|
8
5
|
Object.defineProperty(exports, "getDefaultSampleGasPricesControllerState", { enumerable: true, get: function () { return sample_gas_prices_controller_1.getDefaultSampleGasPricesControllerState; } });
|
|
6
|
+
Object.defineProperty(exports, "SampleGasPricesController", { enumerable: true, get: function () { return sample_gas_prices_controller_1.SampleGasPricesController; } });
|
|
9
7
|
var sample_petnames_controller_1 = require("./sample-petnames-controller.cjs");
|
|
10
8
|
Object.defineProperty(exports, "SamplePetnamesController", { enumerable: true, get: function () { return sample_petnames_controller_1.SamplePetnamesController; } });
|
|
11
|
-
|
|
9
|
+
var sample_gas_prices_service_1 = require("./sample-gas-prices-service/index.cjs");
|
|
10
|
+
Object.defineProperty(exports, "SampleGasPricesService", { enumerable: true, get: function () { return sample_gas_prices_service_1.SampleGasPricesService; } });
|
|
12
11
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAQA,mFAGwC;AAFtC,wJAAA,wCAAwC,OAAA;AACxC,yIAAA,yBAAyB,OAAA;AAU3B,+EAAwE;AAA/D,sIAAA,wBAAwB,OAAA;AACjC,mFAGqC;AAFnC,mIAAA,sBAAsB,OAAA","sourcesContent":["export type {\n SampleGasPricesControllerActions,\n SampleGasPricesControllerEvents,\n SampleGasPricesControllerGetStateAction,\n SampleGasPricesControllerMessenger,\n SampleGasPricesControllerState,\n SampleGasPricesControllerStateChangeEvent,\n} from './sample-gas-prices-controller';\nexport {\n getDefaultSampleGasPricesControllerState,\n SampleGasPricesController,\n} from './sample-gas-prices-controller';\nexport type {\n SamplePetnamesControllerActions,\n SamplePetnamesControllerEvents,\n SamplePetnamesControllerGetStateAction,\n SamplePetnamesControllerMessenger,\n SamplePetnamesControllerState,\n SamplePetnamesControllerStateChangeEvent,\n} from './sample-petnames-controller';\nexport { SamplePetnamesController } from './sample-petnames-controller';\nexport {\n SampleGasPricesService,\n type SampleAbstractGasPricesService,\n} from './sample-gas-prices-service';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
export type { SampleGasPricesServiceActions, SampleGasPricesServiceEvents, SampleGasPricesServiceMessenger, } from "./sample-gas-prices-service/sample-gas-prices-service.cjs";
|
|
2
|
-
export type { SampleGasPricesServiceFetchGasPricesAction } from "./sample-gas-prices-service/sample-gas-prices-service-method-action-types.cjs";
|
|
3
|
-
export { SampleGasPricesService } from "./sample-gas-prices-service/sample-gas-prices-service.cjs";
|
|
4
1
|
export type { SampleGasPricesControllerActions, SampleGasPricesControllerEvents, SampleGasPricesControllerGetStateAction, SampleGasPricesControllerMessenger, SampleGasPricesControllerState, SampleGasPricesControllerStateChangeEvent, } from "./sample-gas-prices-controller.cjs";
|
|
5
|
-
export {
|
|
6
|
-
export type { SampleGasPricesControllerUpdateGasPricesAction } from "./sample-gas-prices-controller-method-action-types.cjs";
|
|
2
|
+
export { getDefaultSampleGasPricesControllerState, SampleGasPricesController, } from "./sample-gas-prices-controller.cjs";
|
|
7
3
|
export type { SamplePetnamesControllerActions, SamplePetnamesControllerEvents, SamplePetnamesControllerGetStateAction, SamplePetnamesControllerMessenger, SamplePetnamesControllerState, SamplePetnamesControllerStateChangeEvent, } from "./sample-petnames-controller.cjs";
|
|
8
|
-
export { SamplePetnamesController
|
|
9
|
-
export type
|
|
4
|
+
export { SamplePetnamesController } from "./sample-petnames-controller.cjs";
|
|
5
|
+
export { SampleGasPricesService, type SampleAbstractGasPricesService, } from "./sample-gas-prices-service/index.cjs";
|
|
10
6
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,gCAAgC,EAChC,+BAA+B,EAC/B,uCAAuC,EACvC,kCAAkC,EAClC,8BAA8B,EAC9B,yCAAyC,GAC1C,2CAAuC;AACxC,OAAO,EACL,wCAAwC,EACxC,yBAAyB,GAC1B,2CAAuC;AACxC,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,sCAAsC,EACtC,iCAAiC,EACjC,6BAA6B,EAC7B,wCAAwC,GACzC,yCAAqC;AACtC,OAAO,EAAE,wBAAwB,EAAE,yCAAqC;AACxE,OAAO,EACL,sBAAsB,EACtB,KAAK,8BAA8B,GACpC,8CAAoC"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
export type { SampleGasPricesServiceActions, SampleGasPricesServiceEvents, SampleGasPricesServiceMessenger, } from "./sample-gas-prices-service/sample-gas-prices-service.mjs";
|
|
2
|
-
export type { SampleGasPricesServiceFetchGasPricesAction } from "./sample-gas-prices-service/sample-gas-prices-service-method-action-types.mjs";
|
|
3
|
-
export { SampleGasPricesService } from "./sample-gas-prices-service/sample-gas-prices-service.mjs";
|
|
4
1
|
export type { SampleGasPricesControllerActions, SampleGasPricesControllerEvents, SampleGasPricesControllerGetStateAction, SampleGasPricesControllerMessenger, SampleGasPricesControllerState, SampleGasPricesControllerStateChangeEvent, } from "./sample-gas-prices-controller.mjs";
|
|
5
|
-
export {
|
|
6
|
-
export type { SampleGasPricesControllerUpdateGasPricesAction } from "./sample-gas-prices-controller-method-action-types.mjs";
|
|
2
|
+
export { getDefaultSampleGasPricesControllerState, SampleGasPricesController, } from "./sample-gas-prices-controller.mjs";
|
|
7
3
|
export type { SamplePetnamesControllerActions, SamplePetnamesControllerEvents, SamplePetnamesControllerGetStateAction, SamplePetnamesControllerMessenger, SamplePetnamesControllerState, SamplePetnamesControllerStateChangeEvent, } from "./sample-petnames-controller.mjs";
|
|
8
|
-
export { SamplePetnamesController
|
|
9
|
-
export type
|
|
4
|
+
export { SamplePetnamesController } from "./sample-petnames-controller.mjs";
|
|
5
|
+
export { SampleGasPricesService, type SampleAbstractGasPricesService, } from "./sample-gas-prices-service/index.mjs";
|
|
10
6
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,gCAAgC,EAChC,+BAA+B,EAC/B,uCAAuC,EACvC,kCAAkC,EAClC,8BAA8B,EAC9B,yCAAyC,GAC1C,2CAAuC;AACxC,OAAO,EACL,wCAAwC,EACxC,yBAAyB,GAC1B,2CAAuC;AACxC,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,sCAAsC,EACtC,iCAAiC,EACjC,6BAA6B,EAC7B,wCAAwC,GACzC,yCAAqC;AACtC,OAAO,EAAE,wBAAwB,EAAE,yCAAqC;AACxE,OAAO,EACL,sBAAsB,EACtB,KAAK,8BAA8B,GACpC,8CAAoC"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { getDefaultSampleGasPricesControllerState, SampleGasPricesController } from "./sample-gas-prices-controller.mjs";
|
|
2
|
+
export { SamplePetnamesController } from "./sample-petnames-controller.mjs";
|
|
3
|
+
export { SampleGasPricesService } from "./sample-gas-prices-service/index.mjs";
|
|
4
4
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,wCAAwC,EACxC,yBAAyB,EAC1B,2CAAuC;AASxC,OAAO,EAAE,wBAAwB,EAAE,yCAAqC;AACxE,OAAO,EACL,sBAAsB,EAEvB,8CAAoC","sourcesContent":["export type {\n SampleGasPricesControllerActions,\n SampleGasPricesControllerEvents,\n SampleGasPricesControllerGetStateAction,\n SampleGasPricesControllerMessenger,\n SampleGasPricesControllerState,\n SampleGasPricesControllerStateChangeEvent,\n} from './sample-gas-prices-controller';\nexport {\n getDefaultSampleGasPricesControllerState,\n SampleGasPricesController,\n} from './sample-gas-prices-controller';\nexport type {\n SamplePetnamesControllerActions,\n SamplePetnamesControllerEvents,\n SamplePetnamesControllerGetStateAction,\n SamplePetnamesControllerMessenger,\n SamplePetnamesControllerState,\n SamplePetnamesControllerStateChangeEvent,\n} from './sample-petnames-controller';\nexport { SamplePetnamesController } from './sample-petnames-controller';\nexport {\n SampleGasPricesService,\n type SampleAbstractGasPricesService,\n} from './sample-gas-prices-service';\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDefaultNetworkControllerState = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Constructs a default representation of a theoretical NetworkController's
|
|
6
|
+
* state.
|
|
7
|
+
*
|
|
8
|
+
* Note that this package does not supply a NetworkController; this type is only
|
|
9
|
+
* here so it is possible to write a complete example.
|
|
10
|
+
*
|
|
11
|
+
* @returns The default network controller state.
|
|
12
|
+
*/
|
|
13
|
+
function getDefaultNetworkControllerState() {
|
|
14
|
+
return {
|
|
15
|
+
networkName: 'Some Network',
|
|
16
|
+
chainId: '0x1',
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.getDefaultNetworkControllerState = getDefaultNetworkControllerState;
|
|
20
|
+
//# sourceMappingURL=network-controller-types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-controller-types.cjs","sourceRoot":"","sources":["../src/network-controller-types.ts"],"names":[],"mappings":";;;AAaA;;;;;;;;GAQG;AACH,SAAgB,gCAAgC;IAC9C,OAAO;QACL,WAAW,EAAE,cAAc;QAC3B,OAAO,EAAE,KAAK;KACf,CAAC;AACJ,CAAC;AALD,4EAKC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\n/**\n * Describes the shape of the state object for a theoretical NetworkController.\n *\n * Note that this package does not supply a NetworkController; this type is only\n * here so it is possible to write a complete example.\n */\ntype NetworkControllerState = {\n networkName: string;\n chainId: Hex;\n};\n\n/**\n * Constructs a default representation of a theoretical NetworkController's\n * state.\n *\n * Note that this package does not supply a NetworkController; this type is only\n * here so it is possible to write a complete example.\n *\n * @returns The default network controller state.\n */\nexport function getDefaultNetworkControllerState(): NetworkControllerState {\n return {\n networkName: 'Some Network',\n chainId: '0x1',\n };\n}\n\n/**\n * The action which can be used to obtain the state for a theoretical\n * NetworkController.\n *\n * Note that this package does not supply a NetworkController; this type is only\n * here so it is possible to write a complete example.\n */\nexport type NetworkControllerGetStateAction = {\n type: 'NetworkController:getState';\n handler: () => NetworkControllerState;\n};\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Hex } from "@metamask/utils";
|
|
2
|
+
/**
|
|
3
|
+
* Describes the shape of the state object for a theoretical NetworkController.
|
|
4
|
+
*
|
|
5
|
+
* Note that this package does not supply a NetworkController; this type is only
|
|
6
|
+
* here so it is possible to write a complete example.
|
|
7
|
+
*/
|
|
8
|
+
type NetworkControllerState = {
|
|
9
|
+
networkName: string;
|
|
10
|
+
chainId: Hex;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Constructs a default representation of a theoretical NetworkController's
|
|
14
|
+
* state.
|
|
15
|
+
*
|
|
16
|
+
* Note that this package does not supply a NetworkController; this type is only
|
|
17
|
+
* here so it is possible to write a complete example.
|
|
18
|
+
*
|
|
19
|
+
* @returns The default network controller state.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getDefaultNetworkControllerState(): NetworkControllerState;
|
|
22
|
+
/**
|
|
23
|
+
* The action which can be used to obtain the state for a theoretical
|
|
24
|
+
* NetworkController.
|
|
25
|
+
*
|
|
26
|
+
* Note that this package does not supply a NetworkController; this type is only
|
|
27
|
+
* here so it is possible to write a complete example.
|
|
28
|
+
*/
|
|
29
|
+
export type NetworkControllerGetStateAction = {
|
|
30
|
+
type: 'NetworkController:getState';
|
|
31
|
+
handler: () => NetworkControllerState;
|
|
32
|
+
};
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=network-controller-types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-controller-types.d.cts","sourceRoot":"","sources":["../src/network-controller-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C;;;;;GAKG;AACH,KAAK,sBAAsB,GAAG;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,GAAG,CAAC;CACd,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,gCAAgC,IAAI,sBAAsB,CAKzE;AAED;;;;;;GAMG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,MAAM,sBAAsB,CAAC;CACvC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Hex } from "@metamask/utils";
|
|
2
|
+
/**
|
|
3
|
+
* Describes the shape of the state object for a theoretical NetworkController.
|
|
4
|
+
*
|
|
5
|
+
* Note that this package does not supply a NetworkController; this type is only
|
|
6
|
+
* here so it is possible to write a complete example.
|
|
7
|
+
*/
|
|
8
|
+
type NetworkControllerState = {
|
|
9
|
+
networkName: string;
|
|
10
|
+
chainId: Hex;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Constructs a default representation of a theoretical NetworkController's
|
|
14
|
+
* state.
|
|
15
|
+
*
|
|
16
|
+
* Note that this package does not supply a NetworkController; this type is only
|
|
17
|
+
* here so it is possible to write a complete example.
|
|
18
|
+
*
|
|
19
|
+
* @returns The default network controller state.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getDefaultNetworkControllerState(): NetworkControllerState;
|
|
22
|
+
/**
|
|
23
|
+
* The action which can be used to obtain the state for a theoretical
|
|
24
|
+
* NetworkController.
|
|
25
|
+
*
|
|
26
|
+
* Note that this package does not supply a NetworkController; this type is only
|
|
27
|
+
* here so it is possible to write a complete example.
|
|
28
|
+
*/
|
|
29
|
+
export type NetworkControllerGetStateAction = {
|
|
30
|
+
type: 'NetworkController:getState';
|
|
31
|
+
handler: () => NetworkControllerState;
|
|
32
|
+
};
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=network-controller-types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-controller-types.d.mts","sourceRoot":"","sources":["../src/network-controller-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C;;;;;GAKG;AACH,KAAK,sBAAsB,GAAG;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,GAAG,CAAC;CACd,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,gCAAgC,IAAI,sBAAsB,CAKzE;AAED;;;;;;GAMG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,MAAM,sBAAsB,CAAC;CACvC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constructs a default representation of a theoretical NetworkController's
|
|
3
|
+
* state.
|
|
4
|
+
*
|
|
5
|
+
* Note that this package does not supply a NetworkController; this type is only
|
|
6
|
+
* here so it is possible to write a complete example.
|
|
7
|
+
*
|
|
8
|
+
* @returns The default network controller state.
|
|
9
|
+
*/
|
|
10
|
+
export function getDefaultNetworkControllerState() {
|
|
11
|
+
return {
|
|
12
|
+
networkName: 'Some Network',
|
|
13
|
+
chainId: '0x1',
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=network-controller-types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-controller-types.mjs","sourceRoot":"","sources":["../src/network-controller-types.ts"],"names":[],"mappings":"AAaA;;;;;;;;GAQG;AACH,MAAM,UAAU,gCAAgC;IAC9C,OAAO;QACL,WAAW,EAAE,cAAc;QAC3B,OAAO,EAAE,KAAK;KACf,CAAC;AACJ,CAAC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\n/**\n * Describes the shape of the state object for a theoretical NetworkController.\n *\n * Note that this package does not supply a NetworkController; this type is only\n * here so it is possible to write a complete example.\n */\ntype NetworkControllerState = {\n networkName: string;\n chainId: Hex;\n};\n\n/**\n * Constructs a default representation of a theoretical NetworkController's\n * state.\n *\n * Note that this package does not supply a NetworkController; this type is only\n * here so it is possible to write a complete example.\n *\n * @returns The default network controller state.\n */\nexport function getDefaultNetworkControllerState(): NetworkControllerState {\n return {\n networkName: 'Some Network',\n chainId: '0x1',\n };\n}\n\n/**\n * The action which can be used to obtain the state for a theoretical\n * NetworkController.\n *\n * Note that this package does not supply a NetworkController; this type is only\n * here so it is possible to write a complete example.\n */\nexport type NetworkControllerGetStateAction = {\n type: 'NetworkController:getState';\n handler: () => NetworkControllerState;\n};\n"]}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
-
};
|
|
7
2
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8
3
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9
4
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10
5
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
6
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
7
|
};
|
|
13
|
-
var
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _SampleGasPricesController_gasPricesService;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.SampleGasPricesController = exports.getDefaultSampleGasPricesControllerState = exports.controllerName = void 0;
|
|
16
16
|
const base_controller_1 = require("@metamask/base-controller");
|
|
@@ -26,10 +26,8 @@ exports.controllerName = 'SampleGasPricesController';
|
|
|
26
26
|
*/
|
|
27
27
|
const gasPricesControllerMetadata = {
|
|
28
28
|
gasPricesByChainId: {
|
|
29
|
-
includeInStateLogs: true,
|
|
30
29
|
persist: true,
|
|
31
30
|
anonymous: false,
|
|
32
|
-
usedInUi: true,
|
|
33
31
|
},
|
|
34
32
|
};
|
|
35
33
|
/**
|
|
@@ -46,8 +44,6 @@ function getDefaultSampleGasPricesControllerState() {
|
|
|
46
44
|
};
|
|
47
45
|
}
|
|
48
46
|
exports.getDefaultSampleGasPricesControllerState = getDefaultSampleGasPricesControllerState;
|
|
49
|
-
// === MESSENGER ===
|
|
50
|
-
const MESSENGER_EXPOSED_METHODS = ['updateGasPrices'];
|
|
51
47
|
// === CONTROLLER DEFINITION ===
|
|
52
48
|
/**
|
|
53
49
|
* `SampleGasPricesController` fetches and persists gas prices for various chains.
|
|
@@ -56,60 +52,36 @@ const MESSENGER_EXPOSED_METHODS = ['updateGasPrices'];
|
|
|
56
52
|
*
|
|
57
53
|
* ``` ts
|
|
58
54
|
* import { Messenger } from '@metamask/base-controller';
|
|
59
|
-
* import type {
|
|
60
|
-
* NetworkControllerActions,
|
|
61
|
-
* NetworkControllerEvents,
|
|
62
|
-
* } from '@metamask/network-controller';
|
|
63
|
-
* import type {
|
|
64
|
-
* SampleGasPricesControllerActions,
|
|
65
|
-
* SampleGasPricesControllerEvents,
|
|
66
|
-
* SampleGasPricesServiceActions,
|
|
67
|
-
* SampleGasPricesServiceEvents,
|
|
68
|
-
* } from '@metamask/sample-controllers';
|
|
69
55
|
* import {
|
|
70
56
|
* SampleGasPricesController,
|
|
71
|
-
* SampleGasPricesService
|
|
72
|
-
*
|
|
73
|
-
*
|
|
57
|
+
* SampleGasPricesService
|
|
58
|
+
* } from '@metamask/example-controllers';
|
|
59
|
+
* import type {
|
|
60
|
+
* SampleGasPricesControllerActions,
|
|
61
|
+
* SampleGasPricesControllerEvents
|
|
62
|
+
* } from '@metamask/example-controllers';
|
|
63
|
+
* import type { NetworkControllerGetStateAction } from '@metamask/network-controller';
|
|
74
64
|
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* |
|
|
79
|
-
*
|
|
80
|
-
* | SampleGasPricesControllerEvents
|
|
81
|
-
* | NetworkControllerEvents
|
|
65
|
+
* // Assuming that you're using this in the browser
|
|
66
|
+
* const gasPricesService = new SampleGasPricesService({ fetch });
|
|
67
|
+
* const rootMessenger = new Messenger<
|
|
68
|
+
* SampleGasPricesControllerActions | NetworkControllerGetStateAction,
|
|
69
|
+
* SampleGasPricesControllerEvents
|
|
82
70
|
* >();
|
|
83
|
-
* const
|
|
84
|
-
* name: 'SampleGasPricesService',
|
|
85
|
-
* allowedActions: [],
|
|
86
|
-
* allowedEvents: [],
|
|
87
|
-
* });
|
|
88
|
-
* // Instantiate the service to register its actions on the messenger
|
|
89
|
-
* new SampleGasPricesService({
|
|
90
|
-
* messenger: gasPricesServiceMessenger,
|
|
91
|
-
* // We assume you're using this in the browser.
|
|
92
|
-
* fetch,
|
|
93
|
-
* });
|
|
94
|
-
* const gasPricesControllerMessenger = globalMessenger.getRestricted({
|
|
71
|
+
* const gasPricesMessenger = rootMessenger.getRestricted({
|
|
95
72
|
* name: 'SampleGasPricesController',
|
|
96
|
-
* allowedActions: ['NetworkController:
|
|
97
|
-
* allowedEvents: [
|
|
73
|
+
* allowedActions: ['NetworkController:getState'],
|
|
74
|
+
* allowedEvents: [],
|
|
98
75
|
* });
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
76
|
+
* const gasPricesController = new SampleGasPricesController({
|
|
77
|
+
* messenger: gasPricesMessenger,
|
|
78
|
+
* gasPricesService,
|
|
102
79
|
* });
|
|
103
80
|
*
|
|
104
|
-
* //
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* );
|
|
109
|
-
* const gasPricesControllerState = await globalMessenger.call(
|
|
110
|
-
* 'SampleGasPricesController:getState',
|
|
111
|
-
* );
|
|
112
|
-
* gasPricesControllerState.gasPricesByChainId
|
|
81
|
+
* // Assuming that `NetworkController:getState` returns an object with a
|
|
82
|
+
* // `chainId` of `0x42`...
|
|
83
|
+
* await gasPricesController.updateGasPrices();
|
|
84
|
+
* gasPricesController.state.gasPricesByChainId
|
|
113
85
|
* // => { '0x42': { low: 5, average: 10, high: 15, fetchedDate: '2024-01-02T00:00:00.000Z' } }
|
|
114
86
|
* ```
|
|
115
87
|
*/
|
|
@@ -117,12 +89,14 @@ class SampleGasPricesController extends base_controller_1.BaseController {
|
|
|
117
89
|
/**
|
|
118
90
|
* Constructs a new {@link SampleGasPricesController}.
|
|
119
91
|
*
|
|
120
|
-
* @param args - The
|
|
92
|
+
* @param args - The arguments to the controller.
|
|
121
93
|
* @param args.messenger - The messenger suited for this controller.
|
|
122
94
|
* @param args.state - The desired state with which to initialize this
|
|
123
95
|
* controller. Missing properties will be filled in with defaults.
|
|
96
|
+
* @param args.gasPricesService - The service object that will be used to
|
|
97
|
+
* obtain gas prices.
|
|
124
98
|
*/
|
|
125
|
-
constructor({ messenger, state, }) {
|
|
99
|
+
constructor({ messenger, state, gasPricesService, }) {
|
|
126
100
|
super({
|
|
127
101
|
messenger,
|
|
128
102
|
metadata: gasPricesControllerMetadata,
|
|
@@ -132,23 +106,20 @@ class SampleGasPricesController extends base_controller_1.BaseController {
|
|
|
132
106
|
...state,
|
|
133
107
|
},
|
|
134
108
|
});
|
|
135
|
-
_SampleGasPricesController_instances.add(this);
|
|
136
109
|
/**
|
|
137
|
-
* The
|
|
110
|
+
* The service object that is used to obtain gas prices.
|
|
138
111
|
*/
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
this.messagingSystem.
|
|
112
|
+
_SampleGasPricesController_gasPricesService.set(this, void 0);
|
|
113
|
+
__classPrivateFieldSet(this, _SampleGasPricesController_gasPricesService, gasPricesService, "f");
|
|
114
|
+
this.messagingSystem.registerActionHandler(`${exports.controllerName}:updateGasPrices`, this.updateGasPrices.bind(this));
|
|
142
115
|
}
|
|
143
116
|
/**
|
|
144
|
-
* Fetches the latest gas prices for the
|
|
117
|
+
* Fetches the latest gas prices for the current chain, persisting them to
|
|
145
118
|
* state.
|
|
146
|
-
*
|
|
147
|
-
* @param args - The arguments to the function.
|
|
148
|
-
* @param args.chainId - The chain ID for which to fetch gas prices.
|
|
149
119
|
*/
|
|
150
|
-
async updateGasPrices(
|
|
151
|
-
const
|
|
120
|
+
async updateGasPrices() {
|
|
121
|
+
const { chainId } = this.messagingSystem.call('NetworkController:getState');
|
|
122
|
+
const gasPricesResponse = await __classPrivateFieldGet(this, _SampleGasPricesController_gasPricesService, "f").fetchGasPrices(chainId);
|
|
152
123
|
this.update((state) => {
|
|
153
124
|
state.gasPricesByChainId[chainId] = {
|
|
154
125
|
...gasPricesResponse,
|
|
@@ -158,18 +129,5 @@ class SampleGasPricesController extends base_controller_1.BaseController {
|
|
|
158
129
|
}
|
|
159
130
|
}
|
|
160
131
|
exports.SampleGasPricesController = SampleGasPricesController;
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Callback to call when the globally selected network client ID changes,
|
|
164
|
-
* ensuring that gas prices get updated.
|
|
165
|
-
*
|
|
166
|
-
* @param selectedNetworkClientId - The globally selected network client ID.
|
|
167
|
-
*/
|
|
168
|
-
async function _SampleGasPricesController_onSelectedNetworkClientIdChange(selectedNetworkClientId) {
|
|
169
|
-
const { configuration: { chainId }, } = this.messagingSystem.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
|
|
170
|
-
if (chainId !== __classPrivateFieldGet(this, _SampleGasPricesController_selectedChainId, "f")) {
|
|
171
|
-
__classPrivateFieldSet(this, _SampleGasPricesController_selectedChainId, chainId, "f");
|
|
172
|
-
await this.updateGasPrices({ chainId });
|
|
173
|
-
}
|
|
174
|
-
};
|
|
132
|
+
_SampleGasPricesController_gasPricesService = new WeakMap();
|
|
175
133
|
//# sourceMappingURL=sample-gas-prices-controller.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sample-gas-prices-controller.cjs","sourceRoot":"","sources":["../src/sample-gas-prices-controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAMA,+DAA2D;AAW3D,kBAAkB;AAElB;;;;GAIG;AACU,QAAA,cAAc,GAAG,2BAA2B,CAAC;AAsC1D;;GAEG;AACH,MAAM,2BAA2B,GAAG;IAClC,kBAAkB,EAAE;QAClB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,KAAK;QAChB,QAAQ,EAAE,IAAI;KACf;CACsD,CAAC;AAE1D;;;;;;;GAOG;AACH,SAAgB,wCAAwC;IACtD,OAAO;QACL,kBAAkB,EAAE,EAAE;KACvB,CAAC;AACJ,CAAC;AAJD,4FAIC;AAED,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG,CAAC,iBAAiB,CAAU,CAAC;AAyD/D,gCAAgC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,MAAa,yBAA0B,SAAQ,gCAI9C;IAMC;;;;;;;OAOG;IACH,YAAY,EACV,SAAS,EACT,KAAK,GAIN;QACC,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,2BAA2B;YACrC,IAAI,EAAE,sBAAc;YACpB,KAAK,EAAE;gBACL,GAAG,wCAAwC,EAAE;gBAC7C,GAAG,KAAK;aACT;SACF,CAAC,CAAC;;QA5BL;;WAEG;QACH,6DAAkC;QA2BhC,IAAI,CAAC,eAAe,CAAC,4BAA4B,CAC/C,IAAI,EACJ,yBAAyB,CAC1B,CAAC;QAEF,IAAI,CAAC,eAAe,CAAC,SAAS,CAC5B,+BAA+B,EAC/B,uBAAA,IAAI,wGAAiC,CAAC,IAAI,CAAC,IAAI,CAAC,EAChD,CAAC,sBAAsB,EAAE,EAAE,CACzB,sBAAsB,CAAC,uBAAuB,CACjD,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,eAAe,CAAC,EAAE,OAAO,EAAoB;QACjD,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CACvD,uCAAuC,EACvC,OAAO,CACR,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,kBAAkB,CAAC,OAAO,CAAC,GAAG;gBAClC,GAAG,iBAAiB;gBACpB,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;aACtC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CAuBF;AA1FD,8DA0FC;;AArBC;;;;;GAKG;AACH,KAAK,qEACH,uBAAwC;IAExC,MAAM,EACJ,aAAa,EAAE,EAAE,OAAO,EAAE,GAC3B,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAC3B,wCAAwC,EACxC,uBAAuB,CACxB,CAAC;IAEF,IAAI,OAAO,KAAK,uBAAA,IAAI,kDAAiB,EAAE;QACrC,uBAAA,IAAI,8CAAoB,OAAO,MAAA,CAAC;QAChC,MAAM,IAAI,CAAC,eAAe,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;KACzC;AACH,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n NetworkClientId,\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerStateChangeEvent,\n} from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport type { SampleGasPricesControllerMethodActions } from './sample-gas-prices-controller-method-action-types';\nimport type { SampleGasPricesServiceFetchGasPricesAction } from './sample-gas-prices-service/sample-gas-prices-service-method-action-types';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link SampleGasPricesController}, used to namespace the\n * controller's actions and events and to namespace the controller's state data\n * when composed with other controllers.\n */\nexport const controllerName = 'SampleGasPricesController';\n\n// === STATE ===\n\n/**\n * The collection of gas price data fetched periodically.\n */\ntype GasPrices = {\n /**\n * The total estimated gas in the \"low\" bucket.\n */\n low: number;\n /**\n * The total estimated gas in the \"average\" bucket.\n */\n average: number;\n /**\n * The total estimated gas in the \"high\" bucket.\n */\n high: number;\n /**\n * The date/time (in ISO-8601 format) when prices were fetched.\n */\n fetchedDate: string;\n};\n\n/**\n * Describes the shape of the state object for {@link SampleGasPricesController}.\n */\nexport type SampleGasPricesControllerState = {\n /**\n * Fetched gas prices categorized by chain ID.\n */\n gasPricesByChainId: {\n [chainId: Hex]: GasPrices;\n };\n};\n\n/**\n * The metadata for each property in {@link SampleGasPricesControllerState}.\n */\nconst gasPricesControllerMetadata = {\n gasPricesByChainId: {\n includeInStateLogs: true,\n persist: true,\n anonymous: false,\n usedInUi: true,\n },\n} satisfies StateMetadata<SampleGasPricesControllerState>;\n\n/**\n * Constructs the default {@link SampleGasPricesController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link SampleGasPricesController} state.\n */\nexport function getDefaultSampleGasPricesControllerState(): SampleGasPricesControllerState {\n return {\n gasPricesByChainId: {},\n };\n}\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = ['updateGasPrices'] as const;\n\n/**\n * Retrieves the state of the {@link SampleGasPricesController}.\n */\nexport type SampleGasPricesControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SampleGasPricesControllerState\n>;\n\n/**\n * Actions that {@link SampleGasPricesMessenger} exposes to other consumers.\n */\nexport type SampleGasPricesControllerActions =\n | SampleGasPricesControllerGetStateAction\n | SampleGasPricesControllerMethodActions;\n\n/**\n * Actions from other messengers that {@link SampleGasPricesMessenger} calls.\n */\ntype AllowedActions =\n | NetworkControllerGetNetworkClientByIdAction\n | SampleGasPricesServiceFetchGasPricesAction;\n\n/**\n * Published when the state of {@link SampleGasPricesController} changes.\n */\nexport type SampleGasPricesControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n SampleGasPricesControllerState\n >;\n\n/**\n * Events that {@link SampleGasPricesMessenger} exposes to other consumers.\n */\nexport type SampleGasPricesControllerEvents =\n SampleGasPricesControllerStateChangeEvent;\n\n/**\n * Events from other messengers that {@link SampleGasPricesMessenger} subscribes\n * to.\n */\ntype AllowedEvents = NetworkControllerStateChangeEvent;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link SampleGasPricesController}.\n */\nexport type SampleGasPricesControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n SampleGasPricesControllerActions | AllowedActions,\n SampleGasPricesControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n// === CONTROLLER DEFINITION ===\n\n/**\n * `SampleGasPricesController` fetches and persists gas prices for various chains.\n *\n * @example\n *\n * ``` ts\n * import { Messenger } from '@metamask/base-controller';\n * import type {\n * NetworkControllerActions,\n * NetworkControllerEvents,\n * } from '@metamask/network-controller';\n * import type {\n * SampleGasPricesControllerActions,\n * SampleGasPricesControllerEvents,\n * SampleGasPricesServiceActions,\n * SampleGasPricesServiceEvents,\n * } from '@metamask/sample-controllers';\n * import {\n * SampleGasPricesController,\n * SampleGasPricesService,\n * selectGasPrices,\n * } from '@metamask/sample-controllers';\n *\n * const globalMessenger = new Messenger<\n * SampleGasPricesServiceActions\n * | SampleGasPricesControllerActions\n * | NetworkControllerActions,\n * SampleGasPricesServiceEvents\n * | SampleGasPricesControllerEvents\n * | NetworkControllerEvents\n * >();\n * const gasPricesServiceMessenger = globalMessenger.getRestricted({\n * name: 'SampleGasPricesService',\n * allowedActions: [],\n * allowedEvents: [],\n * });\n * // Instantiate the service to register its actions on the messenger\n * new SampleGasPricesService({\n * messenger: gasPricesServiceMessenger,\n * // We assume you're using this in the browser.\n * fetch,\n * });\n * const gasPricesControllerMessenger = globalMessenger.getRestricted({\n * name: 'SampleGasPricesController',\n * allowedActions: ['NetworkController:getNetworkClientById'],\n * allowedEvents: ['NetworkController:stateChange'],\n * });\n * // Instantiate the controller to register its actions on the messenger\n * new SampleGasPricesController({\n * messenger: gasPricesControllerMessenger,\n * });\n *\n * // Later...\n * await globalMessenger.call(\n * 'SampleGasPricesController:updateGasPrices',\n * { chainId: '0x42' },\n * );\n * const gasPricesControllerState = await globalMessenger.call(\n * 'SampleGasPricesController:getState',\n * );\n * gasPricesControllerState.gasPricesByChainId\n * // => { '0x42': { low: 5, average: 10, high: 15, fetchedDate: '2024-01-02T00:00:00.000Z' } }\n * ```\n */\nexport class SampleGasPricesController extends BaseController<\n typeof controllerName,\n SampleGasPricesControllerState,\n SampleGasPricesControllerMessenger\n> {\n /**\n * The globally selected chain ID.\n */\n #selectedChainId: Hex | undefined;\n\n /**\n * Constructs a new {@link SampleGasPricesController}.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this controller.\n * @param args.state - The desired state with which to initialize this\n * controller. Missing properties will be filled in with defaults.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: SampleGasPricesControllerMessenger;\n state?: Partial<SampleGasPricesControllerState>;\n }) {\n super({\n messenger,\n metadata: gasPricesControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultSampleGasPricesControllerState(),\n ...state,\n },\n });\n\n this.messagingSystem.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n this.messagingSystem.subscribe(\n 'NetworkController:stateChange',\n this.#onSelectedNetworkClientIdChange.bind(this),\n (networkControllerState) =>\n networkControllerState.selectedNetworkClientId,\n );\n }\n\n /**\n * Fetches the latest gas prices for the given chain and persists them to\n * state.\n *\n * @param args - The arguments to the function.\n * @param args.chainId - The chain ID for which to fetch gas prices.\n */\n async updateGasPrices({ chainId }: { chainId: Hex }) {\n const gasPricesResponse = await this.messagingSystem.call(\n 'SampleGasPricesService:fetchGasPrices',\n chainId,\n );\n\n this.update((state) => {\n state.gasPricesByChainId[chainId] = {\n ...gasPricesResponse,\n fetchedDate: new Date().toISOString(),\n };\n });\n }\n\n /**\n * Callback to call when the globally selected network client ID changes,\n * ensuring that gas prices get updated.\n *\n * @param selectedNetworkClientId - The globally selected network client ID.\n */\n async #onSelectedNetworkClientIdChange(\n selectedNetworkClientId: NetworkClientId,\n ) {\n const {\n configuration: { chainId },\n } = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n );\n\n if (chainId !== this.#selectedChainId) {\n this.#selectedChainId = chainId;\n await this.updateGasPrices({ chainId });\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sample-gas-prices-controller.cjs","sourceRoot":"","sources":["../src/sample-gas-prices-controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAMA,+DAA2D;AAM3D,kBAAkB;AAElB;;;;GAIG;AACU,QAAA,cAAc,GAAG,2BAA2B,CAAC;AAuC1D;;GAEG;AACH,MAAM,2BAA2B,GAAG;IAClC,kBAAkB,EAAE;QAClB,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,KAAK;KACjB;CACsD,CAAC;AAmE1D;;;;;;;GAOG;AACH,SAAgB,wCAAwC;IACtD,OAAO;QACL,kBAAkB,EAAE,EAAE;KACvB,CAAC;AACJ,CAAC;AAJD,4FAIC;AAED,gCAAgC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAa,yBAA0B,SAAQ,gCAI9C;IAMC;;;;;;;;;OASG;IACH,YAAY,EACV,SAAS,EACT,KAAK,EACL,gBAAgB,GAKjB;QACC,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,2BAA2B;YACrC,IAAI,EAAE,sBAAc;YACpB,KAAK,EAAE;gBACL,GAAG,wCAAwC,EAAE;gBAC7C,GAAG,KAAK;aACT;SACF,CAAC,CAAC;QAhCL;;WAEG;QACM,8DAAkD;QA+BzD,uBAAA,IAAI,+CAAqB,gBAAgB,MAAA,CAAC;QAE1C,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,sBAAc,kBAAkB,EACnC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAChC,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,eAAe;QACnB,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;QAC5E,MAAM,iBAAiB,GACrB,MAAM,uBAAA,IAAI,mDAAkB,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QACvD,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,kBAAkB,CAAC,OAAO,CAAC,GAAG;gBAClC,GAAG,iBAAiB;gBACpB,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;aACtC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA9DD,8DA8DC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport type { NetworkControllerGetStateAction } from './network-controller-types';\nimport type { SampleAbstractGasPricesService } from './sample-gas-prices-service';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link SampleGasPricesController}, used to namespace the\n * controller's actions and events and to namespace the controller's state data\n * when composed with other controllers.\n */\nexport const controllerName = 'SampleGasPricesController';\n\n// === STATE ===\n\n/**\n * The collection of gas price data fetched periodically.\n */\ntype GasPrices = {\n /**\n * The total estimated gas in the \"low\" bucket.\n */\n low: number;\n /**\n * The total estimated gas in the \"average\" bucket.\n */\n average: number;\n /**\n * The total estimated gas in the \"high\" bucket.\n */\n high: number;\n /**\n * The date/time (in ISO-8601 format) when prices were fetched.\n */\n fetchedDate: string;\n};\n\n/**\n * Describes the shape of the state object for {@link SampleGasPricesController}.\n */\nexport type SampleGasPricesControllerState = {\n /**\n * The registry of pet names, categorized by chain ID first and address\n * second.\n */\n gasPricesByChainId: {\n [chainId: Hex]: GasPrices;\n };\n};\n\n/**\n * The metadata for each property in {@link SampleGasPricesControllerState}.\n */\nconst gasPricesControllerMetadata = {\n gasPricesByChainId: {\n persist: true,\n anonymous: false,\n },\n} satisfies StateMetadata<SampleGasPricesControllerState>;\n\n// === MESSENGER ===\n\n/**\n * The action which can be used to retrieve the state of the\n * {@link SampleGasPricesController}.\n */\nexport type SampleGasPricesControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SampleGasPricesControllerState\n>;\n\n/**\n * The action which can be used to update gas prices.\n */\nexport type SampleGasPricesControllerUpdateGasPricesAction = {\n type: `${typeof controllerName}:updateGasPrices`;\n handler: SampleGasPricesController['updateGasPrices'];\n};\n\n/**\n * All actions that {@link SampleGasPricesController} registers, to be called\n * externally.\n */\nexport type SampleGasPricesControllerActions =\n | SampleGasPricesControllerGetStateAction\n | SampleGasPricesControllerUpdateGasPricesAction;\n\n/**\n * All actions that {@link SampleGasPricesController} calls internally.\n */\ntype AllowedActions = NetworkControllerGetStateAction;\n\n/**\n * The event that {@link SampleGasPricesController} publishes when updating state.\n */\nexport type SampleGasPricesControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n SampleGasPricesControllerState\n >;\n\n/**\n * All events that {@link SampleGasPricesController} publishes, to be subscribed to\n * externally.\n */\nexport type SampleGasPricesControllerEvents =\n SampleGasPricesControllerStateChangeEvent;\n\n/**\n * All events that {@link SampleGasPricesController} subscribes to internally.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link SampleGasPricesController}.\n */\nexport type SampleGasPricesControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n SampleGasPricesControllerActions | AllowedActions,\n SampleGasPricesControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/**\n * Constructs the default {@link SampleGasPricesController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link SampleGasPricesController} state.\n */\nexport function getDefaultSampleGasPricesControllerState(): SampleGasPricesControllerState {\n return {\n gasPricesByChainId: {},\n };\n}\n\n// === CONTROLLER DEFINITION ===\n\n/**\n * `SampleGasPricesController` fetches and persists gas prices for various chains.\n *\n * @example\n *\n * ``` ts\n * import { Messenger } from '@metamask/base-controller';\n * import {\n * SampleGasPricesController,\n * SampleGasPricesService\n * } from '@metamask/example-controllers';\n * import type {\n * SampleGasPricesControllerActions,\n * SampleGasPricesControllerEvents\n * } from '@metamask/example-controllers';\n * import type { NetworkControllerGetStateAction } from '@metamask/network-controller';\n *\n * // Assuming that you're using this in the browser\n * const gasPricesService = new SampleGasPricesService({ fetch });\n * const rootMessenger = new Messenger<\n * SampleGasPricesControllerActions | NetworkControllerGetStateAction,\n * SampleGasPricesControllerEvents\n * >();\n * const gasPricesMessenger = rootMessenger.getRestricted({\n * name: 'SampleGasPricesController',\n * allowedActions: ['NetworkController:getState'],\n * allowedEvents: [],\n * });\n * const gasPricesController = new SampleGasPricesController({\n * messenger: gasPricesMessenger,\n * gasPricesService,\n * });\n *\n * // Assuming that `NetworkController:getState` returns an object with a\n * // `chainId` of `0x42`...\n * await gasPricesController.updateGasPrices();\n * gasPricesController.state.gasPricesByChainId\n * // => { '0x42': { low: 5, average: 10, high: 15, fetchedDate: '2024-01-02T00:00:00.000Z' } }\n * ```\n */\nexport class SampleGasPricesController extends BaseController<\n typeof controllerName,\n SampleGasPricesControllerState,\n SampleGasPricesControllerMessenger\n> {\n /**\n * The service object that is used to obtain gas prices.\n */\n readonly #gasPricesService: SampleAbstractGasPricesService;\n\n /**\n * Constructs a new {@link SampleGasPricesController}.\n *\n * @param args - The arguments to the controller.\n * @param args.messenger - The messenger suited for this controller.\n * @param args.state - The desired state with which to initialize this\n * controller. Missing properties will be filled in with defaults.\n * @param args.gasPricesService - The service object that will be used to\n * obtain gas prices.\n */\n constructor({\n messenger,\n state,\n gasPricesService,\n }: {\n messenger: SampleGasPricesControllerMessenger;\n state?: Partial<SampleGasPricesControllerState>;\n gasPricesService: SampleAbstractGasPricesService;\n }) {\n super({\n messenger,\n metadata: gasPricesControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultSampleGasPricesControllerState(),\n ...state,\n },\n });\n\n this.#gasPricesService = gasPricesService;\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateGasPrices`,\n this.updateGasPrices.bind(this),\n );\n }\n\n /**\n * Fetches the latest gas prices for the current chain, persisting them to\n * state.\n */\n async updateGasPrices() {\n const { chainId } = this.messagingSystem.call('NetworkController:getState');\n const gasPricesResponse =\n await this.#gasPricesService.fetchGasPrices(chainId);\n this.update((state) => {\n state.gasPricesByChainId[chainId] = {\n ...gasPricesResponse,\n fetchedDate: new Date().toISOString(),\n };\n });\n }\n}\n"]}
|