@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.
Files changed (82) hide show
  1. package/CHANGELOG.md +1 -24
  2. package/dist/index.cjs +4 -5
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +3 -7
  5. package/dist/index.d.cts.map +1 -1
  6. package/dist/index.d.mts +3 -7
  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/network-controller-types.cjs +20 -0
  11. package/dist/network-controller-types.cjs.map +1 -0
  12. package/dist/network-controller-types.d.cts +34 -0
  13. package/dist/network-controller-types.d.cts.map +1 -0
  14. package/dist/network-controller-types.d.mts +34 -0
  15. package/dist/network-controller-types.d.mts.map +1 -0
  16. package/dist/network-controller-types.mjs +16 -0
  17. package/dist/network-controller-types.mjs.map +1 -0
  18. package/dist/sample-gas-prices-controller.cjs +41 -83
  19. package/dist/sample-gas-prices-controller.cjs.map +1 -1
  20. package/dist/sample-gas-prices-controller.d.cts +61 -78
  21. package/dist/sample-gas-prices-controller.d.cts.map +1 -1
  22. package/dist/sample-gas-prices-controller.d.mts +61 -78
  23. package/dist/sample-gas-prices-controller.d.mts.map +1 -1
  24. package/dist/sample-gas-prices-controller.mjs +41 -83
  25. package/dist/sample-gas-prices-controller.mjs.map +1 -1
  26. package/dist/sample-gas-prices-service/index.cjs +6 -0
  27. package/dist/sample-gas-prices-service/index.cjs.map +1 -0
  28. package/dist/sample-gas-prices-service/index.d.cts +3 -0
  29. package/dist/sample-gas-prices-service/index.d.cts.map +1 -0
  30. package/dist/sample-gas-prices-service/index.d.mts +3 -0
  31. package/dist/sample-gas-prices-service/index.d.mts.map +1 -0
  32. package/dist/sample-gas-prices-service/index.mjs +2 -0
  33. package/dist/sample-gas-prices-service/index.mjs.map +1 -0
  34. package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.cjs +3 -0
  35. package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.cjs.map +1 -0
  36. package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.cts +7 -0
  37. package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.cts.map +1 -0
  38. package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.mts +7 -0
  39. package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.mts.map +1 -0
  40. package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.mjs +2 -0
  41. package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.mjs.map +1 -0
  42. package/dist/sample-gas-prices-service/sample-gas-prices-service.cjs +29 -136
  43. package/dist/sample-gas-prices-service/sample-gas-prices-service.cjs.map +1 -1
  44. package/dist/sample-gas-prices-service/sample-gas-prices-service.d.cts +28 -123
  45. package/dist/sample-gas-prices-service/sample-gas-prices-service.d.cts.map +1 -1
  46. package/dist/sample-gas-prices-service/sample-gas-prices-service.d.mts +28 -123
  47. package/dist/sample-gas-prices-service/sample-gas-prices-service.d.mts.map +1 -1
  48. package/dist/sample-gas-prices-service/sample-gas-prices-service.mjs +28 -135
  49. package/dist/sample-gas-prices-service/sample-gas-prices-service.mjs.map +1 -1
  50. package/dist/sample-petnames-controller.cjs +14 -27
  51. package/dist/sample-petnames-controller.cjs.map +1 -1
  52. package/dist/sample-petnames-controller.d.cts +24 -39
  53. package/dist/sample-petnames-controller.d.cts.map +1 -1
  54. package/dist/sample-petnames-controller.d.mts +24 -39
  55. package/dist/sample-petnames-controller.d.mts.map +1 -1
  56. package/dist/sample-petnames-controller.mjs +14 -26
  57. package/dist/sample-petnames-controller.mjs.map +1 -1
  58. package/package.json +2 -3
  59. package/dist/sample-gas-prices-controller-method-action-types.cjs +0 -7
  60. package/dist/sample-gas-prices-controller-method-action-types.cjs.map +0 -1
  61. package/dist/sample-gas-prices-controller-method-action-types.d.cts +0 -21
  62. package/dist/sample-gas-prices-controller-method-action-types.d.cts.map +0 -1
  63. package/dist/sample-gas-prices-controller-method-action-types.d.mts +0 -21
  64. package/dist/sample-gas-prices-controller-method-action-types.d.mts.map +0 -1
  65. package/dist/sample-gas-prices-controller-method-action-types.mjs +0 -6
  66. package/dist/sample-gas-prices-controller-method-action-types.mjs.map +0 -1
  67. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.cjs +0 -7
  68. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.cjs.map +0 -1
  69. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.cts +0 -21
  70. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.cts.map +0 -1
  71. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.mts +0 -21
  72. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.mts.map +0 -1
  73. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.mjs +0 -6
  74. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.mjs.map +0 -1
  75. package/dist/sample-petnames-controller-method-action-types.cjs +0 -7
  76. package/dist/sample-petnames-controller-method-action-types.cjs.map +0 -1
  77. package/dist/sample-petnames-controller-method-action-types.d.cts +0 -22
  78. package/dist/sample-petnames-controller-method-action-types.d.cts.map +0 -1
  79. package/dist/sample-petnames-controller-method-action-types.d.mts +0 -22
  80. package/dist/sample-petnames-controller-method-action-types.d.mts.map +0 -1
  81. package/dist/sample-petnames-controller-method-action-types.mjs +0 -6
  82. package/dist/sample-petnames-controller-method-action-types.mjs.map +0 -1
@@ -1,9 +1,8 @@
1
1
  import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedMessenger } from "@metamask/base-controller";
2
2
  import { BaseController } from "@metamask/base-controller";
3
- import type { NetworkControllerGetNetworkClientByIdAction, NetworkControllerStateChangeEvent } from "@metamask/network-controller";
4
3
  import type { Hex } from "@metamask/utils";
5
- import type { SampleGasPricesControllerMethodActions } from "./sample-gas-prices-controller-method-action-types.cjs";
6
- import type { SampleGasPricesServiceFetchGasPricesAction } from "./sample-gas-prices-service/sample-gas-prices-service-method-action-types.cjs";
4
+ import type { NetworkControllerGetStateAction } from "./network-controller-types.cjs";
5
+ import type { SampleAbstractGasPricesService } from "./sample-gas-prices-service/index.cjs";
7
6
  /**
8
7
  * The name of the {@link SampleGasPricesController}, used to namespace the
9
8
  * controller's actions and events and to namespace the controller's state data
@@ -36,51 +35,61 @@ type GasPrices = {
36
35
  */
37
36
  export type SampleGasPricesControllerState = {
38
37
  /**
39
- * Fetched gas prices categorized by chain ID.
38
+ * The registry of pet names, categorized by chain ID first and address
39
+ * second.
40
40
  */
41
41
  gasPricesByChainId: {
42
42
  [chainId: Hex]: GasPrices;
43
43
  };
44
44
  };
45
45
  /**
46
- * Constructs the default {@link SampleGasPricesController} state. This allows
47
- * consumers to provide a partial state object when initializing the controller
48
- * and also helps in constructing complete state objects for this controller in
49
- * tests.
50
- *
51
- * @returns The default {@link SampleGasPricesController} state.
46
+ * The action which can be used to retrieve the state of the
47
+ * {@link SampleGasPricesController}.
52
48
  */
53
- export declare function getDefaultSampleGasPricesControllerState(): SampleGasPricesControllerState;
49
+ export type SampleGasPricesControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SampleGasPricesControllerState>;
54
50
  /**
55
- * Retrieves the state of the {@link SampleGasPricesController}.
51
+ * The action which can be used to update gas prices.
56
52
  */
57
- export type SampleGasPricesControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SampleGasPricesControllerState>;
53
+ export type SampleGasPricesControllerUpdateGasPricesAction = {
54
+ type: `${typeof controllerName}:updateGasPrices`;
55
+ handler: SampleGasPricesController['updateGasPrices'];
56
+ };
58
57
  /**
59
- * Actions that {@link SampleGasPricesMessenger} exposes to other consumers.
58
+ * All actions that {@link SampleGasPricesController} registers, to be called
59
+ * externally.
60
60
  */
61
- export type SampleGasPricesControllerActions = SampleGasPricesControllerGetStateAction | SampleGasPricesControllerMethodActions;
61
+ export type SampleGasPricesControllerActions = SampleGasPricesControllerGetStateAction | SampleGasPricesControllerUpdateGasPricesAction;
62
62
  /**
63
- * Actions from other messengers that {@link SampleGasPricesMessenger} calls.
63
+ * All actions that {@link SampleGasPricesController} calls internally.
64
64
  */
65
- type AllowedActions = NetworkControllerGetNetworkClientByIdAction | SampleGasPricesServiceFetchGasPricesAction;
65
+ type AllowedActions = NetworkControllerGetStateAction;
66
66
  /**
67
- * Published when the state of {@link SampleGasPricesController} changes.
67
+ * The event that {@link SampleGasPricesController} publishes when updating state.
68
68
  */
69
69
  export type SampleGasPricesControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SampleGasPricesControllerState>;
70
70
  /**
71
- * Events that {@link SampleGasPricesMessenger} exposes to other consumers.
71
+ * All events that {@link SampleGasPricesController} publishes, to be subscribed to
72
+ * externally.
72
73
  */
73
74
  export type SampleGasPricesControllerEvents = SampleGasPricesControllerStateChangeEvent;
74
75
  /**
75
- * Events from other messengers that {@link SampleGasPricesMessenger} subscribes
76
- * to.
76
+ * All events that {@link SampleGasPricesController} subscribes to internally.
77
77
  */
78
- type AllowedEvents = NetworkControllerStateChangeEvent;
78
+ type AllowedEvents = never;
79
79
  /**
80
- * The messenger restricted to actions and events accessed by
80
+ * The messenger which is restricted to actions and events accessed by
81
81
  * {@link SampleGasPricesController}.
82
82
  */
83
83
  export type SampleGasPricesControllerMessenger = RestrictedMessenger<typeof controllerName, SampleGasPricesControllerActions | AllowedActions, SampleGasPricesControllerEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
84
+ /**
85
+ * Constructs the default {@link SampleGasPricesController} state. This allows
86
+ * consumers to provide a partial state object when initializing the controller
87
+ * and also helps in constructing complete state objects for this controller in
88
+ * tests.
89
+ *
90
+ * @returns The default {@link SampleGasPricesController} state.
91
+ */
92
+ export declare function getDefaultSampleGasPricesControllerState(): SampleGasPricesControllerState;
84
93
  /**
85
94
  * `SampleGasPricesController` fetches and persists gas prices for various chains.
86
95
  *
@@ -88,60 +97,36 @@ export type SampleGasPricesControllerMessenger = RestrictedMessenger<typeof cont
88
97
  *
89
98
  * ``` ts
90
99
  * import { Messenger } from '@metamask/base-controller';
91
- * import type {
92
- * NetworkControllerActions,
93
- * NetworkControllerEvents,
94
- * } from '@metamask/network-controller';
95
- * import type {
96
- * SampleGasPricesControllerActions,
97
- * SampleGasPricesControllerEvents,
98
- * SampleGasPricesServiceActions,
99
- * SampleGasPricesServiceEvents,
100
- * } from '@metamask/sample-controllers';
101
100
  * import {
102
101
  * SampleGasPricesController,
103
- * SampleGasPricesService,
104
- * selectGasPrices,
105
- * } from '@metamask/sample-controllers';
102
+ * SampleGasPricesService
103
+ * } from '@metamask/example-controllers';
104
+ * import type {
105
+ * SampleGasPricesControllerActions,
106
+ * SampleGasPricesControllerEvents
107
+ * } from '@metamask/example-controllers';
108
+ * import type { NetworkControllerGetStateAction } from '@metamask/network-controller';
106
109
  *
107
- * const globalMessenger = new Messenger<
108
- * SampleGasPricesServiceActions
109
- * | SampleGasPricesControllerActions
110
- * | NetworkControllerActions,
111
- * SampleGasPricesServiceEvents
112
- * | SampleGasPricesControllerEvents
113
- * | NetworkControllerEvents
110
+ * // Assuming that you're using this in the browser
111
+ * const gasPricesService = new SampleGasPricesService({ fetch });
112
+ * const rootMessenger = new Messenger<
113
+ * SampleGasPricesControllerActions | NetworkControllerGetStateAction,
114
+ * SampleGasPricesControllerEvents
114
115
  * >();
115
- * const gasPricesServiceMessenger = globalMessenger.getRestricted({
116
- * name: 'SampleGasPricesService',
117
- * allowedActions: [],
118
- * allowedEvents: [],
119
- * });
120
- * // Instantiate the service to register its actions on the messenger
121
- * new SampleGasPricesService({
122
- * messenger: gasPricesServiceMessenger,
123
- * // We assume you're using this in the browser.
124
- * fetch,
125
- * });
126
- * const gasPricesControllerMessenger = globalMessenger.getRestricted({
116
+ * const gasPricesMessenger = rootMessenger.getRestricted({
127
117
  * name: 'SampleGasPricesController',
128
- * allowedActions: ['NetworkController:getNetworkClientById'],
129
- * allowedEvents: ['NetworkController:stateChange'],
118
+ * allowedActions: ['NetworkController:getState'],
119
+ * allowedEvents: [],
130
120
  * });
131
- * // Instantiate the controller to register its actions on the messenger
132
- * new SampleGasPricesController({
133
- * messenger: gasPricesControllerMessenger,
121
+ * const gasPricesController = new SampleGasPricesController({
122
+ * messenger: gasPricesMessenger,
123
+ * gasPricesService,
134
124
  * });
135
125
  *
136
- * // Later...
137
- * await globalMessenger.call(
138
- * 'SampleGasPricesController:updateGasPrices',
139
- * { chainId: '0x42' },
140
- * );
141
- * const gasPricesControllerState = await globalMessenger.call(
142
- * 'SampleGasPricesController:getState',
143
- * );
144
- * gasPricesControllerState.gasPricesByChainId
126
+ * // Assuming that `NetworkController:getState` returns an object with a
127
+ * // `chainId` of `0x42`...
128
+ * await gasPricesController.updateGasPrices();
129
+ * gasPricesController.state.gasPricesByChainId
145
130
  * // => { '0x42': { low: 5, average: 10, high: 15, fetchedDate: '2024-01-02T00:00:00.000Z' } }
146
131
  * ```
147
132
  */
@@ -150,25 +135,23 @@ export declare class SampleGasPricesController extends BaseController<typeof con
150
135
  /**
151
136
  * Constructs a new {@link SampleGasPricesController}.
152
137
  *
153
- * @param args - The constructor arguments.
138
+ * @param args - The arguments to the controller.
154
139
  * @param args.messenger - The messenger suited for this controller.
155
140
  * @param args.state - The desired state with which to initialize this
156
141
  * controller. Missing properties will be filled in with defaults.
142
+ * @param args.gasPricesService - The service object that will be used to
143
+ * obtain gas prices.
157
144
  */
158
- constructor({ messenger, state, }: {
145
+ constructor({ messenger, state, gasPricesService, }: {
159
146
  messenger: SampleGasPricesControllerMessenger;
160
147
  state?: Partial<SampleGasPricesControllerState>;
148
+ gasPricesService: SampleAbstractGasPricesService;
161
149
  });
162
150
  /**
163
- * Fetches the latest gas prices for the given chain and persists them to
151
+ * Fetches the latest gas prices for the current chain, persisting them to
164
152
  * state.
165
- *
166
- * @param args - The arguments to the function.
167
- * @param args.chainId - The chain ID for which to fetch gas prices.
168
153
  */
169
- updateGasPrices({ chainId }: {
170
- chainId: Hex;
171
- }): Promise<void>;
154
+ updateGasPrices(): Promise<void>;
172
155
  }
173
156
  export {};
174
157
  //# sourceMappingURL=sample-gas-prices-controller.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sample-gas-prices-controller.d.cts","sourceRoot":"","sources":["../src/sample-gas-prices-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,mBAAmB,EAEpB,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAEV,2CAA2C,EAC3C,iCAAiC,EAClC,qCAAqC;AACtC,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EAAE,sCAAsC,EAAE,+DAA2D;AACjH,OAAO,KAAK,EAAE,0CAA0C,EAAE,sFAAkF;AAI5I;;;;GAIG;AACH,eAAO,MAAM,cAAc,8BAA8B,CAAC;AAI1D;;GAEG;AACH,KAAK,SAAS,GAAG;IACf;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C;;OAEG;IACH,kBAAkB,EAAE;QAClB,CAAC,OAAO,EAAE,GAAG,GAAG,SAAS,CAAC;KAC3B,CAAC;CACH,CAAC;AAcF;;;;;;;GAOG;AACH,wBAAgB,wCAAwC,IAAI,8BAA8B,CAIzF;AAMD;;GAEG;AACH,MAAM,MAAM,uCAAuC,GAAG,wBAAwB,CAC5E,OAAO,cAAc,EACrB,8BAA8B,CAC/B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gCAAgC,GACxC,uCAAuC,GACvC,sCAAsC,CAAC;AAE3C;;GAEG;AACH,KAAK,cAAc,GACf,2CAA2C,GAC3C,0CAA0C,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,yCAAyC,GACnD,0BAA0B,CACxB,OAAO,cAAc,EACrB,8BAA8B,CAC/B,CAAC;AAEJ;;GAEG;AACH,MAAM,MAAM,+BAA+B,GACzC,yCAAyC,CAAC;AAE5C;;;GAGG;AACH,KAAK,aAAa,GAAG,iCAAiC,CAAC;AAEvD;;;GAGG;AACH,MAAM,MAAM,kCAAkC,GAAG,mBAAmB,CAClE,OAAO,cAAc,EACrB,gCAAgC,GAAG,cAAc,EACjD,+BAA+B,GAAG,aAAa,EAC/C,cAAc,CAAC,MAAM,CAAC,EACtB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC;AAIF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,qBAAa,yBAA0B,SAAQ,cAAc,CAC3D,OAAO,cAAc,EACrB,8BAA8B,EAC9B,kCAAkC,CACnC;;IAMC;;;;;;;OAOG;gBACS,EACV,SAAS,EACT,KAAK,GACN,EAAE;QACD,SAAS,EAAE,kCAAkC,CAAC;QAC9C,KAAK,CAAC,EAAE,OAAO,CAAC,8BAA8B,CAAC,CAAC;KACjD;IAwBD;;;;;;OAMG;IACG,eAAe,CAAC,EAAE,OAAO,EAAE,EAAE;QAAE,OAAO,EAAE,GAAG,CAAA;KAAE;CAmCpD"}
1
+ {"version":3,"file":"sample-gas-prices-controller.d.cts","sourceRoot":"","sources":["../src/sample-gas-prices-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,mBAAmB,EAEpB,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EAAE,+BAA+B,EAAE,uCAAmC;AAClF,OAAO,KAAK,E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AC,CACtB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,wCAAwC,IAAI,8BAA8B,CAIzF;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,qBAAa,yBAA0B,SAAQ,cAAc,CAC3D,OAAO,cAAc,EACrB,8BAA8B,EAC9B,kCAAkC,CACnC;;IAMC;;;;;;;;;OASG;gBACS,EACV,SAAS,EACT,KAAK,EACL,gBAAgB,GACjB,EAAE;QACD,SAAS,EAAE,kCAAkC,CAAC;QAC9C,KAAK,CAAC,EAAE,OAAO,CAAC,8BAA8B,CAAC,CAAC;QAChD,gBAAgB,EAAE,8BAA8B,CAAC;KAClD;IAmBD;;;OAGG;IACG,eAAe;CAWtB"}
@@ -1,9 +1,8 @@
1
1
  import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedMessenger } from "@metamask/base-controller";
2
2
  import { BaseController } from "@metamask/base-controller";
3
- import type { NetworkControllerGetNetworkClientByIdAction, NetworkControllerStateChangeEvent } from "@metamask/network-controller";
4
3
  import type { Hex } from "@metamask/utils";
5
- import type { SampleGasPricesControllerMethodActions } from "./sample-gas-prices-controller-method-action-types.mjs";
6
- import type { SampleGasPricesServiceFetchGasPricesAction } from "./sample-gas-prices-service/sample-gas-prices-service-method-action-types.mjs";
4
+ import type { NetworkControllerGetStateAction } from "./network-controller-types.mjs";
5
+ import type { SampleAbstractGasPricesService } from "./sample-gas-prices-service/index.mjs";
7
6
  /**
8
7
  * The name of the {@link SampleGasPricesController}, used to namespace the
9
8
  * controller's actions and events and to namespace the controller's state data
@@ -36,51 +35,61 @@ type GasPrices = {
36
35
  */
37
36
  export type SampleGasPricesControllerState = {
38
37
  /**
39
- * Fetched gas prices categorized by chain ID.
38
+ * The registry of pet names, categorized by chain ID first and address
39
+ * second.
40
40
  */
41
41
  gasPricesByChainId: {
42
42
  [chainId: Hex]: GasPrices;
43
43
  };
44
44
  };
45
45
  /**
46
- * Constructs the default {@link SampleGasPricesController} state. This allows
47
- * consumers to provide a partial state object when initializing the controller
48
- * and also helps in constructing complete state objects for this controller in
49
- * tests.
50
- *
51
- * @returns The default {@link SampleGasPricesController} state.
46
+ * The action which can be used to retrieve the state of the
47
+ * {@link SampleGasPricesController}.
52
48
  */
53
- export declare function getDefaultSampleGasPricesControllerState(): SampleGasPricesControllerState;
49
+ export type SampleGasPricesControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SampleGasPricesControllerState>;
54
50
  /**
55
- * Retrieves the state of the {@link SampleGasPricesController}.
51
+ * The action which can be used to update gas prices.
56
52
  */
57
- export type SampleGasPricesControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SampleGasPricesControllerState>;
53
+ export type SampleGasPricesControllerUpdateGasPricesAction = {
54
+ type: `${typeof controllerName}:updateGasPrices`;
55
+ handler: SampleGasPricesController['updateGasPrices'];
56
+ };
58
57
  /**
59
- * Actions that {@link SampleGasPricesMessenger} exposes to other consumers.
58
+ * All actions that {@link SampleGasPricesController} registers, to be called
59
+ * externally.
60
60
  */
61
- export type SampleGasPricesControllerActions = SampleGasPricesControllerGetStateAction | SampleGasPricesControllerMethodActions;
61
+ export type SampleGasPricesControllerActions = SampleGasPricesControllerGetStateAction | SampleGasPricesControllerUpdateGasPricesAction;
62
62
  /**
63
- * Actions from other messengers that {@link SampleGasPricesMessenger} calls.
63
+ * All actions that {@link SampleGasPricesController} calls internally.
64
64
  */
65
- type AllowedActions = NetworkControllerGetNetworkClientByIdAction | SampleGasPricesServiceFetchGasPricesAction;
65
+ type AllowedActions = NetworkControllerGetStateAction;
66
66
  /**
67
- * Published when the state of {@link SampleGasPricesController} changes.
67
+ * The event that {@link SampleGasPricesController} publishes when updating state.
68
68
  */
69
69
  export type SampleGasPricesControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SampleGasPricesControllerState>;
70
70
  /**
71
- * Events that {@link SampleGasPricesMessenger} exposes to other consumers.
71
+ * All events that {@link SampleGasPricesController} publishes, to be subscribed to
72
+ * externally.
72
73
  */
73
74
  export type SampleGasPricesControllerEvents = SampleGasPricesControllerStateChangeEvent;
74
75
  /**
75
- * Events from other messengers that {@link SampleGasPricesMessenger} subscribes
76
- * to.
76
+ * All events that {@link SampleGasPricesController} subscribes to internally.
77
77
  */
78
- type AllowedEvents = NetworkControllerStateChangeEvent;
78
+ type AllowedEvents = never;
79
79
  /**
80
- * The messenger restricted to actions and events accessed by
80
+ * The messenger which is restricted to actions and events accessed by
81
81
  * {@link SampleGasPricesController}.
82
82
  */
83
83
  export type SampleGasPricesControllerMessenger = RestrictedMessenger<typeof controllerName, SampleGasPricesControllerActions | AllowedActions, SampleGasPricesControllerEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
84
+ /**
85
+ * Constructs the default {@link SampleGasPricesController} state. This allows
86
+ * consumers to provide a partial state object when initializing the controller
87
+ * and also helps in constructing complete state objects for this controller in
88
+ * tests.
89
+ *
90
+ * @returns The default {@link SampleGasPricesController} state.
91
+ */
92
+ export declare function getDefaultSampleGasPricesControllerState(): SampleGasPricesControllerState;
84
93
  /**
85
94
  * `SampleGasPricesController` fetches and persists gas prices for various chains.
86
95
  *
@@ -88,60 +97,36 @@ export type SampleGasPricesControllerMessenger = RestrictedMessenger<typeof cont
88
97
  *
89
98
  * ``` ts
90
99
  * import { Messenger } from '@metamask/base-controller';
91
- * import type {
92
- * NetworkControllerActions,
93
- * NetworkControllerEvents,
94
- * } from '@metamask/network-controller';
95
- * import type {
96
- * SampleGasPricesControllerActions,
97
- * SampleGasPricesControllerEvents,
98
- * SampleGasPricesServiceActions,
99
- * SampleGasPricesServiceEvents,
100
- * } from '@metamask/sample-controllers';
101
100
  * import {
102
101
  * SampleGasPricesController,
103
- * SampleGasPricesService,
104
- * selectGasPrices,
105
- * } from '@metamask/sample-controllers';
102
+ * SampleGasPricesService
103
+ * } from '@metamask/example-controllers';
104
+ * import type {
105
+ * SampleGasPricesControllerActions,
106
+ * SampleGasPricesControllerEvents
107
+ * } from '@metamask/example-controllers';
108
+ * import type { NetworkControllerGetStateAction } from '@metamask/network-controller';
106
109
  *
107
- * const globalMessenger = new Messenger<
108
- * SampleGasPricesServiceActions
109
- * | SampleGasPricesControllerActions
110
- * | NetworkControllerActions,
111
- * SampleGasPricesServiceEvents
112
- * | SampleGasPricesControllerEvents
113
- * | NetworkControllerEvents
110
+ * // Assuming that you're using this in the browser
111
+ * const gasPricesService = new SampleGasPricesService({ fetch });
112
+ * const rootMessenger = new Messenger<
113
+ * SampleGasPricesControllerActions | NetworkControllerGetStateAction,
114
+ * SampleGasPricesControllerEvents
114
115
  * >();
115
- * const gasPricesServiceMessenger = globalMessenger.getRestricted({
116
- * name: 'SampleGasPricesService',
117
- * allowedActions: [],
118
- * allowedEvents: [],
119
- * });
120
- * // Instantiate the service to register its actions on the messenger
121
- * new SampleGasPricesService({
122
- * messenger: gasPricesServiceMessenger,
123
- * // We assume you're using this in the browser.
124
- * fetch,
125
- * });
126
- * const gasPricesControllerMessenger = globalMessenger.getRestricted({
116
+ * const gasPricesMessenger = rootMessenger.getRestricted({
127
117
  * name: 'SampleGasPricesController',
128
- * allowedActions: ['NetworkController:getNetworkClientById'],
129
- * allowedEvents: ['NetworkController:stateChange'],
118
+ * allowedActions: ['NetworkController:getState'],
119
+ * allowedEvents: [],
130
120
  * });
131
- * // Instantiate the controller to register its actions on the messenger
132
- * new SampleGasPricesController({
133
- * messenger: gasPricesControllerMessenger,
121
+ * const gasPricesController = new SampleGasPricesController({
122
+ * messenger: gasPricesMessenger,
123
+ * gasPricesService,
134
124
  * });
135
125
  *
136
- * // Later...
137
- * await globalMessenger.call(
138
- * 'SampleGasPricesController:updateGasPrices',
139
- * { chainId: '0x42' },
140
- * );
141
- * const gasPricesControllerState = await globalMessenger.call(
142
- * 'SampleGasPricesController:getState',
143
- * );
144
- * gasPricesControllerState.gasPricesByChainId
126
+ * // Assuming that `NetworkController:getState` returns an object with a
127
+ * // `chainId` of `0x42`...
128
+ * await gasPricesController.updateGasPrices();
129
+ * gasPricesController.state.gasPricesByChainId
145
130
  * // => { '0x42': { low: 5, average: 10, high: 15, fetchedDate: '2024-01-02T00:00:00.000Z' } }
146
131
  * ```
147
132
  */
@@ -150,25 +135,23 @@ export declare class SampleGasPricesController extends BaseController<typeof con
150
135
  /**
151
136
  * Constructs a new {@link SampleGasPricesController}.
152
137
  *
153
- * @param args - The constructor arguments.
138
+ * @param args - The arguments to the controller.
154
139
  * @param args.messenger - The messenger suited for this controller.
155
140
  * @param args.state - The desired state with which to initialize this
156
141
  * controller. Missing properties will be filled in with defaults.
142
+ * @param args.gasPricesService - The service object that will be used to
143
+ * obtain gas prices.
157
144
  */
158
- constructor({ messenger, state, }: {
145
+ constructor({ messenger, state, gasPricesService, }: {
159
146
  messenger: SampleGasPricesControllerMessenger;
160
147
  state?: Partial<SampleGasPricesControllerState>;
148
+ gasPricesService: SampleAbstractGasPricesService;
161
149
  });
162
150
  /**
163
- * Fetches the latest gas prices for the given chain and persists them to
151
+ * Fetches the latest gas prices for the current chain, persisting them to
164
152
  * state.
165
- *
166
- * @param args - The arguments to the function.
167
- * @param args.chainId - The chain ID for which to fetch gas prices.
168
153
  */
169
- updateGasPrices({ chainId }: {
170
- chainId: Hex;
171
- }): Promise<void>;
154
+ updateGasPrices(): Promise<void>;
172
155
  }
173
156
  export {};
174
157
  //# sourceMappingURL=sample-gas-prices-controller.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sample-gas-prices-controller.d.mts","sourceRoot":"","sources":["../src/sample-gas-prices-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,mBAAmB,EAEpB,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAEV,2CAA2C,EAC3C,iCAAiC,EAClC,qCAAqC;AACtC,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EAAE,sCAAsC,EAAE,+DAA2D;AACj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;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,qBAAa,yBAA0B,SAAQ,cAAc,CAC3D,OAAO,cAAc,EACrB,8BAA8B,EAC9B,kCAAkC,CACnC;;IAMC;;;;;;;OAOG;gBACS,EACV,SAAS,EACT,KAAK,GACN,EAAE;QACD,SAAS,EAAE,kCAAkC,CAAC;QAC9C,KAAK,CAAC,EAAE,OAAO,CAAC,8BAA8B,CAAC,CAAC;KACjD;IAwBD;;;;;;OAMG;IACG,eAAe,CAAC,EAAE,OAAO,EAAE,EAAE;QAAE,OAAO,EAAE,GAAG,CAAA;KAAE;CAmCpD"}
1
+ {"version":3,"file":"sample-gas-prices-controller.d.mts","sourceRoot":"","sources":["../src/sample-gas-prices-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,mBAAmB,EAEpB,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EAAE,+BAA+B,EAAE,uCAAmC;AAClF,OAAO,KAAK,EAAE,8BAA8B,EAAE,8CAAoC;AAIlF;;;;GAIG;AACH,eAAO,MAAM,cAAc,8BAA8B,CAAC;AAI1D;;GAEG;AACH,KAAK,SAAS,GAAG;IACf;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C;;;OAGG;IACH,kBAAkB,EAAE;QAClB,CAAC,OAAO,EAAE,GAAG,GAAG,SAAS,CAAC;KAC3B,CAAC;CACH,CAAC;AAcF;;;GAGG;AACH,MAAM,MAAM,uCAAuC,GAAG,wBAAwB,CAC5E,OAAO,cAAc,EACrB,8B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ver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- 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");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
1
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
2
  if (kind === "m") throw new TypeError("Private method is not writable");
8
3
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
4
  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");
10
5
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
6
  };
12
- var _SampleGasPricesController_instances, _SampleGasPricesController_selectedChainId, _SampleGasPricesController_onSelectedNetworkClientIdChange;
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ 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");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _SampleGasPricesController_gasPricesService;
13
13
  import { BaseController } from "@metamask/base-controller";
14
14
  // === GENERAL ===
15
15
  /**
@@ -23,10 +23,8 @@ export const controllerName = 'SampleGasPricesController';
23
23
  */
24
24
  const gasPricesControllerMetadata = {
25
25
  gasPricesByChainId: {
26
- includeInStateLogs: true,
27
26
  persist: true,
28
27
  anonymous: false,
29
- usedInUi: true,
30
28
  },
31
29
  };
32
30
  /**
@@ -42,8 +40,6 @@ export function getDefaultSampleGasPricesControllerState() {
42
40
  gasPricesByChainId: {},
43
41
  };
44
42
  }
45
- // === MESSENGER ===
46
- const MESSENGER_EXPOSED_METHODS = ['updateGasPrices'];
47
43
  // === CONTROLLER DEFINITION ===
48
44
  /**
49
45
  * `SampleGasPricesController` fetches and persists gas prices for various chains.
@@ -52,60 +48,36 @@ const MESSENGER_EXPOSED_METHODS = ['updateGasPrices'];
52
48
  *
53
49
  * ``` ts
54
50
  * import { Messenger } from '@metamask/base-controller';
55
- * import type {
56
- * NetworkControllerActions,
57
- * NetworkControllerEvents,
58
- * } from '@metamask/network-controller';
59
- * import type {
60
- * SampleGasPricesControllerActions,
61
- * SampleGasPricesControllerEvents,
62
- * SampleGasPricesServiceActions,
63
- * SampleGasPricesServiceEvents,
64
- * } from '@metamask/sample-controllers';
65
51
  * import {
66
52
  * SampleGasPricesController,
67
- * SampleGasPricesService,
68
- * selectGasPrices,
69
- * } from '@metamask/sample-controllers';
53
+ * SampleGasPricesService
54
+ * } from '@metamask/example-controllers';
55
+ * import type {
56
+ * SampleGasPricesControllerActions,
57
+ * SampleGasPricesControllerEvents
58
+ * } from '@metamask/example-controllers';
59
+ * import type { NetworkControllerGetStateAction } from '@metamask/network-controller';
70
60
  *
71
- * const globalMessenger = new Messenger<
72
- * SampleGasPricesServiceActions
73
- * | SampleGasPricesControllerActions
74
- * | NetworkControllerActions,
75
- * SampleGasPricesServiceEvents
76
- * | SampleGasPricesControllerEvents
77
- * | NetworkControllerEvents
61
+ * // Assuming that you're using this in the browser
62
+ * const gasPricesService = new SampleGasPricesService({ fetch });
63
+ * const rootMessenger = new Messenger<
64
+ * SampleGasPricesControllerActions | NetworkControllerGetStateAction,
65
+ * SampleGasPricesControllerEvents
78
66
  * >();
79
- * const gasPricesServiceMessenger = globalMessenger.getRestricted({
80
- * name: 'SampleGasPricesService',
81
- * allowedActions: [],
82
- * allowedEvents: [],
83
- * });
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({
67
+ * const gasPricesMessenger = rootMessenger.getRestricted({
91
68
  * name: 'SampleGasPricesController',
92
- * allowedActions: ['NetworkController:getNetworkClientById'],
93
- * allowedEvents: ['NetworkController:stateChange'],
69
+ * allowedActions: ['NetworkController:getState'],
70
+ * allowedEvents: [],
94
71
  * });
95
- * // Instantiate the controller to register its actions on the messenger
96
- * new SampleGasPricesController({
97
- * messenger: gasPricesControllerMessenger,
72
+ * const gasPricesController = new SampleGasPricesController({
73
+ * messenger: gasPricesMessenger,
74
+ * gasPricesService,
98
75
  * });
99
76
  *
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
77
+ * // Assuming that `NetworkController:getState` returns an object with a
78
+ * // `chainId` of `0x42`...
79
+ * await gasPricesController.updateGasPrices();
80
+ * gasPricesController.state.gasPricesByChainId
109
81
  * // => { '0x42': { low: 5, average: 10, high: 15, fetchedDate: '2024-01-02T00:00:00.000Z' } }
110
82
  * ```
111
83
  */
@@ -113,12 +85,14 @@ export class SampleGasPricesController extends BaseController {
113
85
  /**
114
86
  * Constructs a new {@link SampleGasPricesController}.
115
87
  *
116
- * @param args - The constructor arguments.
88
+ * @param args - The arguments to the controller.
117
89
  * @param args.messenger - The messenger suited for this controller.
118
90
  * @param args.state - The desired state with which to initialize this
119
91
  * controller. Missing properties will be filled in with defaults.
92
+ * @param args.gasPricesService - The service object that will be used to
93
+ * obtain gas prices.
120
94
  */
121
- constructor({ messenger, state, }) {
95
+ constructor({ messenger, state, gasPricesService, }) {
122
96
  super({
123
97
  messenger,
124
98
  metadata: gasPricesControllerMetadata,
@@ -128,23 +102,20 @@ export class SampleGasPricesController extends BaseController {
128
102
  ...state,
129
103
  },
130
104
  });
131
- _SampleGasPricesController_instances.add(this);
132
105
  /**
133
- * The globally selected chain ID.
106
+ * The service object that is used to obtain gas prices.
134
107
  */
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);
108
+ _SampleGasPricesController_gasPricesService.set(this, void 0);
109
+ __classPrivateFieldSet(this, _SampleGasPricesController_gasPricesService, gasPricesService, "f");
110
+ this.messagingSystem.registerActionHandler(`${controllerName}:updateGasPrices`, this.updateGasPrices.bind(this));
138
111
  }
139
112
  /**
140
- * Fetches the latest gas prices for the given chain and persists them to
113
+ * Fetches the latest gas prices for the current chain, persisting them to
141
114
  * state.
142
- *
143
- * @param args - The arguments to the function.
144
- * @param args.chainId - The chain ID for which to fetch gas prices.
145
115
  */
146
- async updateGasPrices({ chainId }) {
147
- const gasPricesResponse = await this.messagingSystem.call('SampleGasPricesService:fetchGasPrices', chainId);
116
+ async updateGasPrices() {
117
+ const { chainId } = this.messagingSystem.call('NetworkController:getState');
118
+ const gasPricesResponse = await __classPrivateFieldGet(this, _SampleGasPricesController_gasPricesService, "f").fetchGasPrices(chainId);
148
119
  this.update((state) => {
149
120
  state.gasPricesByChainId[chainId] = {
150
121
  ...gasPricesResponse,
@@ -153,18 +124,5 @@ export class SampleGasPricesController extends BaseController {
153
124
  });
154
125
  }
155
126
  }
156
- _SampleGasPricesController_selectedChainId = new WeakMap(), _SampleGasPricesController_instances = new WeakSet(), _SampleGasPricesController_onSelectedNetworkClientIdChange =
157
- /**
158
- * Callback to call when the globally selected network client ID changes,
159
- * ensuring that gas prices get updated.
160
- *
161
- * @param selectedNetworkClientId - The globally selected network client ID.
162
- */
163
- async function _SampleGasPricesController_onSelectedNetworkClientIdChange(selectedNetworkClientId) {
164
- const { configuration: { chainId }, } = this.messagingSystem.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
165
- if (chainId !== __classPrivateFieldGet(this, _SampleGasPricesController_selectedChainId, "f")) {
166
- __classPrivateFieldSet(this, _SampleGasPricesController_selectedChainId, chainId, "f");
167
- await this.updateGasPrices({ chainId });
168
- }
169
- };
127
+ _SampleGasPricesController_gasPricesService = new WeakMap();
170
128
  //# sourceMappingURL=sample-gas-prices-controller.mjs.map