@metamask-previews/sample-controllers 0.0.0-preview-37b05a4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/LICENSE +20 -0
  3. package/README.md +15 -0
  4. package/dist/tsconfig.build.tsbuildinfo +1 -0
  5. package/dist/types/gas-prices-controller.cjs +133 -0
  6. package/dist/types/gas-prices-controller.cjs.map +1 -0
  7. package/dist/types/gas-prices-controller.d.cts +157 -0
  8. package/dist/types/gas-prices-controller.d.cts.map +1 -0
  9. package/dist/types/gas-prices-controller.d.mts +157 -0
  10. package/dist/types/gas-prices-controller.d.mts.map +1 -0
  11. package/dist/types/gas-prices-controller.mjs +128 -0
  12. package/dist/types/gas-prices-controller.mjs.map +1 -0
  13. package/dist/types/gas-prices-service/abstract-gas-prices-service.cjs +3 -0
  14. package/dist/types/gas-prices-service/abstract-gas-prices-service.cjs.map +1 -0
  15. package/dist/types/gas-prices-service/abstract-gas-prices-service.d.cts +7 -0
  16. package/dist/types/gas-prices-service/abstract-gas-prices-service.d.cts.map +1 -0
  17. package/dist/types/gas-prices-service/abstract-gas-prices-service.d.mts +7 -0
  18. package/dist/types/gas-prices-service/abstract-gas-prices-service.d.mts.map +1 -0
  19. package/dist/types/gas-prices-service/abstract-gas-prices-service.mjs +2 -0
  20. package/dist/types/gas-prices-service/abstract-gas-prices-service.mjs.map +1 -0
  21. package/dist/types/gas-prices-service/gas-prices-service.cjs +72 -0
  22. package/dist/types/gas-prices-service/gas-prices-service.cjs.map +1 -0
  23. package/dist/types/gas-prices-service/gas-prices-service.d.cts +55 -0
  24. package/dist/types/gas-prices-service/gas-prices-service.d.cts.map +1 -0
  25. package/dist/types/gas-prices-service/gas-prices-service.d.mts +55 -0
  26. package/dist/types/gas-prices-service/gas-prices-service.d.mts.map +1 -0
  27. package/dist/types/gas-prices-service/gas-prices-service.mjs +68 -0
  28. package/dist/types/gas-prices-service/gas-prices-service.mjs.map +1 -0
  29. package/dist/types/index.cjs +12 -0
  30. package/dist/types/index.cjs.map +1 -0
  31. package/dist/types/index.d.cts +6 -0
  32. package/dist/types/index.d.cts.map +1 -0
  33. package/dist/types/index.d.mts +6 -0
  34. package/dist/types/index.d.mts.map +1 -0
  35. package/dist/types/index.mjs +4 -0
  36. package/dist/types/index.mjs.map +1 -0
  37. package/dist/types/network-controller-types.cjs +20 -0
  38. package/dist/types/network-controller-types.cjs.map +1 -0
  39. package/dist/types/network-controller-types.d.cts +34 -0
  40. package/dist/types/network-controller-types.d.cts.map +1 -0
  41. package/dist/types/network-controller-types.d.mts +34 -0
  42. package/dist/types/network-controller-types.d.mts.map +1 -0
  43. package/dist/types/network-controller-types.mjs +16 -0
  44. package/dist/types/network-controller-types.mjs.map +1 -0
  45. package/dist/types/pet-names-controller.cjs +113 -0
  46. package/dist/types/pet-names-controller.cjs.map +1 -0
  47. package/dist/types/pet-names-controller.d.cts +124 -0
  48. package/dist/types/pet-names-controller.d.cts.map +1 -0
  49. package/dist/types/pet-names-controller.d.mts +124 -0
  50. package/dist/types/pet-names-controller.d.mts.map +1 -0
  51. package/dist/types/pet-names-controller.mjs +108 -0
  52. package/dist/types/pet-names-controller.mjs.map +1 -0
  53. package/package.json +72 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gas-prices-controller.mjs","sourceRoot":"","sources":["../../src/gas-prices-controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAM3D,kBAAkB;AAElB;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,qBAAqB,CAAC;AAuCpD;;GAEG;AACH,MAAM,2BAA2B,GAAG;IAClC,kBAAkB,EAAE;QAClB,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,KAAK;KACjB;CACgD,CAAC;AAiEpD;;;;;;;GAOG;AACH,MAAM,UAAU,kCAAkC;IAChD,OAAO;QACL,kBAAkB,EAAE,EAAE;KACvB,CAAC;AACJ,CAAC;AAED,gCAAgC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,OAAO,mBAAoB,SAAQ,cAIxC;IAMC;;;;;;;;;OASG;IACH,YAAY,EACV,SAAS,EACT,KAAK,EACL,gBAAgB,GAKjB;QACC,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,2BAA2B;YACrC,IAAI,EAAE,cAAc;YACpB,KAAK,EAAE;gBACL,GAAG,kCAAkC,EAAE;gBACvC,GAAG,KAAK;aACT;SACF,CAAC,CAAC;QAhCL;;WAEG;QACM,wDAA4C;QA+BnD,uBAAA,IAAI,yCAAqB,gBAAgB,MAAA,CAAC;QAE1C,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,cAAc,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,6CAAkB,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","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 { AbstractGasPricesService } from './gas-prices-service/abstract-gas-prices-service';\nimport type { NetworkControllerGetStateAction } from './network-controller-types';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link GasPricesController}, 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 = 'GasPricesController';\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 GasPricesController}.\n */\nexport type GasPricesControllerState = {\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 GasPricesControllerState}.\n */\nconst gasPricesControllerMetadata = {\n gasPricesByChainId: {\n persist: true,\n anonymous: false,\n },\n} satisfies StateMetadata<GasPricesControllerState>;\n\n// === MESSENGER ===\n\n/**\n * The action which can be used to retrieve the state of the\n * {@link GasPricesController}.\n */\nexport type GasPricesControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n GasPricesControllerState\n>;\n\n/**\n * The action which can be used to update gas prices.\n */\nexport type GasPricesControllerUpdateGasPricesAction = {\n type: `${typeof controllerName}:updateGasPrices`;\n handler: GasPricesController['updateGasPrices'];\n};\n\n/**\n * All actions that {@link GasPricesController} registers, to be called\n * externally.\n */\nexport type GasPricesControllerActions =\n | GasPricesControllerGetStateAction\n | GasPricesControllerUpdateGasPricesAction;\n\n/**\n * All actions that {@link GasPricesController} calls internally.\n */\ntype AllowedActions = NetworkControllerGetStateAction;\n\n/**\n * The event that {@link GasPricesController} publishes when updating state.\n */\nexport type GasPricesControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n GasPricesControllerState\n>;\n\n/**\n * All events that {@link GasPricesController} publishes, to be subscribed to\n * externally.\n */\nexport type GasPricesControllerEvents = GasPricesControllerStateChangeEvent;\n\n/**\n * All events that {@link GasPricesController} subscribes to internally.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link GasPricesController}.\n */\nexport type GasPricesControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n GasPricesControllerActions | AllowedActions,\n GasPricesControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/**\n * Constructs the default {@link GasPricesController} 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 GasPricesController} state.\n */\nexport function getDefaultGasPricesControllerState(): GasPricesControllerState {\n return {\n gasPricesByChainId: {},\n };\n}\n\n// === CONTROLLER DEFINITION ===\n\n/**\n * `GasPricesController` fetches and persists gas prices for various chains.\n *\n * @example\n *\n * ``` ts\n * import { Messenger } from '@metamask/base-controller';\n * import {\n * GasPricesController,\n * GasPricesService\n * } from '@metamask/example-controllers';\n * import type {\n * GasPricesControllerActions,\n * GasPricesControllerEvents\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 GasPricesService({ fetch });\n * const rootMessenger = new Messenger<\n * GasPricesControllerActions | NetworkControllerGetStateAction,\n * GasPricesControllerEvents\n * >();\n * const gasPricesMessenger = rootMessenger.getRestricted({\n * name: 'GasPricesController',\n * allowedActions: ['NetworkController:getState'],\n * allowedEvents: [],\n * });\n * const gasPricesController = new GasPricesController({\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 GasPricesController extends BaseController<\n typeof controllerName,\n GasPricesControllerState,\n GasPricesControllerMessenger\n> {\n /**\n * The service object that is used to obtain gas prices.\n */\n readonly #gasPricesService: AbstractGasPricesService;\n\n /**\n * Constructs a new {@link GasPricesController}.\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: GasPricesControllerMessenger;\n state?: Partial<GasPricesControllerState>;\n gasPricesService: AbstractGasPricesService;\n }) {\n super({\n messenger,\n metadata: gasPricesControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultGasPricesControllerState(),\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"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=abstract-gas-prices-service.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstract-gas-prices-service.cjs","sourceRoot":"","sources":["../../../src/gas-prices-service/abstract-gas-prices-service.ts"],"names":[],"mappings":"","sourcesContent":["import type { PublicInterface } from '@metamask/utils';\n\nimport type { GasPricesService } from './gas-prices-service';\n\n/**\n * A service object which is responsible for fetching gas prices.\n */\nexport type AbstractGasPricesService = PublicInterface<GasPricesService>;\n"]}
@@ -0,0 +1,7 @@
1
+ import type { PublicInterface } from "@metamask/utils";
2
+ import type { GasPricesService } from "./gas-prices-service.cjs";
3
+ /**
4
+ * A service object which is responsible for fetching gas prices.
5
+ */
6
+ export type AbstractGasPricesService = PublicInterface<GasPricesService>;
7
+ //# sourceMappingURL=abstract-gas-prices-service.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstract-gas-prices-service.d.cts","sourceRoot":"","sources":["../../../src/gas-prices-service/abstract-gas-prices-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,wBAAwB;AAEvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,iCAA6B;AAE7D;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { PublicInterface } from "@metamask/utils";
2
+ import type { GasPricesService } from "./gas-prices-service.mjs";
3
+ /**
4
+ * A service object which is responsible for fetching gas prices.
5
+ */
6
+ export type AbstractGasPricesService = PublicInterface<GasPricesService>;
7
+ //# sourceMappingURL=abstract-gas-prices-service.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstract-gas-prices-service.d.mts","sourceRoot":"","sources":["../../../src/gas-prices-service/abstract-gas-prices-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,wBAAwB;AAEvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,iCAA6B;AAE7D;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=abstract-gas-prices-service.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstract-gas-prices-service.mjs","sourceRoot":"","sources":["../../../src/gas-prices-service/abstract-gas-prices-service.ts"],"names":[],"mappings":"","sourcesContent":["import type { PublicInterface } from '@metamask/utils';\n\nimport type { GasPricesService } from './gas-prices-service';\n\n/**\n * A service object which is responsible for fetching gas prices.\n */\nexport type AbstractGasPricesService = PublicInterface<GasPricesService>;\n"]}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _GasPricesService_fetch;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.GasPricesService = void 0;
16
+ /**
17
+ * This service object is responsible for fetching gas prices via an API.
18
+ *
19
+ * @example
20
+ *
21
+ * On its own:
22
+ *
23
+ * ``` ts
24
+ * const gasPricesService = new GasPricesService({ fetch });
25
+ * // Fetch gas prices for Mainnet
26
+ * const gasPricesResponse = await gasPricesService.fetchGasPrices('0x1');
27
+ * // ... Do something with the response ...
28
+ * ```
29
+ *
30
+ * In conjunction with `GasPricesController`:
31
+ *
32
+ * ``` ts
33
+ * const gasPricesService = new GasPricesService({ fetch });
34
+ * const gasPricesController = new GasPricesController({
35
+ * // ... state, messenger, etc. ...
36
+ * gasPricesService,
37
+ * });
38
+ * // This will use the service object internally
39
+ * gasPricesController.updateGasPrices();
40
+ * ```
41
+ */
42
+ class GasPricesService {
43
+ /**
44
+ * Constructs a new GasPricesService object.
45
+ *
46
+ * @param args - The arguments.
47
+ * @param args.fetch - A function that can be used to make an HTTP request.
48
+ * If your JavaScript environment supports `fetch` natively, you'll probably
49
+ * want to pass that; otherwise you can pass an equivalent (such as `fetch`
50
+ * via `node-fetch`).
51
+ */
52
+ constructor({ fetch: fetchFunction }) {
53
+ _GasPricesService_fetch.set(this, void 0);
54
+ __classPrivateFieldSet(this, _GasPricesService_fetch, fetchFunction, "f");
55
+ }
56
+ /**
57
+ * Makes a request to the API in order to retrieve gas prices for a particular
58
+ * chain.
59
+ *
60
+ * @param chainId - The chain ID for which you want to fetch gas prices.
61
+ * @returns The gas prices for the given chain.
62
+ */
63
+ async fetchGasPrices(chainId) {
64
+ const response = await __classPrivateFieldGet(this, _GasPricesService_fetch, "f").call(this, `https://example.com/gas-prices/${chainId}.json`);
65
+ // Type assertion: We have to assume the shape of the response data.
66
+ const gasPricesResponse = (await response.json());
67
+ return gasPricesResponse.data;
68
+ }
69
+ }
70
+ exports.GasPricesService = GasPricesService;
71
+ _GasPricesService_fetch = new WeakMap();
72
+ //# sourceMappingURL=gas-prices-service.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gas-prices-service.cjs","sourceRoot":"","sources":["../../../src/gas-prices-service/gas-prices-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAaA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAa,gBAAgB;IAG3B;;;;;;;;OAQG;IACH,YAAY,EAAE,KAAK,EAAE,aAAa,EAA2B;QAXpD,0CAAqB;QAY5B,uBAAA,IAAI,2BAAU,aAAa,MAAA,CAAC;IAC9B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,cAAc,CAAC,OAAY;QAC/B,MAAM,QAAQ,GAAG,MAAM,uBAAA,IAAI,+BAAO,MAAX,IAAI,EACzB,kCAAkC,OAAO,OAAO,CACjD,CAAC;QACF,oEAAoE;QACpE,MAAM,iBAAiB,GACrB,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAiC,CAAC;QAC1D,OAAO,iBAAiB,CAAC,IAAI,CAAC;IAChC,CAAC;CACF;AAhCD,4CAgCC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\n/**\n * What the API endpoint returns.\n */\ntype GasPricesResponse = {\n data: {\n low: number;\n average: number;\n high: number;\n };\n};\n\n/**\n * This service object is responsible for fetching gas prices via an API.\n *\n * @example\n *\n * On its own:\n *\n * ``` ts\n * const gasPricesService = new GasPricesService({ fetch });\n * // Fetch gas prices for Mainnet\n * const gasPricesResponse = await gasPricesService.fetchGasPrices('0x1');\n * // ... Do something with the response ...\n * ```\n *\n * In conjunction with `GasPricesController`:\n *\n * ``` ts\n * const gasPricesService = new GasPricesService({ fetch });\n * const gasPricesController = new GasPricesController({\n * // ... state, messenger, etc. ...\n * gasPricesService,\n * });\n * // This will use the service object internally\n * gasPricesController.updateGasPrices();\n * ```\n */\nexport class GasPricesService {\n readonly #fetch: typeof fetch;\n\n /**\n * Constructs a new GasPricesService object.\n *\n * @param args - The arguments.\n * @param args.fetch - A function that can be used to make an HTTP request.\n * If your JavaScript environment supports `fetch` natively, you'll probably\n * want to pass that; otherwise you can pass an equivalent (such as `fetch`\n * via `node-fetch`).\n */\n constructor({ fetch: fetchFunction }: { fetch: typeof fetch }) {\n this.#fetch = fetchFunction;\n }\n\n /**\n * Makes a request to the API in order to retrieve gas prices for a particular\n * chain.\n *\n * @param chainId - The chain ID for which you want to fetch gas prices.\n * @returns The gas prices for the given chain.\n */\n async fetchGasPrices(chainId: Hex) {\n const response = await this.#fetch(\n `https://example.com/gas-prices/${chainId}.json`,\n );\n // Type assertion: We have to assume the shape of the response data.\n const gasPricesResponse =\n (await response.json()) as unknown as GasPricesResponse;\n return gasPricesResponse.data;\n }\n}\n"]}
@@ -0,0 +1,55 @@
1
+ import type { Hex } from "@metamask/utils";
2
+ /**
3
+ * This service object is responsible for fetching gas prices via an API.
4
+ *
5
+ * @example
6
+ *
7
+ * On its own:
8
+ *
9
+ * ``` ts
10
+ * const gasPricesService = new GasPricesService({ fetch });
11
+ * // Fetch gas prices for Mainnet
12
+ * const gasPricesResponse = await gasPricesService.fetchGasPrices('0x1');
13
+ * // ... Do something with the response ...
14
+ * ```
15
+ *
16
+ * In conjunction with `GasPricesController`:
17
+ *
18
+ * ``` ts
19
+ * const gasPricesService = new GasPricesService({ fetch });
20
+ * const gasPricesController = new GasPricesController({
21
+ * // ... state, messenger, etc. ...
22
+ * gasPricesService,
23
+ * });
24
+ * // This will use the service object internally
25
+ * gasPricesController.updateGasPrices();
26
+ * ```
27
+ */
28
+ export declare class GasPricesService {
29
+ #private;
30
+ /**
31
+ * Constructs a new GasPricesService object.
32
+ *
33
+ * @param args - The arguments.
34
+ * @param args.fetch - A function that can be used to make an HTTP request.
35
+ * If your JavaScript environment supports `fetch` natively, you'll probably
36
+ * want to pass that; otherwise you can pass an equivalent (such as `fetch`
37
+ * via `node-fetch`).
38
+ */
39
+ constructor({ fetch: fetchFunction }: {
40
+ fetch: typeof fetch;
41
+ });
42
+ /**
43
+ * Makes a request to the API in order to retrieve gas prices for a particular
44
+ * chain.
45
+ *
46
+ * @param chainId - The chain ID for which you want to fetch gas prices.
47
+ * @returns The gas prices for the given chain.
48
+ */
49
+ fetchGasPrices(chainId: Hex): Promise<{
50
+ low: number;
51
+ average: number;
52
+ high: number;
53
+ }>;
54
+ }
55
+ //# sourceMappingURL=gas-prices-service.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gas-prices-service.d.cts","sourceRoot":"","sources":["../../../src/gas-prices-service/gas-prices-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAa3C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,gBAAgB;;IAG3B;;;;;;;;OAQG;gBACS,EAAE,KAAK,EAAE,aAAa,EAAE,EAAE;QAAE,KAAK,EAAE,OAAO,KAAK,CAAA;KAAE;IAI7D;;;;;;OAMG;IACG,cAAc,CAAC,OAAO,EAAE,GAAG;;;;;CASlC"}
@@ -0,0 +1,55 @@
1
+ import type { Hex } from "@metamask/utils";
2
+ /**
3
+ * This service object is responsible for fetching gas prices via an API.
4
+ *
5
+ * @example
6
+ *
7
+ * On its own:
8
+ *
9
+ * ``` ts
10
+ * const gasPricesService = new GasPricesService({ fetch });
11
+ * // Fetch gas prices for Mainnet
12
+ * const gasPricesResponse = await gasPricesService.fetchGasPrices('0x1');
13
+ * // ... Do something with the response ...
14
+ * ```
15
+ *
16
+ * In conjunction with `GasPricesController`:
17
+ *
18
+ * ``` ts
19
+ * const gasPricesService = new GasPricesService({ fetch });
20
+ * const gasPricesController = new GasPricesController({
21
+ * // ... state, messenger, etc. ...
22
+ * gasPricesService,
23
+ * });
24
+ * // This will use the service object internally
25
+ * gasPricesController.updateGasPrices();
26
+ * ```
27
+ */
28
+ export declare class GasPricesService {
29
+ #private;
30
+ /**
31
+ * Constructs a new GasPricesService object.
32
+ *
33
+ * @param args - The arguments.
34
+ * @param args.fetch - A function that can be used to make an HTTP request.
35
+ * If your JavaScript environment supports `fetch` natively, you'll probably
36
+ * want to pass that; otherwise you can pass an equivalent (such as `fetch`
37
+ * via `node-fetch`).
38
+ */
39
+ constructor({ fetch: fetchFunction }: {
40
+ fetch: typeof fetch;
41
+ });
42
+ /**
43
+ * Makes a request to the API in order to retrieve gas prices for a particular
44
+ * chain.
45
+ *
46
+ * @param chainId - The chain ID for which you want to fetch gas prices.
47
+ * @returns The gas prices for the given chain.
48
+ */
49
+ fetchGasPrices(chainId: Hex): Promise<{
50
+ low: number;
51
+ average: number;
52
+ high: number;
53
+ }>;
54
+ }
55
+ //# sourceMappingURL=gas-prices-service.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gas-prices-service.d.mts","sourceRoot":"","sources":["../../../src/gas-prices-service/gas-prices-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAa3C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,gBAAgB;;IAG3B;;;;;;;;OAQG;gBACS,EAAE,KAAK,EAAE,aAAa,EAAE,EAAE;QAAE,KAAK,EAAE,OAAO,KAAK,CAAA;KAAE;IAI7D;;;;;;OAMG;IACG,cAAc,CAAC,OAAO,EAAE,GAAG;;;;;CASlC"}
@@ -0,0 +1,68 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _GasPricesService_fetch;
13
+ /**
14
+ * This service object is responsible for fetching gas prices via an API.
15
+ *
16
+ * @example
17
+ *
18
+ * On its own:
19
+ *
20
+ * ``` ts
21
+ * const gasPricesService = new GasPricesService({ fetch });
22
+ * // Fetch gas prices for Mainnet
23
+ * const gasPricesResponse = await gasPricesService.fetchGasPrices('0x1');
24
+ * // ... Do something with the response ...
25
+ * ```
26
+ *
27
+ * In conjunction with `GasPricesController`:
28
+ *
29
+ * ``` ts
30
+ * const gasPricesService = new GasPricesService({ fetch });
31
+ * const gasPricesController = new GasPricesController({
32
+ * // ... state, messenger, etc. ...
33
+ * gasPricesService,
34
+ * });
35
+ * // This will use the service object internally
36
+ * gasPricesController.updateGasPrices();
37
+ * ```
38
+ */
39
+ export class GasPricesService {
40
+ /**
41
+ * Constructs a new GasPricesService object.
42
+ *
43
+ * @param args - The arguments.
44
+ * @param args.fetch - A function that can be used to make an HTTP request.
45
+ * If your JavaScript environment supports `fetch` natively, you'll probably
46
+ * want to pass that; otherwise you can pass an equivalent (such as `fetch`
47
+ * via `node-fetch`).
48
+ */
49
+ constructor({ fetch: fetchFunction }) {
50
+ _GasPricesService_fetch.set(this, void 0);
51
+ __classPrivateFieldSet(this, _GasPricesService_fetch, fetchFunction, "f");
52
+ }
53
+ /**
54
+ * Makes a request to the API in order to retrieve gas prices for a particular
55
+ * chain.
56
+ *
57
+ * @param chainId - The chain ID for which you want to fetch gas prices.
58
+ * @returns The gas prices for the given chain.
59
+ */
60
+ async fetchGasPrices(chainId) {
61
+ const response = await __classPrivateFieldGet(this, _GasPricesService_fetch, "f").call(this, `https://example.com/gas-prices/${chainId}.json`);
62
+ // Type assertion: We have to assume the shape of the response data.
63
+ const gasPricesResponse = (await response.json());
64
+ return gasPricesResponse.data;
65
+ }
66
+ }
67
+ _GasPricesService_fetch = new WeakMap();
68
+ //# sourceMappingURL=gas-prices-service.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gas-prices-service.mjs","sourceRoot":"","sources":["../../../src/gas-prices-service/gas-prices-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAaA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,gBAAgB;IAG3B;;;;;;;;OAQG;IACH,YAAY,EAAE,KAAK,EAAE,aAAa,EAA2B;QAXpD,0CAAqB;QAY5B,uBAAA,IAAI,2BAAU,aAAa,MAAA,CAAC;IAC9B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,cAAc,CAAC,OAAY;QAC/B,MAAM,QAAQ,GAAG,MAAM,uBAAA,IAAI,+BAAO,MAAX,IAAI,EACzB,kCAAkC,OAAO,OAAO,CACjD,CAAC;QACF,oEAAoE;QACpE,MAAM,iBAAiB,GACrB,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAiC,CAAC;QAC1D,OAAO,iBAAiB,CAAC,IAAI,CAAC;IAChC,CAAC;CACF","sourcesContent":["import type { Hex } from '@metamask/utils';\n\n/**\n * What the API endpoint returns.\n */\ntype GasPricesResponse = {\n data: {\n low: number;\n average: number;\n high: number;\n };\n};\n\n/**\n * This service object is responsible for fetching gas prices via an API.\n *\n * @example\n *\n * On its own:\n *\n * ``` ts\n * const gasPricesService = new GasPricesService({ fetch });\n * // Fetch gas prices for Mainnet\n * const gasPricesResponse = await gasPricesService.fetchGasPrices('0x1');\n * // ... Do something with the response ...\n * ```\n *\n * In conjunction with `GasPricesController`:\n *\n * ``` ts\n * const gasPricesService = new GasPricesService({ fetch });\n * const gasPricesController = new GasPricesController({\n * // ... state, messenger, etc. ...\n * gasPricesService,\n * });\n * // This will use the service object internally\n * gasPricesController.updateGasPrices();\n * ```\n */\nexport class GasPricesService {\n readonly #fetch: typeof fetch;\n\n /**\n * Constructs a new GasPricesService object.\n *\n * @param args - The arguments.\n * @param args.fetch - A function that can be used to make an HTTP request.\n * If your JavaScript environment supports `fetch` natively, you'll probably\n * want to pass that; otherwise you can pass an equivalent (such as `fetch`\n * via `node-fetch`).\n */\n constructor({ fetch: fetchFunction }: { fetch: typeof fetch }) {\n this.#fetch = fetchFunction;\n }\n\n /**\n * Makes a request to the API in order to retrieve gas prices for a particular\n * chain.\n *\n * @param chainId - The chain ID for which you want to fetch gas prices.\n * @returns The gas prices for the given chain.\n */\n async fetchGasPrices(chainId: Hex) {\n const response = await this.#fetch(\n `https://example.com/gas-prices/${chainId}.json`,\n );\n // Type assertion: We have to assume the shape of the response data.\n const gasPricesResponse =\n (await response.json()) as unknown as GasPricesResponse;\n return gasPricesResponse.data;\n }\n}\n"]}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GasPricesService = exports.PetNamesController = exports.getDefaultPetNamesControllerState = exports.GasPricesController = exports.getDefaultGasPricesControllerState = void 0;
4
+ var gas_prices_controller_1 = require("./gas-prices-controller.cjs");
5
+ Object.defineProperty(exports, "getDefaultGasPricesControllerState", { enumerable: true, get: function () { return gas_prices_controller_1.getDefaultGasPricesControllerState; } });
6
+ Object.defineProperty(exports, "GasPricesController", { enumerable: true, get: function () { return gas_prices_controller_1.GasPricesController; } });
7
+ var pet_names_controller_1 = require("./pet-names-controller.cjs");
8
+ Object.defineProperty(exports, "getDefaultPetNamesControllerState", { enumerable: true, get: function () { return pet_names_controller_1.getDefaultPetNamesControllerState; } });
9
+ Object.defineProperty(exports, "PetNamesController", { enumerable: true, get: function () { return pet_names_controller_1.PetNamesController; } });
10
+ var gas_prices_service_1 = require("./gas-prices-service/gas-prices-service.cjs");
11
+ Object.defineProperty(exports, "GasPricesService", { enumerable: true, get: function () { return gas_prices_service_1.GasPricesService; } });
12
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAQA,qEAGiC;AAF/B,2IAAA,kCAAkC,OAAA;AAClC,4HAAA,mBAAmB,OAAA;AAUrB,mEAGgC;AAF9B,yIAAA,iCAAiC,OAAA;AACjC,0HAAA,kBAAkB,OAAA;AAEpB,kFAA2E;AAAlE,sHAAA,gBAAgB,OAAA","sourcesContent":["export type {\n GasPricesControllerActions,\n GasPricesControllerEvents,\n GasPricesControllerGetStateAction,\n GasPricesControllerMessenger,\n GasPricesControllerState,\n GasPricesControllerStateChangeEvent,\n} from './gas-prices-controller';\nexport {\n getDefaultGasPricesControllerState,\n GasPricesController,\n} from './gas-prices-controller';\nexport type {\n PetNamesControllerActions,\n PetNamesControllerEvents,\n PetNamesControllerGetStateAction,\n PetNamesControllerMessenger,\n PetNamesControllerState,\n PetNamesControllerStateChangeEvent,\n} from './pet-names-controller';\nexport {\n getDefaultPetNamesControllerState,\n PetNamesController,\n} from './pet-names-controller';\nexport { GasPricesService } from './gas-prices-service/gas-prices-service';\n"]}
@@ -0,0 +1,6 @@
1
+ export type { GasPricesControllerActions, GasPricesControllerEvents, GasPricesControllerGetStateAction, GasPricesControllerMessenger, GasPricesControllerState, GasPricesControllerStateChangeEvent, } from "./gas-prices-controller.cjs";
2
+ export { getDefaultGasPricesControllerState, GasPricesController, } from "./gas-prices-controller.cjs";
3
+ export type { PetNamesControllerActions, PetNamesControllerEvents, PetNamesControllerGetStateAction, PetNamesControllerMessenger, PetNamesControllerState, PetNamesControllerStateChangeEvent, } from "./pet-names-controller.cjs";
4
+ export { getDefaultPetNamesControllerState, PetNamesController, } from "./pet-names-controller.cjs";
5
+ export { GasPricesService } from "./gas-prices-service/gas-prices-service.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,0BAA0B,EAC1B,yBAAyB,EACzB,iCAAiC,EACjC,4BAA4B,EAC5B,wBAAwB,EACxB,mCAAmC,GACpC,oCAAgC;AACjC,OAAO,EACL,kCAAkC,EAClC,mBAAmB,GACpB,oCAAgC;AACjC,YAAY,EACV,yBAAyB,EACzB,wBAAwB,EACxB,gCAAgC,EAChC,2BAA2B,EAC3B,uBAAuB,EACvB,kCAAkC,GACnC,mCAA+B;AAChC,OAAO,EACL,iCAAiC,EACjC,kBAAkB,GACnB,mCAA+B;AAChC,OAAO,EAAE,gBAAgB,EAAE,oDAAgD"}
@@ -0,0 +1,6 @@
1
+ export type { GasPricesControllerActions, GasPricesControllerEvents, GasPricesControllerGetStateAction, GasPricesControllerMessenger, GasPricesControllerState, GasPricesControllerStateChangeEvent, } from "./gas-prices-controller.mjs";
2
+ export { getDefaultGasPricesControllerState, GasPricesController, } from "./gas-prices-controller.mjs";
3
+ export type { PetNamesControllerActions, PetNamesControllerEvents, PetNamesControllerGetStateAction, PetNamesControllerMessenger, PetNamesControllerState, PetNamesControllerStateChangeEvent, } from "./pet-names-controller.mjs";
4
+ export { getDefaultPetNamesControllerState, PetNamesController, } from "./pet-names-controller.mjs";
5
+ export { GasPricesService } from "./gas-prices-service/gas-prices-service.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,0BAA0B,EAC1B,yBAAyB,EACzB,iCAAiC,EACjC,4BAA4B,EAC5B,wBAAwB,EACxB,mCAAmC,GACpC,oCAAgC;AACjC,OAAO,EACL,kCAAkC,EAClC,mBAAmB,GACpB,oCAAgC;AACjC,YAAY,EACV,yBAAyB,EACzB,wBAAwB,EACxB,gCAAgC,EAChC,2BAA2B,EAC3B,uBAAuB,EACvB,kCAAkC,GACnC,mCAA+B;AAChC,OAAO,EACL,iCAAiC,EACjC,kBAAkB,GACnB,mCAA+B;AAChC,OAAO,EAAE,gBAAgB,EAAE,oDAAgD"}
@@ -0,0 +1,4 @@
1
+ export { getDefaultGasPricesControllerState, GasPricesController } from "./gas-prices-controller.mjs";
2
+ export { getDefaultPetNamesControllerState, PetNamesController } from "./pet-names-controller.mjs";
3
+ export { GasPricesService } from "./gas-prices-service/gas-prices-service.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,kCAAkC,EAClC,mBAAmB,EACpB,oCAAgC;AASjC,OAAO,EACL,iCAAiC,EACjC,kBAAkB,EACnB,mCAA+B;AAChC,OAAO,EAAE,gBAAgB,EAAE,oDAAgD","sourcesContent":["export type {\n GasPricesControllerActions,\n GasPricesControllerEvents,\n GasPricesControllerGetStateAction,\n GasPricesControllerMessenger,\n GasPricesControllerState,\n GasPricesControllerStateChangeEvent,\n} from './gas-prices-controller';\nexport {\n getDefaultGasPricesControllerState,\n GasPricesController,\n} from './gas-prices-controller';\nexport type {\n PetNamesControllerActions,\n PetNamesControllerEvents,\n PetNamesControllerGetStateAction,\n PetNamesControllerMessenger,\n PetNamesControllerState,\n PetNamesControllerStateChangeEvent,\n} from './pet-names-controller';\nexport {\n getDefaultPetNamesControllerState,\n PetNamesController,\n} from './pet-names-controller';\nexport { GasPricesService } from './gas-prices-service/gas-prices-service';\n"]}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDefaultNetworkControllerState = void 0;
4
+ /**
5
+ * Constructs a default representation of a theoretical NetworkController's
6
+ * state.
7
+ *
8
+ * Note that this package does not supply a NetworkController; this type is only
9
+ * here so it is possible to write a complete example.
10
+ *
11
+ * @returns The default network controller state.
12
+ */
13
+ function getDefaultNetworkControllerState() {
14
+ return {
15
+ networkName: 'Some Network',
16
+ chainId: '0x1',
17
+ };
18
+ }
19
+ exports.getDefaultNetworkControllerState = getDefaultNetworkControllerState;
20
+ //# sourceMappingURL=network-controller-types.cjs.map
@@ -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,34 @@
1
+ import type { Hex } from "@metamask/utils";
2
+ /**
3
+ * Describes the shape of the state object for a theoretical NetworkController.
4
+ *
5
+ * Note that this package does not supply a NetworkController; this type is only
6
+ * here so it is possible to write a complete example.
7
+ */
8
+ type NetworkControllerState = {
9
+ networkName: string;
10
+ chainId: Hex;
11
+ };
12
+ /**
13
+ * Constructs a default representation of a theoretical NetworkController's
14
+ * state.
15
+ *
16
+ * Note that this package does not supply a NetworkController; this type is only
17
+ * here so it is possible to write a complete example.
18
+ *
19
+ * @returns The default network controller state.
20
+ */
21
+ export declare function getDefaultNetworkControllerState(): NetworkControllerState;
22
+ /**
23
+ * The action which can be used to obtain the state for a theoretical
24
+ * NetworkController.
25
+ *
26
+ * Note that this package does not supply a NetworkController; this type is only
27
+ * here so it is possible to write a complete example.
28
+ */
29
+ export type NetworkControllerGetStateAction = {
30
+ type: 'NetworkController:getState';
31
+ handler: () => NetworkControllerState;
32
+ };
33
+ export {};
34
+ //# sourceMappingURL=network-controller-types.d.cts.map
@@ -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,34 @@
1
+ import type { Hex } from "@metamask/utils";
2
+ /**
3
+ * Describes the shape of the state object for a theoretical NetworkController.
4
+ *
5
+ * Note that this package does not supply a NetworkController; this type is only
6
+ * here so it is possible to write a complete example.
7
+ */
8
+ type NetworkControllerState = {
9
+ networkName: string;
10
+ chainId: Hex;
11
+ };
12
+ /**
13
+ * Constructs a default representation of a theoretical NetworkController's
14
+ * state.
15
+ *
16
+ * Note that this package does not supply a NetworkController; this type is only
17
+ * here so it is possible to write a complete example.
18
+ *
19
+ * @returns The default network controller state.
20
+ */
21
+ export declare function getDefaultNetworkControllerState(): NetworkControllerState;
22
+ /**
23
+ * The action which can be used to obtain the state for a theoretical
24
+ * NetworkController.
25
+ *
26
+ * Note that this package does not supply a NetworkController; this type is only
27
+ * here so it is possible to write a complete example.
28
+ */
29
+ export type NetworkControllerGetStateAction = {
30
+ type: 'NetworkController:getState';
31
+ handler: () => NetworkControllerState;
32
+ };
33
+ export {};
34
+ //# sourceMappingURL=network-controller-types.d.mts.map
@@ -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,16 @@
1
+ /**
2
+ * Constructs a default representation of a theoretical NetworkController's
3
+ * state.
4
+ *
5
+ * Note that this package does not supply a NetworkController; this type is only
6
+ * here so it is possible to write a complete example.
7
+ *
8
+ * @returns The default network controller state.
9
+ */
10
+ export function getDefaultNetworkControllerState() {
11
+ return {
12
+ networkName: 'Some Network',
13
+ chainId: '0x1',
14
+ };
15
+ }
16
+ //# sourceMappingURL=network-controller-types.mjs.map
@@ -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"]}