@metamask-previews/sample-controllers 1.0.0-preview-f3f2e8c8 → 1.0.0-preview-1f079244
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -1
- package/dist/index.cjs +5 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +7 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +1 -1
- package/dist/sample-gas-prices-controller-method-action-types.cjs +7 -0
- package/dist/sample-gas-prices-controller-method-action-types.cjs.map +1 -0
- package/dist/sample-gas-prices-controller-method-action-types.d.cts +21 -0
- package/dist/sample-gas-prices-controller-method-action-types.d.cts.map +1 -0
- package/dist/sample-gas-prices-controller-method-action-types.d.mts +21 -0
- package/dist/sample-gas-prices-controller-method-action-types.d.mts.map +1 -0
- package/dist/sample-gas-prices-controller-method-action-types.mjs +6 -0
- package/dist/sample-gas-prices-controller-method-action-types.mjs.map +1 -0
- package/dist/sample-gas-prices-controller.cjs +83 -41
- package/dist/sample-gas-prices-controller.cjs.map +1 -1
- package/dist/sample-gas-prices-controller.d.cts +78 -61
- package/dist/sample-gas-prices-controller.d.cts.map +1 -1
- package/dist/sample-gas-prices-controller.d.mts +78 -61
- package/dist/sample-gas-prices-controller.d.mts.map +1 -1
- package/dist/sample-gas-prices-controller.mjs +83 -41
- package/dist/sample-gas-prices-controller.mjs.map +1 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.cjs +7 -0
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.cjs.map +1 -0
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.cts +21 -0
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.cts.map +1 -0
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.mts +21 -0
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.mts.map +1 -0
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.mjs +6 -0
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.mjs.map +1 -0
- package/dist/sample-gas-prices-service/sample-gas-prices-service.cjs +136 -29
- package/dist/sample-gas-prices-service/sample-gas-prices-service.cjs.map +1 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service.d.cts +123 -28
- package/dist/sample-gas-prices-service/sample-gas-prices-service.d.cts.map +1 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service.d.mts +123 -28
- package/dist/sample-gas-prices-service/sample-gas-prices-service.d.mts.map +1 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service.mjs +135 -28
- package/dist/sample-gas-prices-service/sample-gas-prices-service.mjs.map +1 -1
- package/dist/sample-petnames-controller-method-action-types.cjs +7 -0
- package/dist/sample-petnames-controller-method-action-types.cjs.map +1 -0
- package/dist/sample-petnames-controller-method-action-types.d.cts +22 -0
- package/dist/sample-petnames-controller-method-action-types.d.cts.map +1 -0
- package/dist/sample-petnames-controller-method-action-types.d.mts +22 -0
- package/dist/sample-petnames-controller-method-action-types.d.mts.map +1 -0
- package/dist/sample-petnames-controller-method-action-types.mjs +6 -0
- package/dist/sample-petnames-controller-method-action-types.mjs.map +1 -0
- package/dist/sample-petnames-controller.cjs +27 -14
- package/dist/sample-petnames-controller.cjs.map +1 -1
- package/dist/sample-petnames-controller.d.cts +39 -24
- package/dist/sample-petnames-controller.d.cts.map +1 -1
- package/dist/sample-petnames-controller.d.mts +39 -24
- package/dist/sample-petnames-controller.d.mts.map +1 -1
- package/dist/sample-petnames-controller.mjs +26 -14
- package/dist/sample-petnames-controller.mjs.map +1 -1
- package/package.json +4 -3
- package/dist/network-controller-types.cjs +0 -20
- package/dist/network-controller-types.cjs.map +0 -1
- package/dist/network-controller-types.d.cts +0 -34
- package/dist/network-controller-types.d.cts.map +0 -1
- package/dist/network-controller-types.d.mts +0 -34
- package/dist/network-controller-types.d.mts.map +0 -1
- package/dist/network-controller-types.mjs +0 -16
- package/dist/network-controller-types.mjs.map +0 -1
- package/dist/sample-gas-prices-service/index.cjs +0 -6
- package/dist/sample-gas-prices-service/index.cjs.map +0 -1
- package/dist/sample-gas-prices-service/index.d.cts +0 -3
- package/dist/sample-gas-prices-service/index.d.cts.map +0 -1
- package/dist/sample-gas-prices-service/index.d.mts +0 -3
- package/dist/sample-gas-prices-service/index.d.mts.map +0 -1
- package/dist/sample-gas-prices-service/index.mjs +0 -2
- package/dist/sample-gas-prices-service/index.mjs.map +0 -1
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.cjs +0 -3
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.cjs.map +0 -1
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.cts +0 -7
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.cts.map +0 -1
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.mts +0 -7
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.mts.map +0 -1
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.mjs +0 -2
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.mjs.map +0 -1
|
@@ -1,8 +1,9 @@
|
|
|
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";
|
|
3
4
|
import type { Hex } from "@metamask/utils";
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
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";
|
|
6
7
|
/**
|
|
7
8
|
* The name of the {@link SampleGasPricesController}, used to namespace the
|
|
8
9
|
* controller's actions and events and to namespace the controller's state data
|
|
@@ -35,61 +36,51 @@ type GasPrices = {
|
|
|
35
36
|
*/
|
|
36
37
|
export type SampleGasPricesControllerState = {
|
|
37
38
|
/**
|
|
38
|
-
*
|
|
39
|
-
* second.
|
|
39
|
+
* Fetched gas prices categorized by chain ID.
|
|
40
40
|
*/
|
|
41
41
|
gasPricesByChainId: {
|
|
42
42
|
[chainId: Hex]: GasPrices;
|
|
43
43
|
};
|
|
44
44
|
};
|
|
45
45
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
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.
|
|
48
52
|
*/
|
|
49
|
-
export
|
|
53
|
+
export declare function getDefaultSampleGasPricesControllerState(): SampleGasPricesControllerState;
|
|
50
54
|
/**
|
|
51
|
-
*
|
|
55
|
+
* Retrieves the state of the {@link SampleGasPricesController}.
|
|
52
56
|
*/
|
|
53
|
-
export type
|
|
54
|
-
type: `${typeof controllerName}:updateGasPrices`;
|
|
55
|
-
handler: SampleGasPricesController['updateGasPrices'];
|
|
56
|
-
};
|
|
57
|
+
export type SampleGasPricesControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SampleGasPricesControllerState>;
|
|
57
58
|
/**
|
|
58
|
-
*
|
|
59
|
-
* externally.
|
|
59
|
+
* Actions that {@link SampleGasPricesMessenger} exposes to other consumers.
|
|
60
60
|
*/
|
|
61
|
-
export type SampleGasPricesControllerActions = SampleGasPricesControllerGetStateAction |
|
|
61
|
+
export type SampleGasPricesControllerActions = SampleGasPricesControllerGetStateAction | SampleGasPricesControllerMethodActions;
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
63
|
+
* Actions from other messengers that {@link SampleGasPricesMessenger} calls.
|
|
64
64
|
*/
|
|
65
|
-
type AllowedActions =
|
|
65
|
+
type AllowedActions = NetworkControllerGetNetworkClientByIdAction | SampleGasPricesServiceFetchGasPricesAction;
|
|
66
66
|
/**
|
|
67
|
-
*
|
|
67
|
+
* Published when the state of {@link SampleGasPricesController} changes.
|
|
68
68
|
*/
|
|
69
69
|
export type SampleGasPricesControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SampleGasPricesControllerState>;
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
72
|
-
* externally.
|
|
71
|
+
* Events that {@link SampleGasPricesMessenger} exposes to other consumers.
|
|
73
72
|
*/
|
|
74
73
|
export type SampleGasPricesControllerEvents = SampleGasPricesControllerStateChangeEvent;
|
|
75
74
|
/**
|
|
76
|
-
*
|
|
75
|
+
* Events from other messengers that {@link SampleGasPricesMessenger} subscribes
|
|
76
|
+
* to.
|
|
77
77
|
*/
|
|
78
|
-
type AllowedEvents =
|
|
78
|
+
type AllowedEvents = NetworkControllerStateChangeEvent;
|
|
79
79
|
/**
|
|
80
|
-
* The messenger
|
|
80
|
+
* The messenger 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;
|
|
93
84
|
/**
|
|
94
85
|
* `SampleGasPricesController` fetches and persists gas prices for various chains.
|
|
95
86
|
*
|
|
@@ -97,36 +88,60 @@ export declare function getDefaultSampleGasPricesControllerState(): SampleGasPri
|
|
|
97
88
|
*
|
|
98
89
|
* ``` ts
|
|
99
90
|
* import { Messenger } from '@metamask/base-controller';
|
|
100
|
-
* import {
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* } from '@metamask/
|
|
91
|
+
* import type {
|
|
92
|
+
* NetworkControllerActions,
|
|
93
|
+
* NetworkControllerEvents,
|
|
94
|
+
* } from '@metamask/network-controller';
|
|
104
95
|
* import type {
|
|
105
96
|
* SampleGasPricesControllerActions,
|
|
106
|
-
* SampleGasPricesControllerEvents
|
|
107
|
-
*
|
|
108
|
-
*
|
|
97
|
+
* SampleGasPricesControllerEvents,
|
|
98
|
+
* SampleGasPricesServiceActions,
|
|
99
|
+
* SampleGasPricesServiceEvents,
|
|
100
|
+
* } from '@metamask/sample-controllers';
|
|
101
|
+
* import {
|
|
102
|
+
* SampleGasPricesController,
|
|
103
|
+
* SampleGasPricesService,
|
|
104
|
+
* selectGasPrices,
|
|
105
|
+
* } from '@metamask/sample-controllers';
|
|
109
106
|
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
107
|
+
* const globalMessenger = new Messenger<
|
|
108
|
+
* SampleGasPricesServiceActions
|
|
109
|
+
* | SampleGasPricesControllerActions
|
|
110
|
+
* | NetworkControllerActions,
|
|
111
|
+
* SampleGasPricesServiceEvents
|
|
112
|
+
* | SampleGasPricesControllerEvents
|
|
113
|
+
* | NetworkControllerEvents
|
|
115
114
|
* >();
|
|
116
|
-
* const
|
|
117
|
-
* name: '
|
|
118
|
-
* allowedActions: [
|
|
115
|
+
* const gasPricesServiceMessenger = globalMessenger.getRestricted({
|
|
116
|
+
* name: 'SampleGasPricesService',
|
|
117
|
+
* allowedActions: [],
|
|
119
118
|
* allowedEvents: [],
|
|
120
119
|
* });
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
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({
|
|
127
|
+
* name: 'SampleGasPricesController',
|
|
128
|
+
* allowedActions: ['NetworkController:getNetworkClientById'],
|
|
129
|
+
* allowedEvents: ['NetworkController:stateChange'],
|
|
130
|
+
* });
|
|
131
|
+
* // Instantiate the controller to register its actions on the messenger
|
|
132
|
+
* new SampleGasPricesController({
|
|
133
|
+
* messenger: gasPricesControllerMessenger,
|
|
124
134
|
* });
|
|
125
135
|
*
|
|
126
|
-
* //
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
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
|
|
130
145
|
* // => { '0x42': { low: 5, average: 10, high: 15, fetchedDate: '2024-01-02T00:00:00.000Z' } }
|
|
131
146
|
* ```
|
|
132
147
|
*/
|
|
@@ -135,23 +150,25 @@ export declare class SampleGasPricesController extends BaseController<typeof con
|
|
|
135
150
|
/**
|
|
136
151
|
* Constructs a new {@link SampleGasPricesController}.
|
|
137
152
|
*
|
|
138
|
-
* @param args - The arguments
|
|
153
|
+
* @param args - The constructor arguments.
|
|
139
154
|
* @param args.messenger - The messenger suited for this controller.
|
|
140
155
|
* @param args.state - The desired state with which to initialize this
|
|
141
156
|
* 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.
|
|
144
157
|
*/
|
|
145
|
-
constructor({ messenger, state,
|
|
158
|
+
constructor({ messenger, state, }: {
|
|
146
159
|
messenger: SampleGasPricesControllerMessenger;
|
|
147
160
|
state?: Partial<SampleGasPricesControllerState>;
|
|
148
|
-
gasPricesService: SampleAbstractGasPricesService;
|
|
149
161
|
});
|
|
150
162
|
/**
|
|
151
|
-
* Fetches the latest gas prices for the
|
|
163
|
+
* Fetches the latest gas prices for the given chain and persists them to
|
|
152
164
|
* state.
|
|
165
|
+
*
|
|
166
|
+
* @param args - The arguments to the function.
|
|
167
|
+
* @param args.chainId - The chain ID for which to fetch gas prices.
|
|
153
168
|
*/
|
|
154
|
-
updateGasPrices(
|
|
169
|
+
updateGasPrices({ chainId }: {
|
|
170
|
+
chainId: Hex;
|
|
171
|
+
}): Promise<void>;
|
|
155
172
|
}
|
|
156
173
|
export {};
|
|
157
174
|
//# 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,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EAAE
|
|
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,8 +1,9 @@
|
|
|
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";
|
|
3
4
|
import type { Hex } from "@metamask/utils";
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
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";
|
|
6
7
|
/**
|
|
7
8
|
* The name of the {@link SampleGasPricesController}, used to namespace the
|
|
8
9
|
* controller's actions and events and to namespace the controller's state data
|
|
@@ -35,61 +36,51 @@ type GasPrices = {
|
|
|
35
36
|
*/
|
|
36
37
|
export type SampleGasPricesControllerState = {
|
|
37
38
|
/**
|
|
38
|
-
*
|
|
39
|
-
* second.
|
|
39
|
+
* Fetched gas prices categorized by chain ID.
|
|
40
40
|
*/
|
|
41
41
|
gasPricesByChainId: {
|
|
42
42
|
[chainId: Hex]: GasPrices;
|
|
43
43
|
};
|
|
44
44
|
};
|
|
45
45
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
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.
|
|
48
52
|
*/
|
|
49
|
-
export
|
|
53
|
+
export declare function getDefaultSampleGasPricesControllerState(): SampleGasPricesControllerState;
|
|
50
54
|
/**
|
|
51
|
-
*
|
|
55
|
+
* Retrieves the state of the {@link SampleGasPricesController}.
|
|
52
56
|
*/
|
|
53
|
-
export type
|
|
54
|
-
type: `${typeof controllerName}:updateGasPrices`;
|
|
55
|
-
handler: SampleGasPricesController['updateGasPrices'];
|
|
56
|
-
};
|
|
57
|
+
export type SampleGasPricesControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SampleGasPricesControllerState>;
|
|
57
58
|
/**
|
|
58
|
-
*
|
|
59
|
-
* externally.
|
|
59
|
+
* Actions that {@link SampleGasPricesMessenger} exposes to other consumers.
|
|
60
60
|
*/
|
|
61
|
-
export type SampleGasPricesControllerActions = SampleGasPricesControllerGetStateAction |
|
|
61
|
+
export type SampleGasPricesControllerActions = SampleGasPricesControllerGetStateAction | SampleGasPricesControllerMethodActions;
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
63
|
+
* Actions from other messengers that {@link SampleGasPricesMessenger} calls.
|
|
64
64
|
*/
|
|
65
|
-
type AllowedActions =
|
|
65
|
+
type AllowedActions = NetworkControllerGetNetworkClientByIdAction | SampleGasPricesServiceFetchGasPricesAction;
|
|
66
66
|
/**
|
|
67
|
-
*
|
|
67
|
+
* Published when the state of {@link SampleGasPricesController} changes.
|
|
68
68
|
*/
|
|
69
69
|
export type SampleGasPricesControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SampleGasPricesControllerState>;
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
72
|
-
* externally.
|
|
71
|
+
* Events that {@link SampleGasPricesMessenger} exposes to other consumers.
|
|
73
72
|
*/
|
|
74
73
|
export type SampleGasPricesControllerEvents = SampleGasPricesControllerStateChangeEvent;
|
|
75
74
|
/**
|
|
76
|
-
*
|
|
75
|
+
* Events from other messengers that {@link SampleGasPricesMessenger} subscribes
|
|
76
|
+
* to.
|
|
77
77
|
*/
|
|
78
|
-
type AllowedEvents =
|
|
78
|
+
type AllowedEvents = NetworkControllerStateChangeEvent;
|
|
79
79
|
/**
|
|
80
|
-
* The messenger
|
|
80
|
+
* The messenger 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;
|
|
93
84
|
/**
|
|
94
85
|
* `SampleGasPricesController` fetches and persists gas prices for various chains.
|
|
95
86
|
*
|
|
@@ -97,36 +88,60 @@ export declare function getDefaultSampleGasPricesControllerState(): SampleGasPri
|
|
|
97
88
|
*
|
|
98
89
|
* ``` ts
|
|
99
90
|
* import { Messenger } from '@metamask/base-controller';
|
|
100
|
-
* import {
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* } from '@metamask/
|
|
91
|
+
* import type {
|
|
92
|
+
* NetworkControllerActions,
|
|
93
|
+
* NetworkControllerEvents,
|
|
94
|
+
* } from '@metamask/network-controller';
|
|
104
95
|
* import type {
|
|
105
96
|
* SampleGasPricesControllerActions,
|
|
106
|
-
* SampleGasPricesControllerEvents
|
|
107
|
-
*
|
|
108
|
-
*
|
|
97
|
+
* SampleGasPricesControllerEvents,
|
|
98
|
+
* SampleGasPricesServiceActions,
|
|
99
|
+
* SampleGasPricesServiceEvents,
|
|
100
|
+
* } from '@metamask/sample-controllers';
|
|
101
|
+
* import {
|
|
102
|
+
* SampleGasPricesController,
|
|
103
|
+
* SampleGasPricesService,
|
|
104
|
+
* selectGasPrices,
|
|
105
|
+
* } from '@metamask/sample-controllers';
|
|
109
106
|
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
107
|
+
* const globalMessenger = new Messenger<
|
|
108
|
+
* SampleGasPricesServiceActions
|
|
109
|
+
* | SampleGasPricesControllerActions
|
|
110
|
+
* | NetworkControllerActions,
|
|
111
|
+
* SampleGasPricesServiceEvents
|
|
112
|
+
* | SampleGasPricesControllerEvents
|
|
113
|
+
* | NetworkControllerEvents
|
|
115
114
|
* >();
|
|
116
|
-
* const
|
|
117
|
-
* name: '
|
|
118
|
-
* allowedActions: [
|
|
115
|
+
* const gasPricesServiceMessenger = globalMessenger.getRestricted({
|
|
116
|
+
* name: 'SampleGasPricesService',
|
|
117
|
+
* allowedActions: [],
|
|
119
118
|
* allowedEvents: [],
|
|
120
119
|
* });
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
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({
|
|
127
|
+
* name: 'SampleGasPricesController',
|
|
128
|
+
* allowedActions: ['NetworkController:getNetworkClientById'],
|
|
129
|
+
* allowedEvents: ['NetworkController:stateChange'],
|
|
130
|
+
* });
|
|
131
|
+
* // Instantiate the controller to register its actions on the messenger
|
|
132
|
+
* new SampleGasPricesController({
|
|
133
|
+
* messenger: gasPricesControllerMessenger,
|
|
124
134
|
* });
|
|
125
135
|
*
|
|
126
|
-
* //
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
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
|
|
130
145
|
* // => { '0x42': { low: 5, average: 10, high: 15, fetchedDate: '2024-01-02T00:00:00.000Z' } }
|
|
131
146
|
* ```
|
|
132
147
|
*/
|
|
@@ -135,23 +150,25 @@ export declare class SampleGasPricesController extends BaseController<typeof con
|
|
|
135
150
|
/**
|
|
136
151
|
* Constructs a new {@link SampleGasPricesController}.
|
|
137
152
|
*
|
|
138
|
-
* @param args - The arguments
|
|
153
|
+
* @param args - The constructor arguments.
|
|
139
154
|
* @param args.messenger - The messenger suited for this controller.
|
|
140
155
|
* @param args.state - The desired state with which to initialize this
|
|
141
156
|
* 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.
|
|
144
157
|
*/
|
|
145
|
-
constructor({ messenger, state,
|
|
158
|
+
constructor({ messenger, state, }: {
|
|
146
159
|
messenger: SampleGasPricesControllerMessenger;
|
|
147
160
|
state?: Partial<SampleGasPricesControllerState>;
|
|
148
|
-
gasPricesService: SampleAbstractGasPricesService;
|
|
149
161
|
});
|
|
150
162
|
/**
|
|
151
|
-
* Fetches the latest gas prices for the
|
|
163
|
+
* Fetches the latest gas prices for the given chain and persists them to
|
|
152
164
|
* state.
|
|
165
|
+
*
|
|
166
|
+
* @param args - The arguments to the function.
|
|
167
|
+
* @param args.chainId - The chain ID for which to fetch gas prices.
|
|
153
168
|
*/
|
|
154
|
-
updateGasPrices(
|
|
169
|
+
updateGasPrices({ chainId }: {
|
|
170
|
+
chainId: Hex;
|
|
171
|
+
}): Promise<void>;
|
|
155
172
|
}
|
|
156
173
|
export {};
|
|
157
174
|
//# 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,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EAAE
|
|
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;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,15 +1,15 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, 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
|
+
};
|
|
1
6
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
7
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
8
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
9
|
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");
|
|
5
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
11
|
};
|
|
7
|
-
var
|
|
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;
|
|
12
|
+
var _SampleGasPricesController_instances, _SampleGasPricesController_selectedChainId, _SampleGasPricesController_onSelectedNetworkClientIdChange;
|
|
13
13
|
import { BaseController } from "@metamask/base-controller";
|
|
14
14
|
// === GENERAL ===
|
|
15
15
|
/**
|
|
@@ -23,8 +23,10 @@ export const controllerName = 'SampleGasPricesController';
|
|
|
23
23
|
*/
|
|
24
24
|
const gasPricesControllerMetadata = {
|
|
25
25
|
gasPricesByChainId: {
|
|
26
|
+
includeInStateLogs: true,
|
|
26
27
|
persist: true,
|
|
27
28
|
anonymous: false,
|
|
29
|
+
usedInUi: true,
|
|
28
30
|
},
|
|
29
31
|
};
|
|
30
32
|
/**
|
|
@@ -40,6 +42,8 @@ export function getDefaultSampleGasPricesControllerState() {
|
|
|
40
42
|
gasPricesByChainId: {},
|
|
41
43
|
};
|
|
42
44
|
}
|
|
45
|
+
// === MESSENGER ===
|
|
46
|
+
const MESSENGER_EXPOSED_METHODS = ['updateGasPrices'];
|
|
43
47
|
// === CONTROLLER DEFINITION ===
|
|
44
48
|
/**
|
|
45
49
|
* `SampleGasPricesController` fetches and persists gas prices for various chains.
|
|
@@ -48,36 +52,60 @@ export function getDefaultSampleGasPricesControllerState() {
|
|
|
48
52
|
*
|
|
49
53
|
* ``` ts
|
|
50
54
|
* import { Messenger } from '@metamask/base-controller';
|
|
51
|
-
* import {
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* } from '@metamask/
|
|
55
|
+
* import type {
|
|
56
|
+
* NetworkControllerActions,
|
|
57
|
+
* NetworkControllerEvents,
|
|
58
|
+
* } from '@metamask/network-controller';
|
|
55
59
|
* import type {
|
|
56
60
|
* SampleGasPricesControllerActions,
|
|
57
|
-
* SampleGasPricesControllerEvents
|
|
58
|
-
*
|
|
59
|
-
*
|
|
61
|
+
* SampleGasPricesControllerEvents,
|
|
62
|
+
* SampleGasPricesServiceActions,
|
|
63
|
+
* SampleGasPricesServiceEvents,
|
|
64
|
+
* } from '@metamask/sample-controllers';
|
|
65
|
+
* import {
|
|
66
|
+
* SampleGasPricesController,
|
|
67
|
+
* SampleGasPricesService,
|
|
68
|
+
* selectGasPrices,
|
|
69
|
+
* } from '@metamask/sample-controllers';
|
|
60
70
|
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
71
|
+
* const globalMessenger = new Messenger<
|
|
72
|
+
* SampleGasPricesServiceActions
|
|
73
|
+
* | SampleGasPricesControllerActions
|
|
74
|
+
* | NetworkControllerActions,
|
|
75
|
+
* SampleGasPricesServiceEvents
|
|
76
|
+
* | SampleGasPricesControllerEvents
|
|
77
|
+
* | NetworkControllerEvents
|
|
66
78
|
* >();
|
|
67
|
-
* const
|
|
68
|
-
* name: '
|
|
69
|
-
* allowedActions: [
|
|
79
|
+
* const gasPricesServiceMessenger = globalMessenger.getRestricted({
|
|
80
|
+
* name: 'SampleGasPricesService',
|
|
81
|
+
* allowedActions: [],
|
|
70
82
|
* allowedEvents: [],
|
|
71
83
|
* });
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
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,
|
|
75
98
|
* });
|
|
76
99
|
*
|
|
77
|
-
* //
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
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
|
|
81
109
|
* // => { '0x42': { low: 5, average: 10, high: 15, fetchedDate: '2024-01-02T00:00:00.000Z' } }
|
|
82
110
|
* ```
|
|
83
111
|
*/
|
|
@@ -85,14 +113,12 @@ export class SampleGasPricesController extends BaseController {
|
|
|
85
113
|
/**
|
|
86
114
|
* Constructs a new {@link SampleGasPricesController}.
|
|
87
115
|
*
|
|
88
|
-
* @param args - The arguments
|
|
116
|
+
* @param args - The constructor arguments.
|
|
89
117
|
* @param args.messenger - The messenger suited for this controller.
|
|
90
118
|
* @param args.state - The desired state with which to initialize this
|
|
91
119
|
* 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.
|
|
94
120
|
*/
|
|
95
|
-
constructor({ messenger, state,
|
|
121
|
+
constructor({ messenger, state, }) {
|
|
96
122
|
super({
|
|
97
123
|
messenger,
|
|
98
124
|
metadata: gasPricesControllerMetadata,
|
|
@@ -102,20 +128,23 @@ export class SampleGasPricesController extends BaseController {
|
|
|
102
128
|
...state,
|
|
103
129
|
},
|
|
104
130
|
});
|
|
131
|
+
_SampleGasPricesController_instances.add(this);
|
|
105
132
|
/**
|
|
106
|
-
* The
|
|
133
|
+
* The globally selected chain ID.
|
|
107
134
|
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
this.messagingSystem.
|
|
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);
|
|
111
138
|
}
|
|
112
139
|
/**
|
|
113
|
-
* Fetches the latest gas prices for the
|
|
140
|
+
* Fetches the latest gas prices for the given chain and persists them to
|
|
114
141
|
* state.
|
|
142
|
+
*
|
|
143
|
+
* @param args - The arguments to the function.
|
|
144
|
+
* @param args.chainId - The chain ID for which to fetch gas prices.
|
|
115
145
|
*/
|
|
116
|
-
async updateGasPrices() {
|
|
117
|
-
const
|
|
118
|
-
const gasPricesResponse = await __classPrivateFieldGet(this, _SampleGasPricesController_gasPricesService, "f").fetchGasPrices(chainId);
|
|
146
|
+
async updateGasPrices({ chainId }) {
|
|
147
|
+
const gasPricesResponse = await this.messagingSystem.call('SampleGasPricesService:fetchGasPrices', chainId);
|
|
119
148
|
this.update((state) => {
|
|
120
149
|
state.gasPricesByChainId[chainId] = {
|
|
121
150
|
...gasPricesResponse,
|
|
@@ -124,5 +153,18 @@ export class SampleGasPricesController extends BaseController {
|
|
|
124
153
|
});
|
|
125
154
|
}
|
|
126
155
|
}
|
|
127
|
-
|
|
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
|
+
};
|
|
128
170
|
//# sourceMappingURL=sample-gas-prices-controller.mjs.map
|