@metamask-previews/sample-controllers 0.0.0-preview-37b05a4 → 0.0.0-preview-2084c06c
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/dist/index.cjs +11 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +4 -0
- package/dist/index.mjs.map +1 -0
- package/dist/network-controller-types.cjs.map +1 -0
- package/dist/network-controller-types.d.cts.map +1 -0
- package/dist/network-controller-types.d.mts.map +1 -0
- package/dist/network-controller-types.mjs.map +1 -0
- package/dist/{types/gas-prices-controller.cjs → sample-gas-prices-controller.cjs} +28 -28
- package/dist/sample-gas-prices-controller.cjs.map +1 -0
- package/dist/{types/gas-prices-controller.d.cts → sample-gas-prices-controller.d.cts} +38 -38
- package/dist/sample-gas-prices-controller.d.cts.map +1 -0
- package/dist/{types/gas-prices-controller.d.mts → sample-gas-prices-controller.d.mts} +38 -38
- package/dist/sample-gas-prices-controller.d.mts.map +1 -0
- package/dist/{types/gas-prices-controller.mjs → sample-gas-prices-controller.mjs} +25 -25
- package/dist/sample-gas-prices-controller.mjs.map +1 -0
- package/dist/sample-gas-prices-service/index.cjs +6 -0
- package/dist/sample-gas-prices-service/index.cjs.map +1 -0
- package/dist/sample-gas-prices-service/index.d.cts +3 -0
- package/dist/sample-gas-prices-service/index.d.cts.map +1 -0
- package/dist/sample-gas-prices-service/index.d.mts +3 -0
- package/dist/sample-gas-prices-service/index.d.mts.map +1 -0
- package/dist/sample-gas-prices-service/index.mjs +2 -0
- package/dist/sample-gas-prices-service/index.mjs.map +1 -0
- package/dist/{types/gas-prices-service/abstract-gas-prices-service.cjs → sample-gas-prices-service/sample-abstract-gas-prices-service.cjs} +1 -1
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.cjs.map +1 -0
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.cts +7 -0
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.cts.map +1 -0
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.mts +7 -0
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.mts.map +1 -0
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.mjs +2 -0
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.mjs.map +1 -0
- package/dist/{types/gas-prices-service/gas-prices-service.cjs → sample-gas-prices-service/sample-gas-prices-service.cjs} +14 -14
- package/dist/sample-gas-prices-service/sample-gas-prices-service.cjs.map +1 -0
- package/dist/{types/gas-prices-service/gas-prices-service.d.mts → sample-gas-prices-service/sample-gas-prices-service.d.cts} +7 -7
- package/dist/sample-gas-prices-service/sample-gas-prices-service.d.cts.map +1 -0
- package/dist/{types/gas-prices-service/gas-prices-service.d.cts → sample-gas-prices-service/sample-gas-prices-service.d.mts} +7 -7
- package/dist/sample-gas-prices-service/sample-gas-prices-service.d.mts.map +1 -0
- package/dist/{types/gas-prices-service/gas-prices-service.mjs → sample-gas-prices-service/sample-gas-prices-service.mjs} +12 -12
- package/dist/sample-gas-prices-service/sample-gas-prices-service.mjs.map +1 -0
- package/dist/{types/pet-names-controller.cjs → sample-petnames-controller.cjs} +26 -27
- package/dist/sample-petnames-controller.cjs.map +1 -0
- package/dist/sample-petnames-controller.d.cts +115 -0
- package/dist/sample-petnames-controller.d.cts.map +1 -0
- package/dist/sample-petnames-controller.d.mts +115 -0
- package/dist/sample-petnames-controller.d.mts.map +1 -0
- package/dist/{types/pet-names-controller.mjs → sample-petnames-controller.mjs} +24 -24
- package/dist/sample-petnames-controller.mjs.map +1 -0
- package/package.json +6 -2
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types/gas-prices-controller.cjs.map +0 -1
- package/dist/types/gas-prices-controller.d.cts.map +0 -1
- package/dist/types/gas-prices-controller.d.mts.map +0 -1
- package/dist/types/gas-prices-controller.mjs.map +0 -1
- package/dist/types/gas-prices-service/abstract-gas-prices-service.cjs.map +0 -1
- package/dist/types/gas-prices-service/abstract-gas-prices-service.d.cts +0 -7
- package/dist/types/gas-prices-service/abstract-gas-prices-service.d.cts.map +0 -1
- package/dist/types/gas-prices-service/abstract-gas-prices-service.d.mts +0 -7
- package/dist/types/gas-prices-service/abstract-gas-prices-service.d.mts.map +0 -1
- package/dist/types/gas-prices-service/abstract-gas-prices-service.mjs +0 -2
- package/dist/types/gas-prices-service/abstract-gas-prices-service.mjs.map +0 -1
- package/dist/types/gas-prices-service/gas-prices-service.cjs.map +0 -1
- package/dist/types/gas-prices-service/gas-prices-service.d.cts.map +0 -1
- package/dist/types/gas-prices-service/gas-prices-service.d.mts.map +0 -1
- package/dist/types/gas-prices-service/gas-prices-service.mjs.map +0 -1
- package/dist/types/index.cjs +0 -12
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.d.cts +0 -6
- package/dist/types/index.d.cts.map +0 -1
- package/dist/types/index.d.mts +0 -6
- package/dist/types/index.d.mts.map +0 -1
- package/dist/types/index.mjs +0 -4
- package/dist/types/index.mjs.map +0 -1
- package/dist/types/network-controller-types.cjs.map +0 -1
- package/dist/types/network-controller-types.d.cts.map +0 -1
- package/dist/types/network-controller-types.d.mts.map +0 -1
- package/dist/types/network-controller-types.mjs.map +0 -1
- package/dist/types/pet-names-controller.cjs.map +0 -1
- package/dist/types/pet-names-controller.d.cts +0 -124
- package/dist/types/pet-names-controller.d.cts.map +0 -1
- package/dist/types/pet-names-controller.d.mts +0 -124
- package/dist/types/pet-names-controller.d.mts.map +0 -1
- package/dist/types/pet-names-controller.mjs.map +0 -1
- /package/dist/{types/network-controller-types.cjs → network-controller-types.cjs} +0 -0
- /package/dist/{types/network-controller-types.d.cts → network-controller-types.d.cts} +0 -0
- /package/dist/{types/network-controller-types.d.mts → network-controller-types.d.mts} +0 -0
- /package/dist/{types/network-controller-types.mjs → network-controller-types.mjs} +0 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SampleGasPricesService = exports.SamplePetnamesController = exports.SampleGasPricesController = exports.getDefaultSampleGasPricesControllerState = void 0;
|
|
4
|
+
var sample_gas_prices_controller_1 = require("./sample-gas-prices-controller.cjs");
|
|
5
|
+
Object.defineProperty(exports, "getDefaultSampleGasPricesControllerState", { enumerable: true, get: function () { return sample_gas_prices_controller_1.getDefaultSampleGasPricesControllerState; } });
|
|
6
|
+
Object.defineProperty(exports, "SampleGasPricesController", { enumerable: true, get: function () { return sample_gas_prices_controller_1.SampleGasPricesController; } });
|
|
7
|
+
var sample_petnames_controller_1 = require("./sample-petnames-controller.cjs");
|
|
8
|
+
Object.defineProperty(exports, "SamplePetnamesController", { enumerable: true, get: function () { return sample_petnames_controller_1.SamplePetnamesController; } });
|
|
9
|
+
var sample_gas_prices_service_1 = require("./sample-gas-prices-service/index.cjs");
|
|
10
|
+
Object.defineProperty(exports, "SampleGasPricesService", { enumerable: true, get: function () { return sample_gas_prices_service_1.SampleGasPricesService; } });
|
|
11
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAQA,mFAGwC;AAFtC,wJAAA,wCAAwC,OAAA;AACxC,yIAAA,yBAAyB,OAAA;AAU3B,+EAAwE;AAA/D,sIAAA,wBAAwB,OAAA;AACjC,mFAGqC;AAFnC,mIAAA,sBAAsB,OAAA","sourcesContent":["export type {\n SampleGasPricesControllerActions,\n SampleGasPricesControllerEvents,\n SampleGasPricesControllerGetStateAction,\n SampleGasPricesControllerMessenger,\n SampleGasPricesControllerState,\n SampleGasPricesControllerStateChangeEvent,\n} from './sample-gas-prices-controller';\nexport {\n getDefaultSampleGasPricesControllerState,\n SampleGasPricesController,\n} from './sample-gas-prices-controller';\nexport type {\n SamplePetnamesControllerActions,\n SamplePetnamesControllerEvents,\n SamplePetnamesControllerGetStateAction,\n SamplePetnamesControllerMessenger,\n SamplePetnamesControllerState,\n SamplePetnamesControllerStateChangeEvent,\n} from './sample-petnames-controller';\nexport { SamplePetnamesController } from './sample-petnames-controller';\nexport {\n SampleGasPricesService,\n type SampleAbstractGasPricesService,\n} from './sample-gas-prices-service';\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { SampleGasPricesControllerActions, SampleGasPricesControllerEvents, SampleGasPricesControllerGetStateAction, SampleGasPricesControllerMessenger, SampleGasPricesControllerState, SampleGasPricesControllerStateChangeEvent, } from "./sample-gas-prices-controller.cjs";
|
|
2
|
+
export { getDefaultSampleGasPricesControllerState, SampleGasPricesController, } from "./sample-gas-prices-controller.cjs";
|
|
3
|
+
export type { SamplePetnamesControllerActions, SamplePetnamesControllerEvents, SamplePetnamesControllerGetStateAction, SamplePetnamesControllerMessenger, SamplePetnamesControllerState, SamplePetnamesControllerStateChangeEvent, } from "./sample-petnames-controller.cjs";
|
|
4
|
+
export { SamplePetnamesController } from "./sample-petnames-controller.cjs";
|
|
5
|
+
export { SampleGasPricesService, type SampleAbstractGasPricesService, } from "./sample-gas-prices-service/index.cjs";
|
|
6
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,gCAAgC,EAChC,+BAA+B,EAC/B,uCAAuC,EACvC,kCAAkC,EAClC,8BAA8B,EAC9B,yCAAyC,GAC1C,2CAAuC;AACxC,OAAO,EACL,wCAAwC,EACxC,yBAAyB,GAC1B,2CAAuC;AACxC,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,sCAAsC,EACtC,iCAAiC,EACjC,6BAA6B,EAC7B,wCAAwC,GACzC,yCAAqC;AACtC,OAAO,EAAE,wBAAwB,EAAE,yCAAqC;AACxE,OAAO,EACL,sBAAsB,EACtB,KAAK,8BAA8B,GACpC,8CAAoC"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { SampleGasPricesControllerActions, SampleGasPricesControllerEvents, SampleGasPricesControllerGetStateAction, SampleGasPricesControllerMessenger, SampleGasPricesControllerState, SampleGasPricesControllerStateChangeEvent, } from "./sample-gas-prices-controller.mjs";
|
|
2
|
+
export { getDefaultSampleGasPricesControllerState, SampleGasPricesController, } from "./sample-gas-prices-controller.mjs";
|
|
3
|
+
export type { SamplePetnamesControllerActions, SamplePetnamesControllerEvents, SamplePetnamesControllerGetStateAction, SamplePetnamesControllerMessenger, SamplePetnamesControllerState, SamplePetnamesControllerStateChangeEvent, } from "./sample-petnames-controller.mjs";
|
|
4
|
+
export { SamplePetnamesController } from "./sample-petnames-controller.mjs";
|
|
5
|
+
export { SampleGasPricesService, type SampleAbstractGasPricesService, } from "./sample-gas-prices-service/index.mjs";
|
|
6
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,gCAAgC,EAChC,+BAA+B,EAC/B,uCAAuC,EACvC,kCAAkC,EAClC,8BAA8B,EAC9B,yCAAyC,GAC1C,2CAAuC;AACxC,OAAO,EACL,wCAAwC,EACxC,yBAAyB,GAC1B,2CAAuC;AACxC,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,sCAAsC,EACtC,iCAAiC,EACjC,6BAA6B,EAC7B,wCAAwC,GACzC,yCAAqC;AACtC,OAAO,EAAE,wBAAwB,EAAE,yCAAqC;AACxE,OAAO,EACL,sBAAsB,EACtB,KAAK,8BAA8B,GACpC,8CAAoC"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { getDefaultSampleGasPricesControllerState, SampleGasPricesController } from "./sample-gas-prices-controller.mjs";
|
|
2
|
+
export { SamplePetnamesController } from "./sample-petnames-controller.mjs";
|
|
3
|
+
export { SampleGasPricesService } from "./sample-gas-prices-service/index.mjs";
|
|
4
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,wCAAwC,EACxC,yBAAyB,EAC1B,2CAAuC;AASxC,OAAO,EAAE,wBAAwB,EAAE,yCAAqC;AACxE,OAAO,EACL,sBAAsB,EAEvB,8CAAoC","sourcesContent":["export type {\n SampleGasPricesControllerActions,\n SampleGasPricesControllerEvents,\n SampleGasPricesControllerGetStateAction,\n SampleGasPricesControllerMessenger,\n SampleGasPricesControllerState,\n SampleGasPricesControllerStateChangeEvent,\n} from './sample-gas-prices-controller';\nexport {\n getDefaultSampleGasPricesControllerState,\n SampleGasPricesController,\n} from './sample-gas-prices-controller';\nexport type {\n SamplePetnamesControllerActions,\n SamplePetnamesControllerEvents,\n SamplePetnamesControllerGetStateAction,\n SamplePetnamesControllerMessenger,\n SamplePetnamesControllerState,\n SamplePetnamesControllerStateChangeEvent,\n} from './sample-petnames-controller';\nexport { SamplePetnamesController } from './sample-petnames-controller';\nexport {\n SampleGasPricesService,\n type SampleAbstractGasPricesService,\n} from './sample-gas-prices-service';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-controller-types.cjs","sourceRoot":"","sources":["../src/network-controller-types.ts"],"names":[],"mappings":";;;AAaA;;;;;;;;GAQG;AACH,SAAgB,gCAAgC;IAC9C,OAAO;QACL,WAAW,EAAE,cAAc;QAC3B,OAAO,EAAE,KAAK;KACf,CAAC;AACJ,CAAC;AALD,4EAKC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\n/**\n * Describes the shape of the state object for a theoretical NetworkController.\n *\n * Note that this package does not supply a NetworkController; this type is only\n * here so it is possible to write a complete example.\n */\ntype NetworkControllerState = {\n networkName: string;\n chainId: Hex;\n};\n\n/**\n * Constructs a default representation of a theoretical NetworkController's\n * state.\n *\n * Note that this package does not supply a NetworkController; this type is only\n * here so it is possible to write a complete example.\n *\n * @returns The default network controller state.\n */\nexport function getDefaultNetworkControllerState(): NetworkControllerState {\n return {\n networkName: 'Some Network',\n chainId: '0x1',\n };\n}\n\n/**\n * The action which can be used to obtain the state for a theoretical\n * NetworkController.\n *\n * Note that this package does not supply a NetworkController; this type is only\n * here so it is possible to write a complete example.\n */\nexport type NetworkControllerGetStateAction = {\n type: 'NetworkController:getState';\n handler: () => NetworkControllerState;\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-controller-types.d.cts","sourceRoot":"","sources":["../src/network-controller-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C;;;;;GAKG;AACH,KAAK,sBAAsB,GAAG;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,GAAG,CAAC;CACd,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,gCAAgC,IAAI,sBAAsB,CAKzE;AAED;;;;;;GAMG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,MAAM,sBAAsB,CAAC;CACvC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-controller-types.d.mts","sourceRoot":"","sources":["../src/network-controller-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C;;;;;GAKG;AACH,KAAK,sBAAsB,GAAG;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,GAAG,CAAC;CACd,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,gCAAgC,IAAI,sBAAsB,CAKzE;AAED;;;;;;GAMG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,MAAM,sBAAsB,CAAC;CACvC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-controller-types.mjs","sourceRoot":"","sources":["../src/network-controller-types.ts"],"names":[],"mappings":"AAaA;;;;;;;;GAQG;AACH,MAAM,UAAU,gCAAgC;IAC9C,OAAO;QACL,WAAW,EAAE,cAAc;QAC3B,OAAO,EAAE,KAAK;KACf,CAAC;AACJ,CAAC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\n/**\n * Describes the shape of the state object for a theoretical NetworkController.\n *\n * Note that this package does not supply a NetworkController; this type is only\n * here so it is possible to write a complete example.\n */\ntype NetworkControllerState = {\n networkName: string;\n chainId: Hex;\n};\n\n/**\n * Constructs a default representation of a theoretical NetworkController's\n * state.\n *\n * Note that this package does not supply a NetworkController; this type is only\n * here so it is possible to write a complete example.\n *\n * @returns The default network controller state.\n */\nexport function getDefaultNetworkControllerState(): NetworkControllerState {\n return {\n networkName: 'Some Network',\n chainId: '0x1',\n };\n}\n\n/**\n * The action which can be used to obtain the state for a theoretical\n * NetworkController.\n *\n * Note that this package does not supply a NetworkController; this type is only\n * here so it is possible to write a complete example.\n */\nexport type NetworkControllerGetStateAction = {\n type: 'NetworkController:getState';\n handler: () => NetworkControllerState;\n};\n"]}
|
|
@@ -10,19 +10,19 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var
|
|
13
|
+
var _SampleGasPricesController_gasPricesService;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.SampleGasPricesController = exports.getDefaultSampleGasPricesControllerState = exports.controllerName = void 0;
|
|
16
16
|
const base_controller_1 = require("@metamask/base-controller");
|
|
17
17
|
// === GENERAL ===
|
|
18
18
|
/**
|
|
19
|
-
* The name of the {@link
|
|
19
|
+
* The name of the {@link SampleGasPricesController}, used to namespace the
|
|
20
20
|
* controller's actions and events and to namespace the controller's state data
|
|
21
21
|
* when composed with other controllers.
|
|
22
22
|
*/
|
|
23
|
-
exports.controllerName = '
|
|
23
|
+
exports.controllerName = 'SampleGasPricesController';
|
|
24
24
|
/**
|
|
25
|
-
* The metadata for each property in {@link
|
|
25
|
+
* The metadata for each property in {@link SampleGasPricesControllerState}.
|
|
26
26
|
*/
|
|
27
27
|
const gasPricesControllerMetadata = {
|
|
28
28
|
gasPricesByChainId: {
|
|
@@ -31,49 +31,49 @@ const gasPricesControllerMetadata = {
|
|
|
31
31
|
},
|
|
32
32
|
};
|
|
33
33
|
/**
|
|
34
|
-
* Constructs the default {@link
|
|
34
|
+
* Constructs the default {@link SampleGasPricesController} state. This allows
|
|
35
35
|
* consumers to provide a partial state object when initializing the controller
|
|
36
36
|
* and also helps in constructing complete state objects for this controller in
|
|
37
37
|
* tests.
|
|
38
38
|
*
|
|
39
|
-
* @returns The default {@link
|
|
39
|
+
* @returns The default {@link SampleGasPricesController} state.
|
|
40
40
|
*/
|
|
41
|
-
function
|
|
41
|
+
function getDefaultSampleGasPricesControllerState() {
|
|
42
42
|
return {
|
|
43
43
|
gasPricesByChainId: {},
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
|
-
exports.
|
|
46
|
+
exports.getDefaultSampleGasPricesControllerState = getDefaultSampleGasPricesControllerState;
|
|
47
47
|
// === CONTROLLER DEFINITION ===
|
|
48
48
|
/**
|
|
49
|
-
* `
|
|
49
|
+
* `SampleGasPricesController` fetches and persists gas prices for various chains.
|
|
50
50
|
*
|
|
51
51
|
* @example
|
|
52
52
|
*
|
|
53
53
|
* ``` ts
|
|
54
54
|
* import { Messenger } from '@metamask/base-controller';
|
|
55
55
|
* import {
|
|
56
|
-
*
|
|
57
|
-
*
|
|
56
|
+
* SampleGasPricesController,
|
|
57
|
+
* SampleGasPricesService
|
|
58
58
|
* } from '@metamask/example-controllers';
|
|
59
59
|
* import type {
|
|
60
|
-
*
|
|
61
|
-
*
|
|
60
|
+
* SampleGasPricesControllerActions,
|
|
61
|
+
* SampleGasPricesControllerEvents
|
|
62
62
|
* } from '@metamask/example-controllers';
|
|
63
63
|
* import type { NetworkControllerGetStateAction } from '@metamask/network-controller';
|
|
64
64
|
*
|
|
65
65
|
* // Assuming that you're using this in the browser
|
|
66
|
-
* const gasPricesService = new
|
|
66
|
+
* const gasPricesService = new SampleGasPricesService({ fetch });
|
|
67
67
|
* const rootMessenger = new Messenger<
|
|
68
|
-
*
|
|
69
|
-
*
|
|
68
|
+
* SampleGasPricesControllerActions | NetworkControllerGetStateAction,
|
|
69
|
+
* SampleGasPricesControllerEvents
|
|
70
70
|
* >();
|
|
71
71
|
* const gasPricesMessenger = rootMessenger.getRestricted({
|
|
72
|
-
* name: '
|
|
72
|
+
* name: 'SampleGasPricesController',
|
|
73
73
|
* allowedActions: ['NetworkController:getState'],
|
|
74
74
|
* allowedEvents: [],
|
|
75
75
|
* });
|
|
76
|
-
* const gasPricesController = new
|
|
76
|
+
* const gasPricesController = new SampleGasPricesController({
|
|
77
77
|
* messenger: gasPricesMessenger,
|
|
78
78
|
* gasPricesService,
|
|
79
79
|
* });
|
|
@@ -85,9 +85,9 @@ exports.getDefaultGasPricesControllerState = getDefaultGasPricesControllerState;
|
|
|
85
85
|
* // => { '0x42': { low: 5, average: 10, high: 15, fetchedDate: '2024-01-02T00:00:00.000Z' } }
|
|
86
86
|
* ```
|
|
87
87
|
*/
|
|
88
|
-
class
|
|
88
|
+
class SampleGasPricesController extends base_controller_1.BaseController {
|
|
89
89
|
/**
|
|
90
|
-
* Constructs a new {@link
|
|
90
|
+
* Constructs a new {@link SampleGasPricesController}.
|
|
91
91
|
*
|
|
92
92
|
* @param args - The arguments to the controller.
|
|
93
93
|
* @param args.messenger - The messenger suited for this controller.
|
|
@@ -102,15 +102,15 @@ class GasPricesController extends base_controller_1.BaseController {
|
|
|
102
102
|
metadata: gasPricesControllerMetadata,
|
|
103
103
|
name: exports.controllerName,
|
|
104
104
|
state: {
|
|
105
|
-
...
|
|
105
|
+
...getDefaultSampleGasPricesControllerState(),
|
|
106
106
|
...state,
|
|
107
107
|
},
|
|
108
108
|
});
|
|
109
109
|
/**
|
|
110
110
|
* The service object that is used to obtain gas prices.
|
|
111
111
|
*/
|
|
112
|
-
|
|
113
|
-
__classPrivateFieldSet(this,
|
|
112
|
+
_SampleGasPricesController_gasPricesService.set(this, void 0);
|
|
113
|
+
__classPrivateFieldSet(this, _SampleGasPricesController_gasPricesService, gasPricesService, "f");
|
|
114
114
|
this.messagingSystem.registerActionHandler(`${exports.controllerName}:updateGasPrices`, this.updateGasPrices.bind(this));
|
|
115
115
|
}
|
|
116
116
|
/**
|
|
@@ -119,7 +119,7 @@ class GasPricesController extends base_controller_1.BaseController {
|
|
|
119
119
|
*/
|
|
120
120
|
async updateGasPrices() {
|
|
121
121
|
const { chainId } = this.messagingSystem.call('NetworkController:getState');
|
|
122
|
-
const gasPricesResponse = await __classPrivateFieldGet(this,
|
|
122
|
+
const gasPricesResponse = await __classPrivateFieldGet(this, _SampleGasPricesController_gasPricesService, "f").fetchGasPrices(chainId);
|
|
123
123
|
this.update((state) => {
|
|
124
124
|
state.gasPricesByChainId[chainId] = {
|
|
125
125
|
...gasPricesResponse,
|
|
@@ -128,6 +128,6 @@ class GasPricesController extends base_controller_1.BaseController {
|
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
-
exports.
|
|
132
|
-
|
|
133
|
-
//# sourceMappingURL=gas-prices-controller.cjs.map
|
|
131
|
+
exports.SampleGasPricesController = SampleGasPricesController;
|
|
132
|
+
_SampleGasPricesController_gasPricesService = new WeakMap();
|
|
133
|
+
//# sourceMappingURL=sample-gas-prices-controller.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sample-gas-prices-controller.cjs","sourceRoot":"","sources":["../src/sample-gas-prices-controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAMA,+DAA2D;AAM3D,kBAAkB;AAElB;;;;GAIG;AACU,QAAA,cAAc,GAAG,2BAA2B,CAAC;AAuC1D;;GAEG;AACH,MAAM,2BAA2B,GAAG;IAClC,kBAAkB,EAAE;QAClB,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,KAAK;KACjB;CACsD,CAAC;AAmE1D;;;;;;;GAOG;AACH,SAAgB,wCAAwC;IACtD,OAAO;QACL,kBAAkB,EAAE,EAAE;KACvB,CAAC;AACJ,CAAC;AAJD,4FAIC;AAED,gCAAgC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAa,yBAA0B,SAAQ,gCAI9C;IAMC;;;;;;;;;OASG;IACH,YAAY,EACV,SAAS,EACT,KAAK,EACL,gBAAgB,GAKjB;QACC,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,2BAA2B;YACrC,IAAI,EAAE,sBAAc;YACpB,KAAK,EAAE;gBACL,GAAG,wCAAwC,EAAE;gBAC7C,GAAG,KAAK;aACT;SACF,CAAC,CAAC;QAhCL;;WAEG;QACM,8DAAkD;QA+BzD,uBAAA,IAAI,+CAAqB,gBAAgB,MAAA,CAAC;QAE1C,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,sBAAc,kBAAkB,EACnC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAChC,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,eAAe;QACnB,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;QAC5E,MAAM,iBAAiB,GACrB,MAAM,uBAAA,IAAI,mDAAkB,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QACvD,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,kBAAkB,CAAC,OAAO,CAAC,GAAG;gBAClC,GAAG,iBAAiB;gBACpB,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;aACtC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA9DD,8DA8DC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport type { NetworkControllerGetStateAction } from './network-controller-types';\nimport type { SampleAbstractGasPricesService } from './sample-gas-prices-service';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link SampleGasPricesController}, used to namespace the\n * controller's actions and events and to namespace the controller's state data\n * when composed with other controllers.\n */\nexport const controllerName = 'SampleGasPricesController';\n\n// === STATE ===\n\n/**\n * The collection of gas price data fetched periodically.\n */\ntype GasPrices = {\n /**\n * The total estimated gas in the \"low\" bucket.\n */\n low: number;\n /**\n * The total estimated gas in the \"average\" bucket.\n */\n average: number;\n /**\n * The total estimated gas in the \"high\" bucket.\n */\n high: number;\n /**\n * The date/time (in ISO-8601 format) when prices were fetched.\n */\n fetchedDate: string;\n};\n\n/**\n * Describes the shape of the state object for {@link SampleGasPricesController}.\n */\nexport type SampleGasPricesControllerState = {\n /**\n * The registry of pet names, categorized by chain ID first and address\n * second.\n */\n gasPricesByChainId: {\n [chainId: Hex]: GasPrices;\n };\n};\n\n/**\n * The metadata for each property in {@link SampleGasPricesControllerState}.\n */\nconst gasPricesControllerMetadata = {\n gasPricesByChainId: {\n persist: true,\n anonymous: false,\n },\n} satisfies StateMetadata<SampleGasPricesControllerState>;\n\n// === MESSENGER ===\n\n/**\n * The action which can be used to retrieve the state of the\n * {@link SampleGasPricesController}.\n */\nexport type SampleGasPricesControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SampleGasPricesControllerState\n>;\n\n/**\n * The action which can be used to update gas prices.\n */\nexport type SampleGasPricesControllerUpdateGasPricesAction = {\n type: `${typeof controllerName}:updateGasPrices`;\n handler: SampleGasPricesController['updateGasPrices'];\n};\n\n/**\n * All actions that {@link SampleGasPricesController} registers, to be called\n * externally.\n */\nexport type SampleGasPricesControllerActions =\n | SampleGasPricesControllerGetStateAction\n | SampleGasPricesControllerUpdateGasPricesAction;\n\n/**\n * All actions that {@link SampleGasPricesController} calls internally.\n */\ntype AllowedActions = NetworkControllerGetStateAction;\n\n/**\n * The event that {@link SampleGasPricesController} publishes when updating state.\n */\nexport type SampleGasPricesControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n SampleGasPricesControllerState\n >;\n\n/**\n * All events that {@link SampleGasPricesController} publishes, to be subscribed to\n * externally.\n */\nexport type SampleGasPricesControllerEvents =\n SampleGasPricesControllerStateChangeEvent;\n\n/**\n * All events that {@link SampleGasPricesController} subscribes to internally.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link SampleGasPricesController}.\n */\nexport type SampleGasPricesControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n SampleGasPricesControllerActions | AllowedActions,\n SampleGasPricesControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/**\n * Constructs the default {@link SampleGasPricesController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link SampleGasPricesController} state.\n */\nexport function getDefaultSampleGasPricesControllerState(): SampleGasPricesControllerState {\n return {\n gasPricesByChainId: {},\n };\n}\n\n// === CONTROLLER DEFINITION ===\n\n/**\n * `SampleGasPricesController` fetches and persists gas prices for various chains.\n *\n * @example\n *\n * ``` ts\n * import { Messenger } from '@metamask/base-controller';\n * import {\n * SampleGasPricesController,\n * SampleGasPricesService\n * } from '@metamask/example-controllers';\n * import type {\n * SampleGasPricesControllerActions,\n * SampleGasPricesControllerEvents\n * } from '@metamask/example-controllers';\n * import type { NetworkControllerGetStateAction } from '@metamask/network-controller';\n *\n * // Assuming that you're using this in the browser\n * const gasPricesService = new SampleGasPricesService({ fetch });\n * const rootMessenger = new Messenger<\n * SampleGasPricesControllerActions | NetworkControllerGetStateAction,\n * SampleGasPricesControllerEvents\n * >();\n * const gasPricesMessenger = rootMessenger.getRestricted({\n * name: 'SampleGasPricesController',\n * allowedActions: ['NetworkController:getState'],\n * allowedEvents: [],\n * });\n * const gasPricesController = new SampleGasPricesController({\n * messenger: gasPricesMessenger,\n * gasPricesService,\n * });\n *\n * // Assuming that `NetworkController:getState` returns an object with a\n * // `chainId` of `0x42`...\n * await gasPricesController.updateGasPrices();\n * gasPricesController.state.gasPricesByChainId\n * // => { '0x42': { low: 5, average: 10, high: 15, fetchedDate: '2024-01-02T00:00:00.000Z' } }\n * ```\n */\nexport class SampleGasPricesController extends BaseController<\n typeof controllerName,\n SampleGasPricesControllerState,\n SampleGasPricesControllerMessenger\n> {\n /**\n * The service object that is used to obtain gas prices.\n */\n readonly #gasPricesService: SampleAbstractGasPricesService;\n\n /**\n * Constructs a new {@link SampleGasPricesController}.\n *\n * @param args - The arguments to the controller.\n * @param args.messenger - The messenger suited for this controller.\n * @param args.state - The desired state with which to initialize this\n * controller. Missing properties will be filled in with defaults.\n * @param args.gasPricesService - The service object that will be used to\n * obtain gas prices.\n */\n constructor({\n messenger,\n state,\n gasPricesService,\n }: {\n messenger: SampleGasPricesControllerMessenger;\n state?: Partial<SampleGasPricesControllerState>;\n gasPricesService: SampleAbstractGasPricesService;\n }) {\n super({\n messenger,\n metadata: gasPricesControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultSampleGasPricesControllerState(),\n ...state,\n },\n });\n\n this.#gasPricesService = gasPricesService;\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateGasPrices`,\n this.updateGasPrices.bind(this),\n );\n }\n\n /**\n * Fetches the latest gas prices for the current chain, persisting them to\n * state.\n */\n async updateGasPrices() {\n const { chainId } = this.messagingSystem.call('NetworkController:getState');\n const gasPricesResponse =\n await this.#gasPricesService.fetchGasPrices(chainId);\n this.update((state) => {\n state.gasPricesByChainId[chainId] = {\n ...gasPricesResponse,\n fetchedDate: new Date().toISOString(),\n };\n });\n }\n}\n"]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedMessenger } from "@metamask/base-controller";
|
|
2
2
|
import { BaseController } from "@metamask/base-controller";
|
|
3
3
|
import type { Hex } from "@metamask/utils";
|
|
4
|
-
import type { AbstractGasPricesService } from "./gas-prices-service/abstract-gas-prices-service.cjs";
|
|
5
4
|
import type { NetworkControllerGetStateAction } from "./network-controller-types.cjs";
|
|
5
|
+
import type { SampleAbstractGasPricesService } from "./sample-gas-prices-service/index.cjs";
|
|
6
6
|
/**
|
|
7
|
-
* The name of the {@link
|
|
7
|
+
* The name of the {@link SampleGasPricesController}, used to namespace the
|
|
8
8
|
* controller's actions and events and to namespace the controller's state data
|
|
9
9
|
* when composed with other controllers.
|
|
10
10
|
*/
|
|
11
|
-
export declare const controllerName = "
|
|
11
|
+
export declare const controllerName = "SampleGasPricesController";
|
|
12
12
|
/**
|
|
13
13
|
* The collection of gas price data fetched periodically.
|
|
14
14
|
*/
|
|
@@ -31,9 +31,9 @@ type GasPrices = {
|
|
|
31
31
|
fetchedDate: string;
|
|
32
32
|
};
|
|
33
33
|
/**
|
|
34
|
-
* Describes the shape of the state object for {@link
|
|
34
|
+
* Describes the shape of the state object for {@link SampleGasPricesController}.
|
|
35
35
|
*/
|
|
36
|
-
export type
|
|
36
|
+
export type SampleGasPricesControllerState = {
|
|
37
37
|
/**
|
|
38
38
|
* The registry of pet names, categorized by chain ID first and address
|
|
39
39
|
* second.
|
|
@@ -44,81 +44,81 @@ export type GasPricesControllerState = {
|
|
|
44
44
|
};
|
|
45
45
|
/**
|
|
46
46
|
* The action which can be used to retrieve the state of the
|
|
47
|
-
* {@link
|
|
47
|
+
* {@link SampleGasPricesController}.
|
|
48
48
|
*/
|
|
49
|
-
export type
|
|
49
|
+
export type SampleGasPricesControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SampleGasPricesControllerState>;
|
|
50
50
|
/**
|
|
51
51
|
* The action which can be used to update gas prices.
|
|
52
52
|
*/
|
|
53
|
-
export type
|
|
53
|
+
export type SampleGasPricesControllerUpdateGasPricesAction = {
|
|
54
54
|
type: `${typeof controllerName}:updateGasPrices`;
|
|
55
|
-
handler:
|
|
55
|
+
handler: SampleGasPricesController['updateGasPrices'];
|
|
56
56
|
};
|
|
57
57
|
/**
|
|
58
|
-
* All actions that {@link
|
|
58
|
+
* All actions that {@link SampleGasPricesController} registers, to be called
|
|
59
59
|
* externally.
|
|
60
60
|
*/
|
|
61
|
-
export type
|
|
61
|
+
export type SampleGasPricesControllerActions = SampleGasPricesControllerGetStateAction | SampleGasPricesControllerUpdateGasPricesAction;
|
|
62
62
|
/**
|
|
63
|
-
* All actions that {@link
|
|
63
|
+
* All actions that {@link SampleGasPricesController} calls internally.
|
|
64
64
|
*/
|
|
65
65
|
type AllowedActions = NetworkControllerGetStateAction;
|
|
66
66
|
/**
|
|
67
|
-
* The event that {@link
|
|
67
|
+
* The event that {@link SampleGasPricesController} publishes when updating state.
|
|
68
68
|
*/
|
|
69
|
-
export type
|
|
69
|
+
export type SampleGasPricesControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SampleGasPricesControllerState>;
|
|
70
70
|
/**
|
|
71
|
-
* All events that {@link
|
|
71
|
+
* All events that {@link SampleGasPricesController} publishes, to be subscribed to
|
|
72
72
|
* externally.
|
|
73
73
|
*/
|
|
74
|
-
export type
|
|
74
|
+
export type SampleGasPricesControllerEvents = SampleGasPricesControllerStateChangeEvent;
|
|
75
75
|
/**
|
|
76
|
-
* All events that {@link
|
|
76
|
+
* All events that {@link SampleGasPricesController} subscribes to internally.
|
|
77
77
|
*/
|
|
78
78
|
type AllowedEvents = never;
|
|
79
79
|
/**
|
|
80
80
|
* The messenger which is restricted to actions and events accessed by
|
|
81
|
-
* {@link
|
|
81
|
+
* {@link SampleGasPricesController}.
|
|
82
82
|
*/
|
|
83
|
-
export type
|
|
83
|
+
export type SampleGasPricesControllerMessenger = RestrictedMessenger<typeof controllerName, SampleGasPricesControllerActions | AllowedActions, SampleGasPricesControllerEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
|
|
84
84
|
/**
|
|
85
|
-
* Constructs the default {@link
|
|
85
|
+
* Constructs the default {@link SampleGasPricesController} state. This allows
|
|
86
86
|
* consumers to provide a partial state object when initializing the controller
|
|
87
87
|
* and also helps in constructing complete state objects for this controller in
|
|
88
88
|
* tests.
|
|
89
89
|
*
|
|
90
|
-
* @returns The default {@link
|
|
90
|
+
* @returns The default {@link SampleGasPricesController} state.
|
|
91
91
|
*/
|
|
92
|
-
export declare function
|
|
92
|
+
export declare function getDefaultSampleGasPricesControllerState(): SampleGasPricesControllerState;
|
|
93
93
|
/**
|
|
94
|
-
* `
|
|
94
|
+
* `SampleGasPricesController` fetches and persists gas prices for various chains.
|
|
95
95
|
*
|
|
96
96
|
* @example
|
|
97
97
|
*
|
|
98
98
|
* ``` ts
|
|
99
99
|
* import { Messenger } from '@metamask/base-controller';
|
|
100
100
|
* import {
|
|
101
|
-
*
|
|
102
|
-
*
|
|
101
|
+
* SampleGasPricesController,
|
|
102
|
+
* SampleGasPricesService
|
|
103
103
|
* } from '@metamask/example-controllers';
|
|
104
104
|
* import type {
|
|
105
|
-
*
|
|
106
|
-
*
|
|
105
|
+
* SampleGasPricesControllerActions,
|
|
106
|
+
* SampleGasPricesControllerEvents
|
|
107
107
|
* } from '@metamask/example-controllers';
|
|
108
108
|
* import type { NetworkControllerGetStateAction } from '@metamask/network-controller';
|
|
109
109
|
*
|
|
110
110
|
* // Assuming that you're using this in the browser
|
|
111
|
-
* const gasPricesService = new
|
|
111
|
+
* const gasPricesService = new SampleGasPricesService({ fetch });
|
|
112
112
|
* const rootMessenger = new Messenger<
|
|
113
|
-
*
|
|
114
|
-
*
|
|
113
|
+
* SampleGasPricesControllerActions | NetworkControllerGetStateAction,
|
|
114
|
+
* SampleGasPricesControllerEvents
|
|
115
115
|
* >();
|
|
116
116
|
* const gasPricesMessenger = rootMessenger.getRestricted({
|
|
117
|
-
* name: '
|
|
117
|
+
* name: 'SampleGasPricesController',
|
|
118
118
|
* allowedActions: ['NetworkController:getState'],
|
|
119
119
|
* allowedEvents: [],
|
|
120
120
|
* });
|
|
121
|
-
* const gasPricesController = new
|
|
121
|
+
* const gasPricesController = new SampleGasPricesController({
|
|
122
122
|
* messenger: gasPricesMessenger,
|
|
123
123
|
* gasPricesService,
|
|
124
124
|
* });
|
|
@@ -130,10 +130,10 @@ export declare function getDefaultGasPricesControllerState(): GasPricesControlle
|
|
|
130
130
|
* // => { '0x42': { low: 5, average: 10, high: 15, fetchedDate: '2024-01-02T00:00:00.000Z' } }
|
|
131
131
|
* ```
|
|
132
132
|
*/
|
|
133
|
-
export declare class
|
|
133
|
+
export declare class SampleGasPricesController extends BaseController<typeof controllerName, SampleGasPricesControllerState, SampleGasPricesControllerMessenger> {
|
|
134
134
|
#private;
|
|
135
135
|
/**
|
|
136
|
-
* Constructs a new {@link
|
|
136
|
+
* Constructs a new {@link SampleGasPricesController}.
|
|
137
137
|
*
|
|
138
138
|
* @param args - The arguments to the controller.
|
|
139
139
|
* @param args.messenger - The messenger suited for this controller.
|
|
@@ -143,9 +143,9 @@ export declare class GasPricesController extends BaseController<typeof controlle
|
|
|
143
143
|
* obtain gas prices.
|
|
144
144
|
*/
|
|
145
145
|
constructor({ messenger, state, gasPricesService, }: {
|
|
146
|
-
messenger:
|
|
147
|
-
state?: Partial<
|
|
148
|
-
gasPricesService:
|
|
146
|
+
messenger: SampleGasPricesControllerMessenger;
|
|
147
|
+
state?: Partial<SampleGasPricesControllerState>;
|
|
148
|
+
gasPricesService: SampleAbstractGasPricesService;
|
|
149
149
|
});
|
|
150
150
|
/**
|
|
151
151
|
* Fetches the latest gas prices for the current chain, persisting them to
|
|
@@ -154,4 +154,4 @@ export declare class GasPricesController extends BaseController<typeof controlle
|
|
|
154
154
|
updateGasPrices(): Promise<void>;
|
|
155
155
|
}
|
|
156
156
|
export {};
|
|
157
|
-
//# sourceMappingURL=gas-prices-controller.d.cts.map
|
|
157
|
+
//# sourceMappingURL=sample-gas-prices-controller.d.cts.map
|
|
@@ -0,0 +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,+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,8BAA8B,CAC/B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,GAAG,OAAO,cAAc,kBAAkB,CAAC;IACjD,OAAO,EAAE,yBAAyB,CAAC,iBAAiB,CAAC,CAAC;CACvD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,gCAAgC,GACxC,uCAAuC,GACvC,8CAA8C,CAAC;AAEnD;;GAEG;AACH,KAAK,cAAc,GAAG,+BAA+B,CAAC;AAEtD;;GAEG;AACH,MAAM,MAAM,yCAAyC,GACnD,0BAA0B,CACxB,OAAO,cAAc,EACrB,8BAA8B,CAC/B,CAAC;AAEJ;;;GAGG;AACH,MAAM,MAAM,+BAA+B,GACzC,yCAAyC,CAAC;AAE5C;;GAEG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;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;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,14 +1,14 @@
|
|
|
1
1
|
import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedMessenger } from "@metamask/base-controller";
|
|
2
2
|
import { BaseController } from "@metamask/base-controller";
|
|
3
3
|
import type { Hex } from "@metamask/utils";
|
|
4
|
-
import type { AbstractGasPricesService } from "./gas-prices-service/abstract-gas-prices-service.mjs";
|
|
5
4
|
import type { NetworkControllerGetStateAction } from "./network-controller-types.mjs";
|
|
5
|
+
import type { SampleAbstractGasPricesService } from "./sample-gas-prices-service/index.mjs";
|
|
6
6
|
/**
|
|
7
|
-
* The name of the {@link
|
|
7
|
+
* The name of the {@link SampleGasPricesController}, used to namespace the
|
|
8
8
|
* controller's actions and events and to namespace the controller's state data
|
|
9
9
|
* when composed with other controllers.
|
|
10
10
|
*/
|
|
11
|
-
export declare const controllerName = "
|
|
11
|
+
export declare const controllerName = "SampleGasPricesController";
|
|
12
12
|
/**
|
|
13
13
|
* The collection of gas price data fetched periodically.
|
|
14
14
|
*/
|
|
@@ -31,9 +31,9 @@ type GasPrices = {
|
|
|
31
31
|
fetchedDate: string;
|
|
32
32
|
};
|
|
33
33
|
/**
|
|
34
|
-
* Describes the shape of the state object for {@link
|
|
34
|
+
* Describes the shape of the state object for {@link SampleGasPricesController}.
|
|
35
35
|
*/
|
|
36
|
-
export type
|
|
36
|
+
export type SampleGasPricesControllerState = {
|
|
37
37
|
/**
|
|
38
38
|
* The registry of pet names, categorized by chain ID first and address
|
|
39
39
|
* second.
|
|
@@ -44,81 +44,81 @@ export type GasPricesControllerState = {
|
|
|
44
44
|
};
|
|
45
45
|
/**
|
|
46
46
|
* The action which can be used to retrieve the state of the
|
|
47
|
-
* {@link
|
|
47
|
+
* {@link SampleGasPricesController}.
|
|
48
48
|
*/
|
|
49
|
-
export type
|
|
49
|
+
export type SampleGasPricesControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SampleGasPricesControllerState>;
|
|
50
50
|
/**
|
|
51
51
|
* The action which can be used to update gas prices.
|
|
52
52
|
*/
|
|
53
|
-
export type
|
|
53
|
+
export type SampleGasPricesControllerUpdateGasPricesAction = {
|
|
54
54
|
type: `${typeof controllerName}:updateGasPrices`;
|
|
55
|
-
handler:
|
|
55
|
+
handler: SampleGasPricesController['updateGasPrices'];
|
|
56
56
|
};
|
|
57
57
|
/**
|
|
58
|
-
* All actions that {@link
|
|
58
|
+
* All actions that {@link SampleGasPricesController} registers, to be called
|
|
59
59
|
* externally.
|
|
60
60
|
*/
|
|
61
|
-
export type
|
|
61
|
+
export type SampleGasPricesControllerActions = SampleGasPricesControllerGetStateAction | SampleGasPricesControllerUpdateGasPricesAction;
|
|
62
62
|
/**
|
|
63
|
-
* All actions that {@link
|
|
63
|
+
* All actions that {@link SampleGasPricesController} calls internally.
|
|
64
64
|
*/
|
|
65
65
|
type AllowedActions = NetworkControllerGetStateAction;
|
|
66
66
|
/**
|
|
67
|
-
* The event that {@link
|
|
67
|
+
* The event that {@link SampleGasPricesController} publishes when updating state.
|
|
68
68
|
*/
|
|
69
|
-
export type
|
|
69
|
+
export type SampleGasPricesControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SampleGasPricesControllerState>;
|
|
70
70
|
/**
|
|
71
|
-
* All events that {@link
|
|
71
|
+
* All events that {@link SampleGasPricesController} publishes, to be subscribed to
|
|
72
72
|
* externally.
|
|
73
73
|
*/
|
|
74
|
-
export type
|
|
74
|
+
export type SampleGasPricesControllerEvents = SampleGasPricesControllerStateChangeEvent;
|
|
75
75
|
/**
|
|
76
|
-
* All events that {@link
|
|
76
|
+
* All events that {@link SampleGasPricesController} subscribes to internally.
|
|
77
77
|
*/
|
|
78
78
|
type AllowedEvents = never;
|
|
79
79
|
/**
|
|
80
80
|
* The messenger which is restricted to actions and events accessed by
|
|
81
|
-
* {@link
|
|
81
|
+
* {@link SampleGasPricesController}.
|
|
82
82
|
*/
|
|
83
|
-
export type
|
|
83
|
+
export type SampleGasPricesControllerMessenger = RestrictedMessenger<typeof controllerName, SampleGasPricesControllerActions | AllowedActions, SampleGasPricesControllerEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
|
|
84
84
|
/**
|
|
85
|
-
* Constructs the default {@link
|
|
85
|
+
* Constructs the default {@link SampleGasPricesController} state. This allows
|
|
86
86
|
* consumers to provide a partial state object when initializing the controller
|
|
87
87
|
* and also helps in constructing complete state objects for this controller in
|
|
88
88
|
* tests.
|
|
89
89
|
*
|
|
90
|
-
* @returns The default {@link
|
|
90
|
+
* @returns The default {@link SampleGasPricesController} state.
|
|
91
91
|
*/
|
|
92
|
-
export declare function
|
|
92
|
+
export declare function getDefaultSampleGasPricesControllerState(): SampleGasPricesControllerState;
|
|
93
93
|
/**
|
|
94
|
-
* `
|
|
94
|
+
* `SampleGasPricesController` fetches and persists gas prices for various chains.
|
|
95
95
|
*
|
|
96
96
|
* @example
|
|
97
97
|
*
|
|
98
98
|
* ``` ts
|
|
99
99
|
* import { Messenger } from '@metamask/base-controller';
|
|
100
100
|
* import {
|
|
101
|
-
*
|
|
102
|
-
*
|
|
101
|
+
* SampleGasPricesController,
|
|
102
|
+
* SampleGasPricesService
|
|
103
103
|
* } from '@metamask/example-controllers';
|
|
104
104
|
* import type {
|
|
105
|
-
*
|
|
106
|
-
*
|
|
105
|
+
* SampleGasPricesControllerActions,
|
|
106
|
+
* SampleGasPricesControllerEvents
|
|
107
107
|
* } from '@metamask/example-controllers';
|
|
108
108
|
* import type { NetworkControllerGetStateAction } from '@metamask/network-controller';
|
|
109
109
|
*
|
|
110
110
|
* // Assuming that you're using this in the browser
|
|
111
|
-
* const gasPricesService = new
|
|
111
|
+
* const gasPricesService = new SampleGasPricesService({ fetch });
|
|
112
112
|
* const rootMessenger = new Messenger<
|
|
113
|
-
*
|
|
114
|
-
*
|
|
113
|
+
* SampleGasPricesControllerActions | NetworkControllerGetStateAction,
|
|
114
|
+
* SampleGasPricesControllerEvents
|
|
115
115
|
* >();
|
|
116
116
|
* const gasPricesMessenger = rootMessenger.getRestricted({
|
|
117
|
-
* name: '
|
|
117
|
+
* name: 'SampleGasPricesController',
|
|
118
118
|
* allowedActions: ['NetworkController:getState'],
|
|
119
119
|
* allowedEvents: [],
|
|
120
120
|
* });
|
|
121
|
-
* const gasPricesController = new
|
|
121
|
+
* const gasPricesController = new SampleGasPricesController({
|
|
122
122
|
* messenger: gasPricesMessenger,
|
|
123
123
|
* gasPricesService,
|
|
124
124
|
* });
|
|
@@ -130,10 +130,10 @@ export declare function getDefaultGasPricesControllerState(): GasPricesControlle
|
|
|
130
130
|
* // => { '0x42': { low: 5, average: 10, high: 15, fetchedDate: '2024-01-02T00:00:00.000Z' } }
|
|
131
131
|
* ```
|
|
132
132
|
*/
|
|
133
|
-
export declare class
|
|
133
|
+
export declare class SampleGasPricesController extends BaseController<typeof controllerName, SampleGasPricesControllerState, SampleGasPricesControllerMessenger> {
|
|
134
134
|
#private;
|
|
135
135
|
/**
|
|
136
|
-
* Constructs a new {@link
|
|
136
|
+
* Constructs a new {@link SampleGasPricesController}.
|
|
137
137
|
*
|
|
138
138
|
* @param args - The arguments to the controller.
|
|
139
139
|
* @param args.messenger - The messenger suited for this controller.
|
|
@@ -143,9 +143,9 @@ export declare class GasPricesController extends BaseController<typeof controlle
|
|
|
143
143
|
* obtain gas prices.
|
|
144
144
|
*/
|
|
145
145
|
constructor({ messenger, state, gasPricesService, }: {
|
|
146
|
-
messenger:
|
|
147
|
-
state?: Partial<
|
|
148
|
-
gasPricesService:
|
|
146
|
+
messenger: SampleGasPricesControllerMessenger;
|
|
147
|
+
state?: Partial<SampleGasPricesControllerState>;
|
|
148
|
+
gasPricesService: SampleAbstractGasPricesService;
|
|
149
149
|
});
|
|
150
150
|
/**
|
|
151
151
|
* Fetches the latest gas prices for the current chain, persisting them to
|
|
@@ -154,4 +154,4 @@ export declare class GasPricesController extends BaseController<typeof controlle
|
|
|
154
154
|
updateGasPrices(): Promise<void>;
|
|
155
155
|
}
|
|
156
156
|
export {};
|
|
157
|
-
//# sourceMappingURL=gas-prices-controller.d.mts.map
|
|
157
|
+
//# sourceMappingURL=sample-gas-prices-controller.d.mts.map
|
|
@@ -0,0 +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,+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,8BAA8B,CAC/B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,GAAG,OAAO,cAAc,kBAAkB,CAAC;IACjD,OAAO,EAAE,yBAAyB,CAAC,iBAAiB,CAAC,CAAC;CACvD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,gCAAgC,GACxC,uCAAuC,GACvC,8CAA8C,CAAC;AAEnD;;GAEG;AACH,KAAK,cAAc,GAAG,+BAA+B,CAAC;AAEtD;;GAEG;AACH,MAAM,MAAM,yCAAyC,GACnD,0BAA0B,CACxB,OAAO,cAAc,EACrB,8BAA8B,CAC/B,CAAC;AAEJ;;;GAGG;AACH,MAAM,MAAM,+BAA+B,GACzC,yCAAyC,CAAC;AAE5C;;GAEG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;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;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"}
|