@metamask-previews/sample-controllers 1.0.0-preview-aa8c4291 → 1.0.0-preview-e821953
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 +23 -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 +77 -39
- package/dist/sample-gas-prices-controller.cjs.map +1 -1
- package/dist/sample-gas-prices-controller.d.cts +74 -59
- package/dist/sample-gas-prices-controller.d.cts.map +1 -1
- package/dist/sample-gas-prices-controller.d.mts +74 -59
- package/dist/sample-gas-prices-controller.d.mts.map +1 -1
- package/dist/sample-gas-prices-controller.mjs +77 -39
- 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 +135 -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 +122 -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 +122 -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 +134 -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 +24 -13
- package/dist/sample-petnames-controller.cjs.map +1 -1
- package/dist/sample-petnames-controller.d.cts +38 -23
- package/dist/sample-petnames-controller.d.cts.map +1 -1
- package/dist/sample-petnames-controller.d.mts +38 -23
- package/dist/sample-petnames-controller.d.mts.map +1 -1
- package/dist/sample-petnames-controller.mjs +23 -13
- package/dist/sample-petnames-controller.mjs.map +1 -1
- package/package.json +2 -1
- 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,58 @@ 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
97
|
* SampleGasPricesControllerEvents
|
|
107
98
|
* } from '@metamask/example-controllers';
|
|
108
|
-
* import
|
|
99
|
+
* import {
|
|
100
|
+
* SampleGasPricesController,
|
|
101
|
+
* SampleGasPricesService,
|
|
102
|
+
* selectGasPrices,
|
|
103
|
+
* } from '@metamask/example-controllers';
|
|
109
104
|
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
105
|
+
* const globalMessenger = new Messenger<
|
|
106
|
+
* SampleGasPricesServiceActions
|
|
107
|
+
* | SampleGasPricesControllerActions
|
|
108
|
+
* | NetworkControllerActions
|
|
109
|
+
* SampleGasPricesServiceEvents
|
|
110
|
+
* | SampleGasPricesControllerEvents
|
|
111
|
+
* | NetworkControllerEvents
|
|
115
112
|
* >();
|
|
116
|
-
* const
|
|
117
|
-
* name: '
|
|
118
|
-
* allowedActions: [
|
|
113
|
+
* const gasPricesServiceMessenger = globalMessenger.getRestricted({
|
|
114
|
+
* name: 'SampleGasPricesService',
|
|
115
|
+
* allowedActions: [],
|
|
119
116
|
* allowedEvents: [],
|
|
120
117
|
* });
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
118
|
+
* // Instantiate the service to register its actions on the messenger
|
|
119
|
+
* new SampleGasPricesService({
|
|
120
|
+
* messenger: gasPricesServiceMessenger,
|
|
121
|
+
* // We assume you're using this in the browser.
|
|
122
|
+
* fetch,
|
|
123
|
+
* });
|
|
124
|
+
* const gasPricesControllerMessenger = globalMessenger.getRestricted({
|
|
125
|
+
* name: 'SampleGasPricesController',
|
|
126
|
+
* allowedActions: ['NetworkController:getNetworkClientById'],
|
|
127
|
+
* allowedEvents: ['NetworkController:stateChange'],
|
|
128
|
+
* });
|
|
129
|
+
* // Instantiate the controller to register its actions on the messenger
|
|
130
|
+
* new SampleGasPricesController({
|
|
131
|
+
* messenger: gasPricesControllerMessenger,
|
|
124
132
|
* });
|
|
125
133
|
*
|
|
126
|
-
* //
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
134
|
+
* // Later...
|
|
135
|
+
* await globalMessenger.call(
|
|
136
|
+
* 'SampleGasPricesController:updateGasPrices',
|
|
137
|
+
* { chainId: '0x42' },
|
|
138
|
+
* );
|
|
139
|
+
* const gasPricesControllerState = await globalMessenger.call(
|
|
140
|
+
* 'SampleGasPricesController:getState',
|
|
141
|
+
* );
|
|
142
|
+
* gasPricesControllerState.gasPricesByChainId
|
|
130
143
|
* // => { '0x42': { low: 5, average: 10, high: 15, fetchedDate: '2024-01-02T00:00:00.000Z' } }
|
|
131
144
|
* ```
|
|
132
145
|
*/
|
|
@@ -135,23 +148,25 @@ export declare class SampleGasPricesController extends BaseController<typeof con
|
|
|
135
148
|
/**
|
|
136
149
|
* Constructs a new {@link SampleGasPricesController}.
|
|
137
150
|
*
|
|
138
|
-
* @param args - The arguments
|
|
151
|
+
* @param args - The constructor arguments.
|
|
139
152
|
* @param args.messenger - The messenger suited for this controller.
|
|
140
153
|
* @param args.state - The desired state with which to initialize this
|
|
141
154
|
* 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
155
|
*/
|
|
145
|
-
constructor({ messenger, state,
|
|
156
|
+
constructor({ messenger, state, }: {
|
|
146
157
|
messenger: SampleGasPricesControllerMessenger;
|
|
147
158
|
state?: Partial<SampleGasPricesControllerState>;
|
|
148
|
-
gasPricesService: SampleAbstractGasPricesService;
|
|
149
159
|
});
|
|
150
160
|
/**
|
|
151
|
-
* Fetches the latest gas prices for the
|
|
161
|
+
* Fetches the latest gas prices for the given chain and persists them to
|
|
152
162
|
* state.
|
|
163
|
+
*
|
|
164
|
+
* @param args - The arguments to the function.
|
|
165
|
+
* @param args.chainId - The chain ID for which to fetch gas prices.
|
|
153
166
|
*/
|
|
154
|
-
updateGasPrices(
|
|
167
|
+
updateGasPrices({ chainId }: {
|
|
168
|
+
chainId: Hex;
|
|
169
|
+
}): Promise<void>;
|
|
155
170
|
}
|
|
156
171
|
export {};
|
|
157
172
|
//# 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;AAYF;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;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,58 @@ 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
97
|
* SampleGasPricesControllerEvents
|
|
107
98
|
* } from '@metamask/example-controllers';
|
|
108
|
-
* import
|
|
99
|
+
* import {
|
|
100
|
+
* SampleGasPricesController,
|
|
101
|
+
* SampleGasPricesService,
|
|
102
|
+
* selectGasPrices,
|
|
103
|
+
* } from '@metamask/example-controllers';
|
|
109
104
|
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
105
|
+
* const globalMessenger = new Messenger<
|
|
106
|
+
* SampleGasPricesServiceActions
|
|
107
|
+
* | SampleGasPricesControllerActions
|
|
108
|
+
* | NetworkControllerActions
|
|
109
|
+
* SampleGasPricesServiceEvents
|
|
110
|
+
* | SampleGasPricesControllerEvents
|
|
111
|
+
* | NetworkControllerEvents
|
|
115
112
|
* >();
|
|
116
|
-
* const
|
|
117
|
-
* name: '
|
|
118
|
-
* allowedActions: [
|
|
113
|
+
* const gasPricesServiceMessenger = globalMessenger.getRestricted({
|
|
114
|
+
* name: 'SampleGasPricesService',
|
|
115
|
+
* allowedActions: [],
|
|
119
116
|
* allowedEvents: [],
|
|
120
117
|
* });
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
118
|
+
* // Instantiate the service to register its actions on the messenger
|
|
119
|
+
* new SampleGasPricesService({
|
|
120
|
+
* messenger: gasPricesServiceMessenger,
|
|
121
|
+
* // We assume you're using this in the browser.
|
|
122
|
+
* fetch,
|
|
123
|
+
* });
|
|
124
|
+
* const gasPricesControllerMessenger = globalMessenger.getRestricted({
|
|
125
|
+
* name: 'SampleGasPricesController',
|
|
126
|
+
* allowedActions: ['NetworkController:getNetworkClientById'],
|
|
127
|
+
* allowedEvents: ['NetworkController:stateChange'],
|
|
128
|
+
* });
|
|
129
|
+
* // Instantiate the controller to register its actions on the messenger
|
|
130
|
+
* new SampleGasPricesController({
|
|
131
|
+
* messenger: gasPricesControllerMessenger,
|
|
124
132
|
* });
|
|
125
133
|
*
|
|
126
|
-
* //
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
134
|
+
* // Later...
|
|
135
|
+
* await globalMessenger.call(
|
|
136
|
+
* 'SampleGasPricesController:updateGasPrices',
|
|
137
|
+
* { chainId: '0x42' },
|
|
138
|
+
* );
|
|
139
|
+
* const gasPricesControllerState = await globalMessenger.call(
|
|
140
|
+
* 'SampleGasPricesController:getState',
|
|
141
|
+
* );
|
|
142
|
+
* gasPricesControllerState.gasPricesByChainId
|
|
130
143
|
* // => { '0x42': { low: 5, average: 10, high: 15, fetchedDate: '2024-01-02T00:00:00.000Z' } }
|
|
131
144
|
* ```
|
|
132
145
|
*/
|
|
@@ -135,23 +148,25 @@ export declare class SampleGasPricesController extends BaseController<typeof con
|
|
|
135
148
|
/**
|
|
136
149
|
* Constructs a new {@link SampleGasPricesController}.
|
|
137
150
|
*
|
|
138
|
-
* @param args - The arguments
|
|
151
|
+
* @param args - The constructor arguments.
|
|
139
152
|
* @param args.messenger - The messenger suited for this controller.
|
|
140
153
|
* @param args.state - The desired state with which to initialize this
|
|
141
154
|
* 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
155
|
*/
|
|
145
|
-
constructor({ messenger, state,
|
|
156
|
+
constructor({ messenger, state, }: {
|
|
146
157
|
messenger: SampleGasPricesControllerMessenger;
|
|
147
158
|
state?: Partial<SampleGasPricesControllerState>;
|
|
148
|
-
gasPricesService: SampleAbstractGasPricesService;
|
|
149
159
|
});
|
|
150
160
|
/**
|
|
151
|
-
* Fetches the latest gas prices for the
|
|
161
|
+
* Fetches the latest gas prices for the given chain and persists them to
|
|
152
162
|
* state.
|
|
163
|
+
*
|
|
164
|
+
* @param args - The arguments to the function.
|
|
165
|
+
* @param args.chainId - The chain ID for which to fetch gas prices.
|
|
153
166
|
*/
|
|
154
|
-
updateGasPrices(
|
|
167
|
+
updateGasPrices({ chainId }: {
|
|
168
|
+
chainId: Hex;
|
|
169
|
+
}): Promise<void>;
|
|
155
170
|
}
|
|
156
171
|
export {};
|
|
157
172
|
//# 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;AAYF;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;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
|
/**
|
|
@@ -40,6 +40,8 @@ export function getDefaultSampleGasPricesControllerState() {
|
|
|
40
40
|
gasPricesByChainId: {},
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
+
// === MESSENGER ===
|
|
44
|
+
const MESSENGER_EXPOSED_METHODS = ['updateGasPrices'];
|
|
43
45
|
// === CONTROLLER DEFINITION ===
|
|
44
46
|
/**
|
|
45
47
|
* `SampleGasPricesController` fetches and persists gas prices for various chains.
|
|
@@ -48,36 +50,58 @@ export function getDefaultSampleGasPricesControllerState() {
|
|
|
48
50
|
*
|
|
49
51
|
* ``` ts
|
|
50
52
|
* import { Messenger } from '@metamask/base-controller';
|
|
51
|
-
* import {
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* } from '@metamask/
|
|
53
|
+
* import type {
|
|
54
|
+
* NetworkControllerActions,
|
|
55
|
+
* NetworkControllerEvents
|
|
56
|
+
* } from '@metamask/network-controller';
|
|
55
57
|
* import type {
|
|
56
58
|
* SampleGasPricesControllerActions,
|
|
57
59
|
* SampleGasPricesControllerEvents
|
|
58
60
|
* } from '@metamask/example-controllers';
|
|
59
|
-
* import
|
|
61
|
+
* import {
|
|
62
|
+
* SampleGasPricesController,
|
|
63
|
+
* SampleGasPricesService,
|
|
64
|
+
* selectGasPrices,
|
|
65
|
+
* } from '@metamask/example-controllers';
|
|
60
66
|
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
67
|
+
* const globalMessenger = new Messenger<
|
|
68
|
+
* SampleGasPricesServiceActions
|
|
69
|
+
* | SampleGasPricesControllerActions
|
|
70
|
+
* | NetworkControllerActions
|
|
71
|
+
* SampleGasPricesServiceEvents
|
|
72
|
+
* | SampleGasPricesControllerEvents
|
|
73
|
+
* | NetworkControllerEvents
|
|
66
74
|
* >();
|
|
67
|
-
* const
|
|
68
|
-
* name: '
|
|
69
|
-
* allowedActions: [
|
|
75
|
+
* const gasPricesServiceMessenger = globalMessenger.getRestricted({
|
|
76
|
+
* name: 'SampleGasPricesService',
|
|
77
|
+
* allowedActions: [],
|
|
70
78
|
* allowedEvents: [],
|
|
71
79
|
* });
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
80
|
+
* // Instantiate the service to register its actions on the messenger
|
|
81
|
+
* new SampleGasPricesService({
|
|
82
|
+
* messenger: gasPricesServiceMessenger,
|
|
83
|
+
* // We assume you're using this in the browser.
|
|
84
|
+
* fetch,
|
|
85
|
+
* });
|
|
86
|
+
* const gasPricesControllerMessenger = globalMessenger.getRestricted({
|
|
87
|
+
* name: 'SampleGasPricesController',
|
|
88
|
+
* allowedActions: ['NetworkController:getNetworkClientById'],
|
|
89
|
+
* allowedEvents: ['NetworkController:stateChange'],
|
|
90
|
+
* });
|
|
91
|
+
* // Instantiate the controller to register its actions on the messenger
|
|
92
|
+
* new SampleGasPricesController({
|
|
93
|
+
* messenger: gasPricesControllerMessenger,
|
|
75
94
|
* });
|
|
76
95
|
*
|
|
77
|
-
* //
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
96
|
+
* // Later...
|
|
97
|
+
* await globalMessenger.call(
|
|
98
|
+
* 'SampleGasPricesController:updateGasPrices',
|
|
99
|
+
* { chainId: '0x42' },
|
|
100
|
+
* );
|
|
101
|
+
* const gasPricesControllerState = await globalMessenger.call(
|
|
102
|
+
* 'SampleGasPricesController:getState',
|
|
103
|
+
* );
|
|
104
|
+
* gasPricesControllerState.gasPricesByChainId
|
|
81
105
|
* // => { '0x42': { low: 5, average: 10, high: 15, fetchedDate: '2024-01-02T00:00:00.000Z' } }
|
|
82
106
|
* ```
|
|
83
107
|
*/
|
|
@@ -85,14 +109,12 @@ export class SampleGasPricesController extends BaseController {
|
|
|
85
109
|
/**
|
|
86
110
|
* Constructs a new {@link SampleGasPricesController}.
|
|
87
111
|
*
|
|
88
|
-
* @param args - The arguments
|
|
112
|
+
* @param args - The constructor arguments.
|
|
89
113
|
* @param args.messenger - The messenger suited for this controller.
|
|
90
114
|
* @param args.state - The desired state with which to initialize this
|
|
91
115
|
* 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
116
|
*/
|
|
95
|
-
constructor({ messenger, state,
|
|
117
|
+
constructor({ messenger, state, }) {
|
|
96
118
|
super({
|
|
97
119
|
messenger,
|
|
98
120
|
metadata: gasPricesControllerMetadata,
|
|
@@ -102,20 +124,23 @@ export class SampleGasPricesController extends BaseController {
|
|
|
102
124
|
...state,
|
|
103
125
|
},
|
|
104
126
|
});
|
|
127
|
+
_SampleGasPricesController_instances.add(this);
|
|
105
128
|
/**
|
|
106
|
-
* The
|
|
129
|
+
* The globally selected chain ID.
|
|
107
130
|
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
this.messagingSystem.
|
|
131
|
+
_SampleGasPricesController_selectedChainId.set(this, void 0);
|
|
132
|
+
this.messagingSystem.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
133
|
+
this.messagingSystem.subscribe('NetworkController:stateChange', __classPrivateFieldGet(this, _SampleGasPricesController_instances, "m", _SampleGasPricesController_onSelectedNetworkClientIdChange).bind(this), (networkControllerState) => networkControllerState.selectedNetworkClientId);
|
|
111
134
|
}
|
|
112
135
|
/**
|
|
113
|
-
* Fetches the latest gas prices for the
|
|
136
|
+
* Fetches the latest gas prices for the given chain and persists them to
|
|
114
137
|
* state.
|
|
138
|
+
*
|
|
139
|
+
* @param args - The arguments to the function.
|
|
140
|
+
* @param args.chainId - The chain ID for which to fetch gas prices.
|
|
115
141
|
*/
|
|
116
|
-
async updateGasPrices() {
|
|
117
|
-
const
|
|
118
|
-
const gasPricesResponse = await __classPrivateFieldGet(this, _SampleGasPricesController_gasPricesService, "f").fetchGasPrices(chainId);
|
|
142
|
+
async updateGasPrices({ chainId }) {
|
|
143
|
+
const gasPricesResponse = await this.messagingSystem.call('SampleGasPricesService:fetchGasPrices', chainId);
|
|
119
144
|
this.update((state) => {
|
|
120
145
|
state.gasPricesByChainId[chainId] = {
|
|
121
146
|
...gasPricesResponse,
|
|
@@ -124,5 +149,18 @@ export class SampleGasPricesController extends BaseController {
|
|
|
124
149
|
});
|
|
125
150
|
}
|
|
126
151
|
}
|
|
127
|
-
|
|
152
|
+
_SampleGasPricesController_selectedChainId = new WeakMap(), _SampleGasPricesController_instances = new WeakSet(), _SampleGasPricesController_onSelectedNetworkClientIdChange =
|
|
153
|
+
/**
|
|
154
|
+
* Callback to call when the globally selected network client ID changes,
|
|
155
|
+
* ensuring that gas prices get updated.
|
|
156
|
+
*
|
|
157
|
+
* @param selectedNetworkClientId - The globally selected network client ID.
|
|
158
|
+
*/
|
|
159
|
+
async function _SampleGasPricesController_onSelectedNetworkClientIdChange(selectedNetworkClientId) {
|
|
160
|
+
const { configuration: { chainId }, } = this.messagingSystem.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
|
|
161
|
+
if (chainId !== __classPrivateFieldGet(this, _SampleGasPricesController_selectedChainId, "f")) {
|
|
162
|
+
__classPrivateFieldSet(this, _SampleGasPricesController_selectedChainId, chainId, "f");
|
|
163
|
+
await this.updateGasPrices({ chainId });
|
|
164
|
+
}
|
|
165
|
+
};
|
|
128
166
|
//# sourceMappingURL=sample-gas-prices-controller.mjs.map
|