@metamask-previews/sample-controllers 1.0.0-preview-aa8c4291 → 1.0.0-preview-8facad04

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 (82) hide show
  1. package/CHANGELOG.md +23 -1
  2. package/dist/index.cjs +5 -4
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +7 -3
  5. package/dist/index.d.cts.map +1 -1
  6. package/dist/index.d.mts +7 -3
  7. package/dist/index.d.mts.map +1 -1
  8. package/dist/index.mjs +3 -3
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/sample-gas-prices-controller-method-action-types.cjs +7 -0
  11. package/dist/sample-gas-prices-controller-method-action-types.cjs.map +1 -0
  12. package/dist/sample-gas-prices-controller-method-action-types.d.cts +21 -0
  13. package/dist/sample-gas-prices-controller-method-action-types.d.cts.map +1 -0
  14. package/dist/sample-gas-prices-controller-method-action-types.d.mts +21 -0
  15. package/dist/sample-gas-prices-controller-method-action-types.d.mts.map +1 -0
  16. package/dist/sample-gas-prices-controller-method-action-types.mjs +6 -0
  17. package/dist/sample-gas-prices-controller-method-action-types.mjs.map +1 -0
  18. package/dist/sample-gas-prices-controller.cjs +77 -39
  19. package/dist/sample-gas-prices-controller.cjs.map +1 -1
  20. package/dist/sample-gas-prices-controller.d.cts +74 -59
  21. package/dist/sample-gas-prices-controller.d.cts.map +1 -1
  22. package/dist/sample-gas-prices-controller.d.mts +74 -59
  23. package/dist/sample-gas-prices-controller.d.mts.map +1 -1
  24. package/dist/sample-gas-prices-controller.mjs +77 -39
  25. package/dist/sample-gas-prices-controller.mjs.map +1 -1
  26. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.cjs +7 -0
  27. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.cjs.map +1 -0
  28. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.cts +21 -0
  29. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.cts.map +1 -0
  30. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.mts +21 -0
  31. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.mts.map +1 -0
  32. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.mjs +6 -0
  33. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.mjs.map +1 -0
  34. package/dist/sample-gas-prices-service/sample-gas-prices-service.cjs +135 -29
  35. package/dist/sample-gas-prices-service/sample-gas-prices-service.cjs.map +1 -1
  36. package/dist/sample-gas-prices-service/sample-gas-prices-service.d.cts +122 -28
  37. package/dist/sample-gas-prices-service/sample-gas-prices-service.d.cts.map +1 -1
  38. package/dist/sample-gas-prices-service/sample-gas-prices-service.d.mts +122 -28
  39. package/dist/sample-gas-prices-service/sample-gas-prices-service.d.mts.map +1 -1
  40. package/dist/sample-gas-prices-service/sample-gas-prices-service.mjs +134 -28
  41. package/dist/sample-gas-prices-service/sample-gas-prices-service.mjs.map +1 -1
  42. package/dist/sample-petnames-controller-method-action-types.cjs +7 -0
  43. package/dist/sample-petnames-controller-method-action-types.cjs.map +1 -0
  44. package/dist/sample-petnames-controller-method-action-types.d.cts +22 -0
  45. package/dist/sample-petnames-controller-method-action-types.d.cts.map +1 -0
  46. package/dist/sample-petnames-controller-method-action-types.d.mts +22 -0
  47. package/dist/sample-petnames-controller-method-action-types.d.mts.map +1 -0
  48. package/dist/sample-petnames-controller-method-action-types.mjs +6 -0
  49. package/dist/sample-petnames-controller-method-action-types.mjs.map +1 -0
  50. package/dist/sample-petnames-controller.cjs +24 -13
  51. package/dist/sample-petnames-controller.cjs.map +1 -1
  52. package/dist/sample-petnames-controller.d.cts +38 -23
  53. package/dist/sample-petnames-controller.d.cts.map +1 -1
  54. package/dist/sample-petnames-controller.d.mts +38 -23
  55. package/dist/sample-petnames-controller.d.mts.map +1 -1
  56. package/dist/sample-petnames-controller.mjs +23 -13
  57. package/dist/sample-petnames-controller.mjs.map +1 -1
  58. package/package.json +2 -1
  59. package/dist/network-controller-types.cjs +0 -20
  60. package/dist/network-controller-types.cjs.map +0 -1
  61. package/dist/network-controller-types.d.cts +0 -34
  62. package/dist/network-controller-types.d.cts.map +0 -1
  63. package/dist/network-controller-types.d.mts +0 -34
  64. package/dist/network-controller-types.d.mts.map +0 -1
  65. package/dist/network-controller-types.mjs +0 -16
  66. package/dist/network-controller-types.mjs.map +0 -1
  67. package/dist/sample-gas-prices-service/index.cjs +0 -6
  68. package/dist/sample-gas-prices-service/index.cjs.map +0 -1
  69. package/dist/sample-gas-prices-service/index.d.cts +0 -3
  70. package/dist/sample-gas-prices-service/index.d.cts.map +0 -1
  71. package/dist/sample-gas-prices-service/index.d.mts +0 -3
  72. package/dist/sample-gas-prices-service/index.d.mts.map +0 -1
  73. package/dist/sample-gas-prices-service/index.mjs +0 -2
  74. package/dist/sample-gas-prices-service/index.mjs.map +0 -1
  75. package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.cjs +0 -3
  76. package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.cjs.map +0 -1
  77. package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.cts +0 -7
  78. package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.cts.map +0 -1
  79. package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.mts +0 -7
  80. package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.mts.map +0 -1
  81. package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.mjs +0 -2
  82. package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,10 +7,32 @@ 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
+
10
23
  ### Changed
11
24
 
12
- - Bump `@metamask/utils` from `^11.2.0` to `^11.4.2` ([#6054](https://github.com/MetaMask/core/pull/6054))
25
+ - **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))
26
+ - **BREAKING:** `SampleGasPricesController.updateGasPrices` now takes a required `chainId` option ([#6168](https://github.com/MetaMask/core/pull/6168))
27
+ - `SampleGasPricesController` will now automatically update gas prices when the globally selected chain changes ([#6168](https://github.com/MetaMask/core/pull/6168))
13
28
  - Bump `@metamask/base-controller` from `^8.0.1` to `^8.2.0` ([#6284](https://github.com/MetaMask/core/pull/6284), [#6355](https://github.com/MetaMask/core/pull/6355))
29
+ - Bump `@metamask/utils` from `^11.2.0` to `^11.4.2` ([#6054](https://github.com/MetaMask/core/pull/6054))
30
+
31
+ ### Removed
32
+
33
+ - **BREAKING:** `SampleGasPricesController` no longer takes a `gasPricesService` option ([#6168](https://github.com/MetaMask/core/pull/6168))
34
+ - The controller now expects `SampleGasPricesService` to have been instantiated ahead of time
35
+ - **BREAKING:** Remove `SampleAbstractGasPricesService` ([#6168](https://github.com/MetaMask/core/pull/6168))
14
36
 
15
37
  ## [1.0.0]
16
38
 
package/dist/index.cjs CHANGED
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SampleGasPricesService = exports.SamplePetnamesController = exports.SampleGasPricesController = exports.getDefaultSampleGasPricesControllerState = void 0;
3
+ exports.getDefaultPetnamesControllerState = exports.SamplePetnamesController = exports.getDefaultSampleGasPricesControllerState = exports.SampleGasPricesController = exports.SampleGasPricesService = void 0;
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; } });
4
6
  var sample_gas_prices_controller_1 = require("./sample-gas-prices-controller.cjs");
5
- Object.defineProperty(exports, "getDefaultSampleGasPricesControllerState", { enumerable: true, get: function () { return sample_gas_prices_controller_1.getDefaultSampleGasPricesControllerState; } });
6
7
  Object.defineProperty(exports, "SampleGasPricesController", { enumerable: true, get: function () { return sample_gas_prices_controller_1.SampleGasPricesController; } });
8
+ Object.defineProperty(exports, "getDefaultSampleGasPricesControllerState", { enumerable: true, get: function () { return sample_gas_prices_controller_1.getDefaultSampleGasPricesControllerState; } });
7
9
  var sample_petnames_controller_1 = require("./sample-petnames-controller.cjs");
8
10
  Object.defineProperty(exports, "SamplePetnamesController", { enumerable: true, get: function () { return sample_petnames_controller_1.SamplePetnamesController; } });
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; } });
11
+ Object.defineProperty(exports, "getDefaultPetnamesControllerState", { enumerable: true, get: function () { return sample_petnames_controller_1.getDefaultPetnamesControllerState; } });
11
12
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
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"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAMA,uGAA+F;AAAtF,mIAAA,sBAAsB,OAAA;AAS/B,mFAGwC;AAFtC,yIAAA,yBAAyB,OAAA;AACzB,wJAAA,wCAAwC,OAAA;AAW1C,+EAGsC;AAFpC,sIAAA,wBAAwB,OAAA;AACxB,+IAAA,iCAAiC,OAAA","sourcesContent":["export type {\n SampleGasPricesServiceActions,\n SampleGasPricesServiceEvents,\n SampleGasPricesServiceMessenger,\n} from './sample-gas-prices-service/sample-gas-prices-service';\nexport type { SampleGasPricesServiceFetchGasPricesAction } from './sample-gas-prices-service/sample-gas-prices-service-method-action-types';\nexport { SampleGasPricesService } from './sample-gas-prices-service/sample-gas-prices-service';\nexport type {\n SampleGasPricesControllerActions,\n SampleGasPricesControllerEvents,\n SampleGasPricesControllerGetStateAction,\n SampleGasPricesControllerMessenger,\n SampleGasPricesControllerState,\n SampleGasPricesControllerStateChangeEvent,\n} from './sample-gas-prices-controller';\nexport {\n SampleGasPricesController,\n getDefaultSampleGasPricesControllerState,\n} from './sample-gas-prices-controller';\nexport type { SampleGasPricesControllerUpdateGasPricesAction } from './sample-gas-prices-controller-method-action-types';\nexport type {\n SamplePetnamesControllerActions,\n SamplePetnamesControllerEvents,\n SamplePetnamesControllerGetStateAction,\n SamplePetnamesControllerMessenger,\n SamplePetnamesControllerState,\n SamplePetnamesControllerStateChangeEvent,\n} from './sample-petnames-controller';\nexport {\n SamplePetnamesController,\n getDefaultPetnamesControllerState,\n} from './sample-petnames-controller';\nexport type { SamplePetnamesControllerAssignPetnameAction } from './sample-petnames-controller-method-action-types';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,6 +1,10 @@
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";
1
4
  export type { SampleGasPricesControllerActions, SampleGasPricesControllerEvents, SampleGasPricesControllerGetStateAction, SampleGasPricesControllerMessenger, SampleGasPricesControllerState, SampleGasPricesControllerStateChangeEvent, } from "./sample-gas-prices-controller.cjs";
2
- export { getDefaultSampleGasPricesControllerState, SampleGasPricesController, } from "./sample-gas-prices-controller.cjs";
5
+ export { SampleGasPricesController, getDefaultSampleGasPricesControllerState, } from "./sample-gas-prices-controller.cjs";
6
+ export type { SampleGasPricesControllerUpdateGasPricesAction } from "./sample-gas-prices-controller-method-action-types.cjs";
3
7
  export type { SamplePetnamesControllerActions, SamplePetnamesControllerEvents, SamplePetnamesControllerGetStateAction, SamplePetnamesControllerMessenger, SamplePetnamesControllerState, SamplePetnamesControllerStateChangeEvent, } from "./sample-petnames-controller.cjs";
4
- export { SamplePetnamesController } from "./sample-petnames-controller.cjs";
5
- export { SampleGasPricesService, type SampleAbstractGasPricesService, } from "./sample-gas-prices-service/index.cjs";
8
+ export { SamplePetnamesController, getDefaultPetnamesControllerState, } from "./sample-petnames-controller.cjs";
9
+ export type { SamplePetnamesControllerAssignPetnameAction } from "./sample-petnames-controller-method-action-types.cjs";
6
10
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,6BAA6B,EAC7B,4BAA4B,EAC5B,+BAA+B,GAChC,kEAA8D;AAC/D,YAAY,EAAE,0CAA0C,EAAE,sFAAkF;AAC5I,OAAO,EAAE,sBAAsB,EAAE,kEAA8D;AAC/F,YAAY,EACV,gCAAgC,EAChC,+BAA+B,EAC/B,uCAAuC,EACvC,kCAAkC,EAClC,8BAA8B,EAC9B,yCAAyC,GAC1C,2CAAuC;AACxC,OAAO,EACL,yBAAyB,EACzB,wCAAwC,GACzC,2CAAuC;AACxC,YAAY,EAAE,8CAA8C,EAAE,+DAA2D;AACzH,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,sCAAsC,EACtC,iCAAiC,EACjC,6BAA6B,EAC7B,wCAAwC,GACzC,yCAAqC;AACtC,OAAO,EACL,wBAAwB,EACxB,iCAAiC,GAClC,yCAAqC;AACtC,YAAY,EAAE,2CAA2C,EAAE,6DAAyD"}
package/dist/index.d.mts CHANGED
@@ -1,6 +1,10 @@
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";
1
4
  export type { SampleGasPricesControllerActions, SampleGasPricesControllerEvents, SampleGasPricesControllerGetStateAction, SampleGasPricesControllerMessenger, SampleGasPricesControllerState, SampleGasPricesControllerStateChangeEvent, } from "./sample-gas-prices-controller.mjs";
2
- export { getDefaultSampleGasPricesControllerState, SampleGasPricesController, } from "./sample-gas-prices-controller.mjs";
5
+ export { SampleGasPricesController, getDefaultSampleGasPricesControllerState, } from "./sample-gas-prices-controller.mjs";
6
+ export type { SampleGasPricesControllerUpdateGasPricesAction } from "./sample-gas-prices-controller-method-action-types.mjs";
3
7
  export type { SamplePetnamesControllerActions, SamplePetnamesControllerEvents, SamplePetnamesControllerGetStateAction, SamplePetnamesControllerMessenger, SamplePetnamesControllerState, SamplePetnamesControllerStateChangeEvent, } from "./sample-petnames-controller.mjs";
4
- export { SamplePetnamesController } from "./sample-petnames-controller.mjs";
5
- export { SampleGasPricesService, type SampleAbstractGasPricesService, } from "./sample-gas-prices-service/index.mjs";
8
+ export { SamplePetnamesController, getDefaultPetnamesControllerState, } from "./sample-petnames-controller.mjs";
9
+ export type { SamplePetnamesControllerAssignPetnameAction } from "./sample-petnames-controller-method-action-types.mjs";
6
10
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,6BAA6B,EAC7B,4BAA4B,EAC5B,+BAA+B,GAChC,kEAA8D;AAC/D,YAAY,EAAE,0CAA0C,EAAE,sFAAkF;AAC5I,OAAO,EAAE,sBAAsB,EAAE,kEAA8D;AAC/F,YAAY,EACV,gCAAgC,EAChC,+BAA+B,EAC/B,uCAAuC,EACvC,kCAAkC,EAClC,8BAA8B,EAC9B,yCAAyC,GAC1C,2CAAuC;AACxC,OAAO,EACL,yBAAyB,EACzB,wCAAwC,GACzC,2CAAuC;AACxC,YAAY,EAAE,8CAA8C,EAAE,+DAA2D;AACzH,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,sCAAsC,EACtC,iCAAiC,EACjC,6BAA6B,EAC7B,wCAAwC,GACzC,yCAAqC;AACtC,OAAO,EACL,wBAAwB,EACxB,iCAAiC,GAClC,yCAAqC;AACtC,YAAY,EAAE,2CAA2C,EAAE,6DAAyD"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
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";
1
+ export { SampleGasPricesService } from "./sample-gas-prices-service/sample-gas-prices-service.mjs";
2
+ export { SampleGasPricesController, getDefaultSampleGasPricesControllerState } from "./sample-gas-prices-controller.mjs";
3
+ export { SamplePetnamesController, getDefaultPetnamesControllerState } from "./sample-petnames-controller.mjs";
4
4
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
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"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,sBAAsB,EAAE,kEAA8D;AAS/F,OAAO,EACL,yBAAyB,EACzB,wCAAwC,EACzC,2CAAuC;AAUxC,OAAO,EACL,wBAAwB,EACxB,iCAAiC,EAClC,yCAAqC","sourcesContent":["export type {\n SampleGasPricesServiceActions,\n SampleGasPricesServiceEvents,\n SampleGasPricesServiceMessenger,\n} from './sample-gas-prices-service/sample-gas-prices-service';\nexport type { SampleGasPricesServiceFetchGasPricesAction } from './sample-gas-prices-service/sample-gas-prices-service-method-action-types';\nexport { SampleGasPricesService } from './sample-gas-prices-service/sample-gas-prices-service';\nexport type {\n SampleGasPricesControllerActions,\n SampleGasPricesControllerEvents,\n SampleGasPricesControllerGetStateAction,\n SampleGasPricesControllerMessenger,\n SampleGasPricesControllerState,\n SampleGasPricesControllerStateChangeEvent,\n} from './sample-gas-prices-controller';\nexport {\n SampleGasPricesController,\n getDefaultSampleGasPricesControllerState,\n} from './sample-gas-prices-controller';\nexport type { SampleGasPricesControllerUpdateGasPricesAction } from './sample-gas-prices-controller-method-action-types';\nexport type {\n SamplePetnamesControllerActions,\n SamplePetnamesControllerEvents,\n SamplePetnamesControllerGetStateAction,\n SamplePetnamesControllerMessenger,\n SamplePetnamesControllerState,\n SamplePetnamesControllerStateChangeEvent,\n} from './sample-petnames-controller';\nexport {\n SamplePetnamesController,\n getDefaultPetnamesControllerState,\n} from './sample-petnames-controller';\nexport type { SamplePetnamesControllerAssignPetnameAction } from './sample-petnames-controller-method-action-types';\n"]}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * This file is auto generated by `scripts/generate-method-action-types.ts`.
4
+ * Do not edit manually.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=sample-gas-prices-controller-method-action-types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample-gas-prices-controller-method-action-types.cjs","sourceRoot":"","sources":["../src/sample-gas-prices-controller-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { SampleGasPricesController } from './sample-gas-prices-controller';\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 */\nexport type SampleGasPricesControllerUpdateGasPricesAction = {\n type: `SampleGasPricesController:updateGasPrices`;\n handler: SampleGasPricesController['updateGasPrices'];\n};\n\n/**\n * Union of all SampleGasPricesController action types.\n */\nexport type SampleGasPricesControllerMethodActions =\n SampleGasPricesControllerUpdateGasPricesAction;\n"]}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * This file is auto generated by `scripts/generate-method-action-types.ts`.
3
+ * Do not edit manually.
4
+ */
5
+ import type { SampleGasPricesController } from "./sample-gas-prices-controller.cjs";
6
+ /**
7
+ * Fetches the latest gas prices for the given chain and persists them to
8
+ * state.
9
+ *
10
+ * @param args - The arguments to the function.
11
+ * @param args.chainId - The chain ID for which to fetch gas prices.
12
+ */
13
+ export type SampleGasPricesControllerUpdateGasPricesAction = {
14
+ type: `SampleGasPricesController:updateGasPrices`;
15
+ handler: SampleGasPricesController['updateGasPrices'];
16
+ };
17
+ /**
18
+ * Union of all SampleGasPricesController action types.
19
+ */
20
+ export type SampleGasPricesControllerMethodActions = SampleGasPricesControllerUpdateGasPricesAction;
21
+ //# sourceMappingURL=sample-gas-prices-controller-method-action-types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample-gas-prices-controller-method-action-types.d.cts","sourceRoot":"","sources":["../src/sample-gas-prices-controller-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,yBAAyB,EAAE,2CAAuC;AAEhF;;;;;;GAMG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,yBAAyB,CAAC,iBAAiB,CAAC,CAAC;CACvD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,sCAAsC,GAChD,8CAA8C,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * This file is auto generated by `scripts/generate-method-action-types.ts`.
3
+ * Do not edit manually.
4
+ */
5
+ import type { SampleGasPricesController } from "./sample-gas-prices-controller.mjs";
6
+ /**
7
+ * Fetches the latest gas prices for the given chain and persists them to
8
+ * state.
9
+ *
10
+ * @param args - The arguments to the function.
11
+ * @param args.chainId - The chain ID for which to fetch gas prices.
12
+ */
13
+ export type SampleGasPricesControllerUpdateGasPricesAction = {
14
+ type: `SampleGasPricesController:updateGasPrices`;
15
+ handler: SampleGasPricesController['updateGasPrices'];
16
+ };
17
+ /**
18
+ * Union of all SampleGasPricesController action types.
19
+ */
20
+ export type SampleGasPricesControllerMethodActions = SampleGasPricesControllerUpdateGasPricesAction;
21
+ //# sourceMappingURL=sample-gas-prices-controller-method-action-types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample-gas-prices-controller-method-action-types.d.mts","sourceRoot":"","sources":["../src/sample-gas-prices-controller-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,yBAAyB,EAAE,2CAAuC;AAEhF;;;;;;GAMG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,yBAAyB,CAAC,iBAAiB,CAAC,CAAC;CACvD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,sCAAsC,GAChD,8CAA8C,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * This file is auto generated by `scripts/generate-method-action-types.ts`.
3
+ * Do not edit manually.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=sample-gas-prices-controller-method-action-types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample-gas-prices-controller-method-action-types.mjs","sourceRoot":"","sources":["../src/sample-gas-prices-controller-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { SampleGasPricesController } from './sample-gas-prices-controller';\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 */\nexport type SampleGasPricesControllerUpdateGasPricesAction = {\n type: `SampleGasPricesController:updateGasPrices`;\n handler: SampleGasPricesController['updateGasPrices'];\n};\n\n/**\n * Union of all SampleGasPricesController action types.\n */\nexport type SampleGasPricesControllerMethodActions =\n SampleGasPricesControllerUpdateGasPricesAction;\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
+ };
2
7
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
8
  if (kind === "m") throw new TypeError("Private method is not writable");
4
9
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
10
  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");
6
11
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
12
  };
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;
13
+ var _SampleGasPricesController_instances, _SampleGasPricesController_selectedChainId, _SampleGasPricesController_onSelectedNetworkClientIdChange;
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");
@@ -44,6 +44,8 @@ function getDefaultSampleGasPricesControllerState() {
44
44
  };
45
45
  }
46
46
  exports.getDefaultSampleGasPricesControllerState = getDefaultSampleGasPricesControllerState;
47
+ // === MESSENGER ===
48
+ const MESSENGER_EXPOSED_METHODS = ['updateGasPrices'];
47
49
  // === CONTROLLER DEFINITION ===
48
50
  /**
49
51
  * `SampleGasPricesController` fetches and persists gas prices for various chains.
@@ -52,36 +54,58 @@ exports.getDefaultSampleGasPricesControllerState = getDefaultSampleGasPricesCont
52
54
  *
53
55
  * ``` ts
54
56
  * import { Messenger } from '@metamask/base-controller';
55
- * import {
56
- * SampleGasPricesController,
57
- * SampleGasPricesService
58
- * } from '@metamask/example-controllers';
57
+ * import type {
58
+ * NetworkControllerActions,
59
+ * NetworkControllerEvents
60
+ * } from '@metamask/network-controller';
59
61
  * import type {
60
62
  * SampleGasPricesControllerActions,
61
63
  * SampleGasPricesControllerEvents
62
64
  * } from '@metamask/example-controllers';
63
- * import type { NetworkControllerGetStateAction } from '@metamask/network-controller';
65
+ * import {
66
+ * SampleGasPricesController,
67
+ * SampleGasPricesService,
68
+ * selectGasPrices,
69
+ * } from '@metamask/example-controllers';
64
70
  *
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
71
+ * const globalMessenger = new Messenger<
72
+ * SampleGasPricesServiceActions
73
+ * | SampleGasPricesControllerActions
74
+ * | NetworkControllerActions
75
+ * SampleGasPricesServiceEvents
76
+ * | SampleGasPricesControllerEvents
77
+ * | NetworkControllerEvents
70
78
  * >();
71
- * const gasPricesMessenger = rootMessenger.getRestricted({
72
- * name: 'SampleGasPricesController',
73
- * allowedActions: ['NetworkController:getState'],
79
+ * const gasPricesServiceMessenger = globalMessenger.getRestricted({
80
+ * name: 'SampleGasPricesService',
81
+ * allowedActions: [],
74
82
  * allowedEvents: [],
75
83
  * });
76
- * const gasPricesController = new SampleGasPricesController({
77
- * messenger: gasPricesMessenger,
78
- * gasPricesService,
84
+ * // Instantiate the service to register its actions on the messenger
85
+ * new SampleGasPricesService({
86
+ * messenger: gasPricesServiceMessenger,
87
+ * // We assume you're using this in the browser.
88
+ * fetch,
89
+ * });
90
+ * const gasPricesControllerMessenger = globalMessenger.getRestricted({
91
+ * name: 'SampleGasPricesController',
92
+ * allowedActions: ['NetworkController:getNetworkClientById'],
93
+ * allowedEvents: ['NetworkController:stateChange'],
94
+ * });
95
+ * // Instantiate the controller to register its actions on the messenger
96
+ * new SampleGasPricesController({
97
+ * messenger: gasPricesControllerMessenger,
79
98
  * });
80
99
  *
81
- * // Assuming that `NetworkController:getState` returns an object with a
82
- * // `chainId` of `0x42`...
83
- * await gasPricesController.updateGasPrices();
84
- * gasPricesController.state.gasPricesByChainId
100
+ * // Later...
101
+ * await globalMessenger.call(
102
+ * 'SampleGasPricesController:updateGasPrices',
103
+ * { chainId: '0x42' },
104
+ * );
105
+ * const gasPricesControllerState = await globalMessenger.call(
106
+ * 'SampleGasPricesController:getState',
107
+ * );
108
+ * gasPricesControllerState.gasPricesByChainId
85
109
  * // => { '0x42': { low: 5, average: 10, high: 15, fetchedDate: '2024-01-02T00:00:00.000Z' } }
86
110
  * ```
87
111
  */
@@ -89,14 +113,12 @@ class SampleGasPricesController extends base_controller_1.BaseController {
89
113
  /**
90
114
  * Constructs a new {@link SampleGasPricesController}.
91
115
  *
92
- * @param args - The arguments to the controller.
116
+ * @param args - The constructor arguments.
93
117
  * @param args.messenger - The messenger suited for this controller.
94
118
  * @param args.state - The desired state with which to initialize this
95
119
  * 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.
98
120
  */
99
- constructor({ messenger, state, gasPricesService, }) {
121
+ constructor({ messenger, state, }) {
100
122
  super({
101
123
  messenger,
102
124
  metadata: gasPricesControllerMetadata,
@@ -106,20 +128,23 @@ class SampleGasPricesController extends base_controller_1.BaseController {
106
128
  ...state,
107
129
  },
108
130
  });
131
+ _SampleGasPricesController_instances.add(this);
109
132
  /**
110
- * The service object that is used to obtain gas prices.
133
+ * The globally selected chain ID.
111
134
  */
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));
135
+ _SampleGasPricesController_selectedChainId.set(this, void 0);
136
+ this.messagingSystem.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
137
+ this.messagingSystem.subscribe('NetworkController:stateChange', __classPrivateFieldGet(this, _SampleGasPricesController_instances, "m", _SampleGasPricesController_onSelectedNetworkClientIdChange).bind(this), (networkControllerState) => networkControllerState.selectedNetworkClientId);
115
138
  }
116
139
  /**
117
- * Fetches the latest gas prices for the current chain, persisting them to
140
+ * Fetches the latest gas prices for the given chain and persists them to
118
141
  * state.
142
+ *
143
+ * @param args - The arguments to the function.
144
+ * @param args.chainId - The chain ID for which to fetch gas prices.
119
145
  */
120
- async updateGasPrices() {
121
- const { chainId } = this.messagingSystem.call('NetworkController:getState');
122
- const gasPricesResponse = await __classPrivateFieldGet(this, _SampleGasPricesController_gasPricesService, "f").fetchGasPrices(chainId);
146
+ async updateGasPrices({ chainId }) {
147
+ const gasPricesResponse = await this.messagingSystem.call('SampleGasPricesService:fetchGasPrices', chainId);
123
148
  this.update((state) => {
124
149
  state.gasPricesByChainId[chainId] = {
125
150
  ...gasPricesResponse,
@@ -129,5 +154,18 @@ class SampleGasPricesController extends base_controller_1.BaseController {
129
154
  }
130
155
  }
131
156
  exports.SampleGasPricesController = SampleGasPricesController;
132
- _SampleGasPricesController_gasPricesService = new WeakMap();
157
+ _SampleGasPricesController_selectedChainId = new WeakMap(), _SampleGasPricesController_instances = new WeakSet(), _SampleGasPricesController_onSelectedNetworkClientIdChange =
158
+ /**
159
+ * Callback to call when the globally selected network client ID changes,
160
+ * ensuring that gas prices get updated.
161
+ *
162
+ * @param selectedNetworkClientId - The globally selected network client ID.
163
+ */
164
+ async function _SampleGasPricesController_onSelectedNetworkClientIdChange(selectedNetworkClientId) {
165
+ const { configuration: { chainId }, } = this.messagingSystem.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
166
+ if (chainId !== __classPrivateFieldGet(this, _SampleGasPricesController_selectedChainId, "f")) {
167
+ __classPrivateFieldSet(this, _SampleGasPricesController_selectedChainId, chainId, "f");
168
+ await this.updateGasPrices({ chainId });
169
+ }
170
+ };
133
171
  //# 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;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"]}
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,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,KAAK;KACjB;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;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 persist: true,\n anonymous: false,\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 * } from '@metamask/example-controllers';\n * import {\n * SampleGasPricesController,\n * SampleGasPricesService,\n * selectGasPrices,\n * } from '@metamask/example-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"]}