@metamask-previews/sample-controllers 1.0.0-preview-aa8c4291 → 1.0.0-preview-e821953
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -1
- package/dist/index.cjs +5 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +7 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +1 -1
- package/dist/sample-gas-prices-controller-method-action-types.cjs +7 -0
- package/dist/sample-gas-prices-controller-method-action-types.cjs.map +1 -0
- package/dist/sample-gas-prices-controller-method-action-types.d.cts +21 -0
- package/dist/sample-gas-prices-controller-method-action-types.d.cts.map +1 -0
- package/dist/sample-gas-prices-controller-method-action-types.d.mts +21 -0
- package/dist/sample-gas-prices-controller-method-action-types.d.mts.map +1 -0
- package/dist/sample-gas-prices-controller-method-action-types.mjs +6 -0
- package/dist/sample-gas-prices-controller-method-action-types.mjs.map +1 -0
- package/dist/sample-gas-prices-controller.cjs +77 -39
- package/dist/sample-gas-prices-controller.cjs.map +1 -1
- package/dist/sample-gas-prices-controller.d.cts +74 -59
- package/dist/sample-gas-prices-controller.d.cts.map +1 -1
- package/dist/sample-gas-prices-controller.d.mts +74 -59
- package/dist/sample-gas-prices-controller.d.mts.map +1 -1
- package/dist/sample-gas-prices-controller.mjs +77 -39
- package/dist/sample-gas-prices-controller.mjs.map +1 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.cjs +7 -0
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.cjs.map +1 -0
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.cts +21 -0
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.cts.map +1 -0
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.mts +21 -0
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.mts.map +1 -0
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.mjs +6 -0
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.mjs.map +1 -0
- package/dist/sample-gas-prices-service/sample-gas-prices-service.cjs +135 -29
- package/dist/sample-gas-prices-service/sample-gas-prices-service.cjs.map +1 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service.d.cts +122 -28
- package/dist/sample-gas-prices-service/sample-gas-prices-service.d.cts.map +1 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service.d.mts +122 -28
- package/dist/sample-gas-prices-service/sample-gas-prices-service.d.mts.map +1 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service.mjs +134 -28
- package/dist/sample-gas-prices-service/sample-gas-prices-service.mjs.map +1 -1
- package/dist/sample-petnames-controller-method-action-types.cjs +7 -0
- package/dist/sample-petnames-controller-method-action-types.cjs.map +1 -0
- package/dist/sample-petnames-controller-method-action-types.d.cts +22 -0
- package/dist/sample-petnames-controller-method-action-types.d.cts.map +1 -0
- package/dist/sample-petnames-controller-method-action-types.d.mts +22 -0
- package/dist/sample-petnames-controller-method-action-types.d.mts.map +1 -0
- package/dist/sample-petnames-controller-method-action-types.mjs +6 -0
- package/dist/sample-petnames-controller-method-action-types.mjs.map +1 -0
- package/dist/sample-petnames-controller.cjs +24 -13
- package/dist/sample-petnames-controller.cjs.map +1 -1
- package/dist/sample-petnames-controller.d.cts +38 -23
- package/dist/sample-petnames-controller.d.cts.map +1 -1
- package/dist/sample-petnames-controller.d.mts +38 -23
- package/dist/sample-petnames-controller.d.mts.map +1 -1
- package/dist/sample-petnames-controller.mjs +23 -13
- package/dist/sample-petnames-controller.mjs.map +1 -1
- package/package.json +2 -1
- package/dist/network-controller-types.cjs +0 -20
- package/dist/network-controller-types.cjs.map +0 -1
- package/dist/network-controller-types.d.cts +0 -34
- package/dist/network-controller-types.d.cts.map +0 -1
- package/dist/network-controller-types.d.mts +0 -34
- package/dist/network-controller-types.d.mts.map +0 -1
- package/dist/network-controller-types.mjs +0 -16
- package/dist/network-controller-types.mjs.map +0 -1
- package/dist/sample-gas-prices-service/index.cjs +0 -6
- package/dist/sample-gas-prices-service/index.cjs.map +0 -1
- package/dist/sample-gas-prices-service/index.d.cts +0 -3
- package/dist/sample-gas-prices-service/index.d.cts.map +0 -1
- package/dist/sample-gas-prices-service/index.d.mts +0 -3
- package/dist/sample-gas-prices-service/index.d.mts.map +0 -1
- package/dist/sample-gas-prices-service/index.mjs +0 -2
- package/dist/sample-gas-prices-service/index.mjs.map +0 -1
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.cjs +0 -3
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.cjs.map +0 -1
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.cts +0 -7
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.cts.map +0 -1
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.mts +0 -7
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.d.mts.map +0 -1
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.mjs +0 -2
- package/dist/sample-gas-prices-service/sample-abstract-gas-prices-service.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sample-gas-prices-controller.mjs","sourceRoot":"","sources":["../src/sample-gas-prices-controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAM3D,kBAAkB;AAElB;;;;GAIG;AACH,MAAM,CAAC,MAAM,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,MAAM,UAAU,wCAAwC;IACtD,OAAO;QACL,kBAAkB,EAAE,EAAE;KACvB,CAAC;AACJ,CAAC;AAED,gCAAgC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,OAAO,yBAA0B,SAAQ,cAI9C;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,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,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,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","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
|
+
{"version":3,"file":"sample-gas-prices-controller.mjs","sourceRoot":"","sources":["../src/sample-gas-prices-controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAW3D,kBAAkB;AAElB;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,2BAA2B,CAAC;AAsC1D;;GAEG;AACH,MAAM,2BAA2B,GAAG;IAClC,kBAAkB,EAAE;QAClB,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,KAAK;KACjB;CACsD,CAAC;AAE1D;;;;;;;GAOG;AACH,MAAM,UAAU,wCAAwC;IACtD,OAAO;QACL,kBAAkB,EAAE,EAAE;KACvB,CAAC;AACJ,CAAC;AAED,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG,CAAC,iBAAiB,CAAU,CAAC;AAyD/D,gCAAgC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,MAAM,OAAO,yBAA0B,SAAQ,cAI9C;IAMC;;;;;;;OAOG;IACH,YAAY,EACV,SAAS,EACT,KAAK,GAIN;QACC,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,2BAA2B;YACrC,IAAI,EAAE,cAAc;YACpB,KAAK,EAAE;gBACL,GAAG,wCAAwC,EAAE;gBAC7C,GAAG,KAAK;aACT;SACF,CAAC,CAAC;;QA5BL;;WAEG;QACH,6DAAkC;QA2BhC,IAAI,CAAC,eAAe,CAAC,4BAA4B,CAC/C,IAAI,EACJ,yBAAyB,CAC1B,CAAC;QAEF,IAAI,CAAC,eAAe,CAAC,SAAS,CAC5B,+BAA+B,EAC/B,uBAAA,IAAI,wGAAiC,CAAC,IAAI,CAAC,IAAI,CAAC,EAChD,CAAC,sBAAsB,EAAE,EAAE,CACzB,sBAAsB,CAAC,uBAAuB,CACjD,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,eAAe,CAAC,EAAE,OAAO,EAAoB;QACjD,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CACvD,uCAAuC,EACvC,OAAO,CACR,CAAC;QAEF,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;CAuBF;;AArBC;;;;;GAKG;AACH,KAAK,qEACH,uBAAwC;IAExC,MAAM,EACJ,aAAa,EAAE,EAAE,OAAO,EAAE,GAC3B,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAC3B,wCAAwC,EACxC,uBAAuB,CACxB,CAAC;IAEF,IAAI,OAAO,KAAK,uBAAA,IAAI,kDAAiB,EAAE;QACrC,uBAAA,IAAI,8CAAoB,OAAO,MAAA,CAAC;QAChC,MAAM,IAAI,CAAC,eAAe,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;KACzC;AACH,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n NetworkClientId,\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerStateChangeEvent,\n} from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport type { SampleGasPricesControllerMethodActions } from './sample-gas-prices-controller-method-action-types';\nimport type { SampleGasPricesServiceFetchGasPricesAction } from './sample-gas-prices-service/sample-gas-prices-service-method-action-types';\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 * Fetched gas prices categorized by chain ID.\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/**\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// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = ['updateGasPrices'] as const;\n\n/**\n * Retrieves the state of the {@link SampleGasPricesController}.\n */\nexport type SampleGasPricesControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SampleGasPricesControllerState\n>;\n\n/**\n * Actions that {@link SampleGasPricesMessenger} exposes to other consumers.\n */\nexport type SampleGasPricesControllerActions =\n | SampleGasPricesControllerGetStateAction\n | SampleGasPricesControllerMethodActions;\n\n/**\n * Actions from other messengers that {@link SampleGasPricesMessenger} calls.\n */\ntype AllowedActions =\n | NetworkControllerGetNetworkClientByIdAction\n | SampleGasPricesServiceFetchGasPricesAction;\n\n/**\n * Published when the state of {@link SampleGasPricesController} changes.\n */\nexport type SampleGasPricesControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n SampleGasPricesControllerState\n >;\n\n/**\n * Events that {@link SampleGasPricesMessenger} exposes to other consumers.\n */\nexport type SampleGasPricesControllerEvents =\n SampleGasPricesControllerStateChangeEvent;\n\n/**\n * Events from other messengers that {@link SampleGasPricesMessenger} subscribes\n * to.\n */\ntype AllowedEvents = NetworkControllerStateChangeEvent;\n\n/**\n * The messenger 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// === 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 type {\n * NetworkControllerActions,\n * NetworkControllerEvents\n * } from '@metamask/network-controller';\n * import type {\n * SampleGasPricesControllerActions,\n * SampleGasPricesControllerEvents\n * } from '@metamask/example-controllers';\n * import {\n * SampleGasPricesController,\n * SampleGasPricesService,\n * selectGasPrices,\n * } from '@metamask/example-controllers';\n *\n * const globalMessenger = new Messenger<\n * SampleGasPricesServiceActions\n * | SampleGasPricesControllerActions\n * | NetworkControllerActions\n * SampleGasPricesServiceEvents\n * | SampleGasPricesControllerEvents\n * | NetworkControllerEvents\n * >();\n * const gasPricesServiceMessenger = globalMessenger.getRestricted({\n * name: 'SampleGasPricesService',\n * allowedActions: [],\n * allowedEvents: [],\n * });\n * // Instantiate the service to register its actions on the messenger\n * new SampleGasPricesService({\n * messenger: gasPricesServiceMessenger,\n * // We assume you're using this in the browser.\n * fetch,\n * });\n * const gasPricesControllerMessenger = globalMessenger.getRestricted({\n * name: 'SampleGasPricesController',\n * allowedActions: ['NetworkController:getNetworkClientById'],\n * allowedEvents: ['NetworkController:stateChange'],\n * });\n * // Instantiate the controller to register its actions on the messenger\n * new SampleGasPricesController({\n * messenger: gasPricesControllerMessenger,\n * });\n *\n * // Later...\n * await globalMessenger.call(\n * 'SampleGasPricesController:updateGasPrices',\n * { chainId: '0x42' },\n * );\n * const gasPricesControllerState = await globalMessenger.call(\n * 'SampleGasPricesController:getState',\n * );\n * gasPricesControllerState.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 globally selected chain ID.\n */\n #selectedChainId: Hex | undefined;\n\n /**\n * Constructs a new {@link SampleGasPricesController}.\n *\n * @param args - The constructor arguments.\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 */\n constructor({\n messenger,\n state,\n }: {\n messenger: SampleGasPricesControllerMessenger;\n state?: Partial<SampleGasPricesControllerState>;\n }) {\n super({\n messenger,\n metadata: gasPricesControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultSampleGasPricesControllerState(),\n ...state,\n },\n });\n\n this.messagingSystem.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n this.messagingSystem.subscribe(\n 'NetworkController:stateChange',\n this.#onSelectedNetworkClientIdChange.bind(this),\n (networkControllerState) =>\n networkControllerState.selectedNetworkClientId,\n );\n }\n\n /**\n * Fetches the latest gas prices for the given chain and persists them to\n * state.\n *\n * @param args - The arguments to the function.\n * @param args.chainId - The chain ID for which to fetch gas prices.\n */\n async updateGasPrices({ chainId }: { chainId: Hex }) {\n const gasPricesResponse = await this.messagingSystem.call(\n 'SampleGasPricesService:fetchGasPrices',\n chainId,\n );\n\n this.update((state) => {\n state.gasPricesByChainId[chainId] = {\n ...gasPricesResponse,\n fetchedDate: new Date().toISOString(),\n };\n });\n }\n\n /**\n * Callback to call when the globally selected network client ID changes,\n * ensuring that gas prices get updated.\n *\n * @param selectedNetworkClientId - The globally selected network client ID.\n */\n async #onSelectedNetworkClientIdChange(\n selectedNetworkClientId: NetworkClientId,\n ) {\n const {\n configuration: { chainId },\n } = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n );\n\n if (chainId !== this.#selectedChainId) {\n this.#selectedChainId = chainId;\n await this.updateGasPrices({ chainId });\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
4
|
+
* Do not edit manually.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
//# sourceMappingURL=sample-gas-prices-service-method-action-types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sample-gas-prices-service-method-action-types.cjs","sourceRoot":"","sources":["../../src/sample-gas-prices-service/sample-gas-prices-service-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { SampleGasPricesService } from './sample-gas-prices-service';\n\n/**\n * Fetches the latest gas prices for the given chain and persists them to\n * state.\n *\n * @param args - The arguments to the function.\n * @param args.chainId - The chain ID for which to fetch gas prices.\n */\nexport type SampleGasPricesServiceFetchGasPricesAction = {\n type: `SampleGasPricesService:fetchGasPrices`;\n handler: SampleGasPricesService['fetchGasPrices'];\n};\n\n/**\n * Union of all SampleGasPricesService action types.\n */\nexport type SampleGasPricesServiceMethodActions =\n SampleGasPricesServiceFetchGasPricesAction;\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { SampleGasPricesService } from "./sample-gas-prices-service.cjs";
|
|
6
|
+
/**
|
|
7
|
+
* Fetches the latest gas prices for the given chain and persists them to
|
|
8
|
+
* state.
|
|
9
|
+
*
|
|
10
|
+
* @param args - The arguments to the function.
|
|
11
|
+
* @param args.chainId - The chain ID for which to fetch gas prices.
|
|
12
|
+
*/
|
|
13
|
+
export type SampleGasPricesServiceFetchGasPricesAction = {
|
|
14
|
+
type: `SampleGasPricesService:fetchGasPrices`;
|
|
15
|
+
handler: SampleGasPricesService['fetchGasPrices'];
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Union of all SampleGasPricesService action types.
|
|
19
|
+
*/
|
|
20
|
+
export type SampleGasPricesServiceMethodActions = SampleGasPricesServiceFetchGasPricesAction;
|
|
21
|
+
//# sourceMappingURL=sample-gas-prices-service-method-action-types.d.cts.map
|
package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.cts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sample-gas-prices-service-method-action-types.d.cts","sourceRoot":"","sources":["../../src/sample-gas-prices-service/sample-gas-prices-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAoC;AAE1E;;;;;;GAMG;AACH,MAAM,MAAM,0CAA0C,GAAG;IACvD,IAAI,EAAE,uCAAuC,CAAC;IAC9C,OAAO,EAAE,sBAAsB,CAAC,gBAAgB,CAAC,CAAC;CACnD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mCAAmC,GAC7C,0CAA0C,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { SampleGasPricesService } from "./sample-gas-prices-service.mjs";
|
|
6
|
+
/**
|
|
7
|
+
* Fetches the latest gas prices for the given chain and persists them to
|
|
8
|
+
* state.
|
|
9
|
+
*
|
|
10
|
+
* @param args - The arguments to the function.
|
|
11
|
+
* @param args.chainId - The chain ID for which to fetch gas prices.
|
|
12
|
+
*/
|
|
13
|
+
export type SampleGasPricesServiceFetchGasPricesAction = {
|
|
14
|
+
type: `SampleGasPricesService:fetchGasPrices`;
|
|
15
|
+
handler: SampleGasPricesService['fetchGasPrices'];
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Union of all SampleGasPricesService action types.
|
|
19
|
+
*/
|
|
20
|
+
export type SampleGasPricesServiceMethodActions = SampleGasPricesServiceFetchGasPricesAction;
|
|
21
|
+
//# sourceMappingURL=sample-gas-prices-service-method-action-types.d.mts.map
|
package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.mts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sample-gas-prices-service-method-action-types.d.mts","sourceRoot":"","sources":["../../src/sample-gas-prices-service/sample-gas-prices-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAoC;AAE1E;;;;;;GAMG;AACH,MAAM,MAAM,0CAA0C,GAAG;IACvD,IAAI,EAAE,uCAAuC,CAAC;IAC9C,OAAO,EAAE,sBAAsB,CAAC,gBAAgB,CAAC,CAAC;CACnD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mCAAmC,GAC7C,0CAA0C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sample-gas-prices-service-method-action-types.mjs","sourceRoot":"","sources":["../../src/sample-gas-prices-service/sample-gas-prices-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { SampleGasPricesService } from './sample-gas-prices-service';\n\n/**\n * Fetches the latest gas prices for the given chain and persists them to\n * state.\n *\n * @param args - The arguments to the function.\n * @param args.chainId - The chain ID for which to fetch gas prices.\n */\nexport type SampleGasPricesServiceFetchGasPricesAction = {\n type: `SampleGasPricesService:fetchGasPrices`;\n handler: SampleGasPricesService['fetchGasPrices'];\n};\n\n/**\n * Union of all SampleGasPricesService action types.\n */\nexport type SampleGasPricesServiceMethodActions =\n SampleGasPricesServiceFetchGasPricesAction;\n"]}
|
|
@@ -10,48 +10,134 @@ 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 _SampleGasPricesService_fetch;
|
|
13
|
+
var _a, _SampleGasPricesService_messenger, _SampleGasPricesService_fetch, _SampleGasPricesService_policy;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.SampleGasPricesService = void 0;
|
|
15
|
+
exports.SampleGasPricesService = exports.serviceName = void 0;
|
|
16
|
+
const controller_utils_1 = require("@metamask/controller-utils");
|
|
17
|
+
const utils_1 = require("@metamask/utils");
|
|
18
|
+
// === GENERAL ===
|
|
19
|
+
/**
|
|
20
|
+
* The name of the {@link SampleGasPricesService}, used to namespace the
|
|
21
|
+
* service's actions and events.
|
|
22
|
+
*/
|
|
23
|
+
exports.serviceName = 'SampleGasPricesService';
|
|
24
|
+
// === MESSENGER ===
|
|
25
|
+
const MESSENGER_EXPOSED_METHODS = ['fetchGasPrices'];
|
|
16
26
|
/**
|
|
17
27
|
* This service object is responsible for fetching gas prices via an API.
|
|
18
28
|
*
|
|
19
29
|
* @example
|
|
20
30
|
*
|
|
21
|
-
* On its own:
|
|
22
|
-
*
|
|
23
31
|
* ``` ts
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* In conjunction with `SampleGasPricesController`:
|
|
32
|
+
* import type {
|
|
33
|
+
* SampleGasPricesServiceActions,
|
|
34
|
+
* SampleGasPricesServiceEvents
|
|
35
|
+
* } from '@metamask/sample-controllers';
|
|
31
36
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
+
* const globalMessenger = new Messenger<
|
|
38
|
+
* SampleGasPricesServiceActions
|
|
39
|
+
* SampleGasPricesServiceEvents
|
|
40
|
+
* >();
|
|
41
|
+
* const gasPricesServiceMessenger = globalMessenger.getRestricted({
|
|
42
|
+
* name: 'SampleGasPricesService',
|
|
43
|
+
* allowedActions: [],
|
|
44
|
+
* allowedEvents: [],
|
|
45
|
+
* });
|
|
46
|
+
* // Instantiate the service to register its actions on the messenger
|
|
47
|
+
* new SampleGasPricesService({
|
|
48
|
+
* messenger: gasPricesServiceMessenger,
|
|
49
|
+
* fetch,
|
|
37
50
|
* });
|
|
38
|
-
*
|
|
39
|
-
*
|
|
51
|
+
*
|
|
52
|
+
* // Later...
|
|
53
|
+
* // Fetch gas prices for Mainnet
|
|
54
|
+
* const gasPrices = await globalMessenger.call(
|
|
55
|
+
* 'SampleGasPricesService:fetchGasPrices',
|
|
56
|
+
* '0x1',
|
|
57
|
+
* );
|
|
58
|
+
* // ... Do something with the gas prices ...
|
|
40
59
|
* ```
|
|
41
60
|
*/
|
|
42
61
|
class SampleGasPricesService {
|
|
43
62
|
/**
|
|
44
63
|
* Constructs a new SampleGasPricesService object.
|
|
45
64
|
*
|
|
46
|
-
* @param args - The arguments.
|
|
47
|
-
* @param args.
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
65
|
+
* @param args - The constructor arguments.
|
|
66
|
+
* @param args.messenger - The messenger suited for this service.
|
|
67
|
+
* @param args.fetch - A function that can be used to make an HTTP request. If
|
|
68
|
+
* your JavaScript environment supports `fetch` natively, you'll probably want
|
|
69
|
+
* to pass that; otherwise you can pass an equivalent (such as `fetch` via
|
|
70
|
+
* `node-fetch`).
|
|
71
|
+
* @param args.policyOptions - Options to pass to `createServicePolicy`, which
|
|
72
|
+
* is used to wrap each request. See {@link CreateServicePolicyOptions}.
|
|
51
73
|
*/
|
|
52
|
-
constructor({ fetch: fetchFunction }) {
|
|
74
|
+
constructor({ messenger, fetch: fetchFunction, policyOptions = {}, }) {
|
|
75
|
+
/**
|
|
76
|
+
* The messenger suited for this service.
|
|
77
|
+
*/
|
|
78
|
+
_SampleGasPricesService_messenger.set(this, void 0);
|
|
79
|
+
/**
|
|
80
|
+
* A function that can be used to make an HTTP request.
|
|
81
|
+
*/
|
|
53
82
|
_SampleGasPricesService_fetch.set(this, void 0);
|
|
83
|
+
/**
|
|
84
|
+
* The policy that wraps the request.
|
|
85
|
+
*
|
|
86
|
+
* @see {@link createServicePolicy}
|
|
87
|
+
*/
|
|
88
|
+
_SampleGasPricesService_policy.set(this, void 0);
|
|
89
|
+
this.name = exports.serviceName;
|
|
90
|
+
__classPrivateFieldSet(this, _SampleGasPricesService_messenger, messenger, "f");
|
|
54
91
|
__classPrivateFieldSet(this, _SampleGasPricesService_fetch, fetchFunction, "f");
|
|
92
|
+
__classPrivateFieldSet(this, _SampleGasPricesService_policy, (0, controller_utils_1.createServicePolicy)(policyOptions), "f");
|
|
93
|
+
__classPrivateFieldGet(this, _SampleGasPricesService_messenger, "f").registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Registers a handler that will be called after a request returns a non-500
|
|
97
|
+
* response, causing a retry. Primarily useful in tests where timers are being
|
|
98
|
+
* mocked.
|
|
99
|
+
*
|
|
100
|
+
* @param listener - The handler to be called.
|
|
101
|
+
* @returns An object that can be used to unregister the handler. See
|
|
102
|
+
* {@link CockatielEvent}.
|
|
103
|
+
* @see {@link createServicePolicy}
|
|
104
|
+
*/
|
|
105
|
+
onRetry(listener) {
|
|
106
|
+
return __classPrivateFieldGet(this, _SampleGasPricesService_policy, "f").onRetry(listener);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Registers a handler that will be called after a set number of retry rounds
|
|
110
|
+
* prove that requests to the API endpoint consistently return a 5xx response.
|
|
111
|
+
*
|
|
112
|
+
* @param listener - The handler to be called.
|
|
113
|
+
* @returns An object that can be used to unregister the handler. See
|
|
114
|
+
* {@link CockatielEvent}.
|
|
115
|
+
* @see {@link createServicePolicy}
|
|
116
|
+
*/
|
|
117
|
+
onBreak(listener) {
|
|
118
|
+
return __classPrivateFieldGet(this, _SampleGasPricesService_policy, "f").onBreak(listener);
|
|
119
|
+
}
|
|
120
|
+
/* eslint-disable jsdoc/check-indentation */
|
|
121
|
+
/**
|
|
122
|
+
* Registers a handler that will be called under one of two circumstances:
|
|
123
|
+
*
|
|
124
|
+
* 1. After a set number of retries prove that requests to the API
|
|
125
|
+
* consistently result in one of the following failures:
|
|
126
|
+
* 1. A connection initiation error
|
|
127
|
+
* 2. A connection reset error
|
|
128
|
+
* 3. A timeout error
|
|
129
|
+
* 4. A non-JSON response
|
|
130
|
+
* 5. A 502, 503, or 504 response
|
|
131
|
+
* 2. After a successful request is made to the API, but the response takes
|
|
132
|
+
* longer than a set duration to return.
|
|
133
|
+
*
|
|
134
|
+
* @param listener - The handler to be called.
|
|
135
|
+
* @returns An object that can be used to unregister the handler. See
|
|
136
|
+
* {@link CockatielEvent}.
|
|
137
|
+
*/
|
|
138
|
+
/* eslint-enable jsdoc/check-indentation */
|
|
139
|
+
onDegraded(listener) {
|
|
140
|
+
return __classPrivateFieldGet(this, _SampleGasPricesService_policy, "f").onDegraded(listener);
|
|
55
141
|
}
|
|
56
142
|
/**
|
|
57
143
|
* Makes a request to the API in order to retrieve gas prices for a particular
|
|
@@ -61,12 +147,32 @@ class SampleGasPricesService {
|
|
|
61
147
|
* @returns The gas prices for the given chain.
|
|
62
148
|
*/
|
|
63
149
|
async fetchGasPrices(chainId) {
|
|
64
|
-
const response = await __classPrivateFieldGet(this,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
150
|
+
const response = await __classPrivateFieldGet(this, _SampleGasPricesService_policy, "f").execute(async () => {
|
|
151
|
+
const url = new URL('https://api.example.com/gas-prices');
|
|
152
|
+
url.searchParams.append('chainId', `eip155:${(0, controller_utils_1.fromHex)(chainId)}`);
|
|
153
|
+
const localResponse = await __classPrivateFieldGet(this, _SampleGasPricesService_fetch, "f").call(this, url);
|
|
154
|
+
if (!localResponse.ok) {
|
|
155
|
+
throw new controller_utils_1.HttpError(localResponse.status, `Fetching '${url.toString()}' failed with status '${localResponse.status}'`);
|
|
156
|
+
}
|
|
157
|
+
return localResponse;
|
|
158
|
+
});
|
|
159
|
+
const jsonResponse = await response.json();
|
|
160
|
+
if ((0, utils_1.isPlainObject)(jsonResponse) &&
|
|
161
|
+
(0, utils_1.hasProperty)(jsonResponse, 'data') &&
|
|
162
|
+
(0, utils_1.isPlainObject)(jsonResponse.data) &&
|
|
163
|
+
(0, utils_1.hasProperty)(jsonResponse.data, 'low') &&
|
|
164
|
+
(0, utils_1.hasProperty)(jsonResponse.data, 'average') &&
|
|
165
|
+
(0, utils_1.hasProperty)(jsonResponse.data, 'high')) {
|
|
166
|
+
const { data: { low, average, high }, } = jsonResponse;
|
|
167
|
+
if (typeof low === 'number' &&
|
|
168
|
+
typeof average === 'number' &&
|
|
169
|
+
typeof high === 'number') {
|
|
170
|
+
return { low, average, high };
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
throw new Error('Malformed response received from gas prices API');
|
|
68
174
|
}
|
|
69
175
|
}
|
|
70
176
|
exports.SampleGasPricesService = SampleGasPricesService;
|
|
71
|
-
_SampleGasPricesService_fetch = new WeakMap();
|
|
177
|
+
_a = SampleGasPricesService, _SampleGasPricesService_messenger = new WeakMap(), _SampleGasPricesService_fetch = new WeakMap(), _SampleGasPricesService_policy = new WeakMap();
|
|
72
178
|
//# sourceMappingURL=sample-gas-prices-service.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sample-gas-prices-service.cjs","sourceRoot":"","sources":["../../src/sample-gas-prices-service/sample-gas-prices-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAaA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAa,sBAAsB;IAGjC;;;;;;;;OAQG;IACH,YAAY,EAAE,KAAK,EAAE,aAAa,EAA2B;QAXpD,gDAAqB;QAY5B,uBAAA,IAAI,iCAAU,aAAa,MAAA,CAAC;IAC9B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,cAAc,CAAC,OAAY;QAC/B,MAAM,QAAQ,GAAG,MAAM,uBAAA,IAAI,qCAAO,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,wDAgCC","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 SampleGasPricesService({ 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 `SampleGasPricesController`:\n *\n * ``` ts\n * const gasPricesService = new SampleGasPricesService({ fetch });\n * const gasPricesController = new SampleGasPricesController({\n * // ... state, messenger, etc. ...\n * gasPricesService,\n * });\n * // This will use the service object internally\n * gasPricesController.updateGasPrices();\n * ```\n */\nexport class SampleGasPricesService {\n readonly #fetch: typeof fetch;\n\n /**\n * Constructs a new SampleGasPricesService 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"]}
|
|
1
|
+
{"version":3,"file":"sample-gas-prices-service.cjs","sourceRoot":"","sources":["../../src/sample-gas-prices-service/sample-gas-prices-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,iEAIoC;AACpC,2CAAuE;AAIvE,kBAAkB;AAElB;;;GAGG;AACU,QAAA,WAAW,GAAG,wBAAwB,CAAC;AAEpD,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG,CAAC,gBAAgB,CAAU,CAAC;AAgD9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAa,sBAAsB;IA2BjC;;;;;;;;;;;OAWG;IACH,YAAY,EACV,SAAS,EACT,KAAK,EAAE,aAAa,EACpB,aAAa,GAAG,EAAE,GAKnB;QAzCD;;WAEG;QACM,oDAES;QAElB;;WAEG;QACM,gDAEK;QAEd;;;;WAIG;QACM,iDAAuB;QAuB9B,IAAI,CAAC,IAAI,GAAG,mBAAW,CAAC;QACxB,uBAAA,IAAI,qCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,iCAAU,aAAa,MAAA,CAAC;QAC5B,uBAAA,IAAI,kCAAW,IAAA,sCAAmB,EAAC,aAAa,CAAC,MAAA,CAAC;QAElD,uBAAA,IAAI,yCAAW,CAAC,4BAA4B,CAC1C,IAAI,EACJ,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED;;;;;;;;;OASG;IACH,OAAO,CAAC,QAAiD;QACvD,OAAO,uBAAA,IAAI,sCAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC;IAED;;;;;;;;OAQG;IACH,OAAO,CAAC,QAAiD;QACvD,OAAO,uBAAA,IAAI,sCAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC;IAED,4CAA4C;IAC5C;;;;;;;;;;;;;;;;OAgBG;IACH,2CAA2C;IAC3C,UAAU,CAAC,QAAoD;QAC7D,OAAO,uBAAA,IAAI,sCAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,cAAc,CAAC,OAAY;QAC/B,MAAM,QAAQ,GAAG,MAAM,uBAAA,IAAI,sCAAQ,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE;YACrD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,oCAAoC,CAAC,CAAC;YAC1D,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,SAAS,EAAE,UAAU,IAAA,0BAAO,EAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACjE,MAAM,aAAa,GAAG,MAAM,uBAAA,IAAI,qCAAO,MAAX,IAAI,EAAQ,GAAG,CAAC,CAAC;YAC7C,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE;gBACrB,MAAM,IAAI,4BAAS,CACjB,aAAa,CAAC,MAAM,EACpB,aAAa,GAAG,CAAC,QAAQ,EAAE,yBAAyB,aAAa,CAAC,MAAM,GAAG,CAC5E,CAAC;aACH;YACD,OAAO,aAAa,CAAC;QACvB,CAAC,CAAC,CAAC;QACH,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAE3C,IACE,IAAA,qBAAa,EAAC,YAAY,CAAC;YAC3B,IAAA,mBAAW,EAAC,YAAY,EAAE,MAAM,CAAC;YACjC,IAAA,qBAAa,EAAC,YAAY,CAAC,IAAI,CAAC;YAChC,IAAA,mBAAW,EAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC;YACrC,IAAA,mBAAW,EAAC,YAAY,CAAC,IAAI,EAAE,SAAS,CAAC;YACzC,IAAA,mBAAW,EAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,EACtC;YACA,MAAM,EACJ,IAAI,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,GAC7B,GAAG,YAAY,CAAC;YACjB,IACE,OAAO,GAAG,KAAK,QAAQ;gBACvB,OAAO,OAAO,KAAK,QAAQ;gBAC3B,OAAO,IAAI,KAAK,QAAQ,EACxB;gBACA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;aAC/B;SACF;QAED,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;CACF;AAzJD,wDAyJC","sourcesContent":["import type { RestrictedMessenger } from '@metamask/base-controller';\nimport type {\n CreateServicePolicyOptions,\n ServicePolicy,\n} from '@metamask/controller-utils';\nimport {\n createServicePolicy,\n fromHex,\n HttpError,\n} from '@metamask/controller-utils';\nimport { hasProperty, isPlainObject, type Hex } from '@metamask/utils';\n\nimport type { SampleGasPricesServiceMethodActions } from './sample-gas-prices-service-method-action-types';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link SampleGasPricesService}, used to namespace the\n * service's actions and events.\n */\nexport const serviceName = 'SampleGasPricesService';\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = ['fetchGasPrices'] as const;\n\n/**\n * Actions that {@link SampleGasPricesService} exposes to other consumers.\n */\nexport type SampleGasPricesServiceActions = SampleGasPricesServiceMethodActions;\n\n/**\n * Actions from other messengers that {@link SampleGasPricesMessenger} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Events that {@link SampleGasPricesService} exposes to other consumers.\n */\nexport type SampleGasPricesServiceEvents = never;\n\n/**\n * Events from other messengers that {@link SampleGasPricesService} subscribes\n * to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link SampleGasPricesService}.\n */\nexport type SampleGasPricesServiceMessenger = RestrictedMessenger<\n typeof serviceName,\n SampleGasPricesServiceActions | AllowedActions,\n SampleGasPricesServiceEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n// === SERVICE DEFINITION ===\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 * ``` ts\n * import type {\n * SampleGasPricesServiceActions,\n * SampleGasPricesServiceEvents\n * } from '@metamask/sample-controllers';\n *\n * const globalMessenger = new Messenger<\n * SampleGasPricesServiceActions\n * SampleGasPricesServiceEvents\n * >();\n * const gasPricesServiceMessenger = globalMessenger.getRestricted({\n * name: 'SampleGasPricesService',\n * allowedActions: [],\n * allowedEvents: [],\n * });\n * // Instantiate the service to register its actions on the messenger\n * new SampleGasPricesService({\n * messenger: gasPricesServiceMessenger,\n * fetch,\n * });\n *\n * // Later...\n * // Fetch gas prices for Mainnet\n * const gasPrices = await globalMessenger.call(\n * 'SampleGasPricesService:fetchGasPrices',\n * '0x1',\n * );\n * // ... Do something with the gas prices ...\n * ```\n */\nexport class SampleGasPricesService {\n /**\n * The name of the service.\n */\n readonly name: typeof serviceName;\n\n /**\n * The messenger suited for this service.\n */\n readonly #messenger: ConstructorParameters<\n typeof SampleGasPricesService\n >[0]['messenger'];\n\n /**\n * A function that can be used to make an HTTP request.\n */\n readonly #fetch: ConstructorParameters<\n typeof SampleGasPricesService\n >[0]['fetch'];\n\n /**\n * The policy that wraps the request.\n *\n * @see {@link createServicePolicy}\n */\n readonly #policy: ServicePolicy;\n\n /**\n * Constructs a new SampleGasPricesService object.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this service.\n * @param args.fetch - A function that can be used to make an HTTP request. If\n * your JavaScript environment supports `fetch` natively, you'll probably want\n * to pass that; otherwise you can pass an equivalent (such as `fetch` via\n * `node-fetch`).\n * @param args.policyOptions - Options to pass to `createServicePolicy`, which\n * is used to wrap each request. See {@link CreateServicePolicyOptions}.\n */\n constructor({\n messenger,\n fetch: fetchFunction,\n policyOptions = {},\n }: {\n messenger: SampleGasPricesServiceMessenger;\n fetch: typeof fetch;\n policyOptions?: CreateServicePolicyOptions;\n }) {\n this.name = serviceName;\n this.#messenger = messenger;\n this.#fetch = fetchFunction;\n this.#policy = createServicePolicy(policyOptions);\n\n this.#messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Registers a handler that will be called after a request returns a non-500\n * response, causing a retry. Primarily useful in tests where timers are being\n * mocked.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler. See\n * {@link CockatielEvent}.\n * @see {@link createServicePolicy}\n */\n onRetry(listener: Parameters<ServicePolicy['onRetry']>[0]) {\n return this.#policy.onRetry(listener);\n }\n\n /**\n * Registers a handler that will be called after a set number of retry rounds\n * prove that requests to the API endpoint consistently return a 5xx response.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler. See\n * {@link CockatielEvent}.\n * @see {@link createServicePolicy}\n */\n onBreak(listener: Parameters<ServicePolicy['onBreak']>[0]) {\n return this.#policy.onBreak(listener);\n }\n\n /* eslint-disable jsdoc/check-indentation */\n /**\n * Registers a handler that will be called under one of two circumstances:\n *\n * 1. After a set number of retries prove that requests to the API\n * consistently result in one of the following failures:\n * 1. A connection initiation error\n * 2. A connection reset error\n * 3. A timeout error\n * 4. A non-JSON response\n * 5. A 502, 503, or 504 response\n * 2. After a successful request is made to the API, but the response takes\n * longer than a set duration to return.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler. See\n * {@link CockatielEvent}.\n */\n /* eslint-enable jsdoc/check-indentation */\n onDegraded(listener: Parameters<ServicePolicy['onDegraded']>[0]) {\n return this.#policy.onDegraded(listener);\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): Promise<GasPricesResponse['data']> {\n const response = await this.#policy.execute(async () => {\n const url = new URL('https://api.example.com/gas-prices');\n url.searchParams.append('chainId', `eip155:${fromHex(chainId)}`);\n const localResponse = await this.#fetch(url);\n if (!localResponse.ok) {\n throw new HttpError(\n localResponse.status,\n `Fetching '${url.toString()}' failed with status '${localResponse.status}'`,\n );\n }\n return localResponse;\n });\n const jsonResponse = await response.json();\n\n if (\n isPlainObject(jsonResponse) &&\n hasProperty(jsonResponse, 'data') &&\n isPlainObject(jsonResponse.data) &&\n hasProperty(jsonResponse.data, 'low') &&\n hasProperty(jsonResponse.data, 'average') &&\n hasProperty(jsonResponse.data, 'high')\n ) {\n const {\n data: { low, average, high },\n } = jsonResponse;\n if (\n typeof low === 'number' &&\n typeof average === 'number' &&\n typeof high === 'number'\n ) {\n return { low, average, high };\n }\n }\n\n throw new Error('Malformed response received from gas prices API');\n }\n}\n"]}
|
|
@@ -1,44 +1,141 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RestrictedMessenger } from "@metamask/base-controller";
|
|
2
|
+
import type { CreateServicePolicyOptions, ServicePolicy } from "@metamask/controller-utils";
|
|
3
|
+
import { type Hex } from "@metamask/utils";
|
|
4
|
+
import type { SampleGasPricesServiceMethodActions } from "./sample-gas-prices-service-method-action-types.cjs";
|
|
5
|
+
/**
|
|
6
|
+
* The name of the {@link SampleGasPricesService}, used to namespace the
|
|
7
|
+
* service's actions and events.
|
|
8
|
+
*/
|
|
9
|
+
export declare const serviceName = "SampleGasPricesService";
|
|
10
|
+
/**
|
|
11
|
+
* Actions that {@link SampleGasPricesService} exposes to other consumers.
|
|
12
|
+
*/
|
|
13
|
+
export type SampleGasPricesServiceActions = SampleGasPricesServiceMethodActions;
|
|
14
|
+
/**
|
|
15
|
+
* Actions from other messengers that {@link SampleGasPricesMessenger} calls.
|
|
16
|
+
*/
|
|
17
|
+
type AllowedActions = never;
|
|
18
|
+
/**
|
|
19
|
+
* Events that {@link SampleGasPricesService} exposes to other consumers.
|
|
20
|
+
*/
|
|
21
|
+
export type SampleGasPricesServiceEvents = never;
|
|
22
|
+
/**
|
|
23
|
+
* Events from other messengers that {@link SampleGasPricesService} subscribes
|
|
24
|
+
* to.
|
|
25
|
+
*/
|
|
26
|
+
type AllowedEvents = never;
|
|
27
|
+
/**
|
|
28
|
+
* The messenger which is restricted to actions and events accessed by
|
|
29
|
+
* {@link SampleGasPricesService}.
|
|
30
|
+
*/
|
|
31
|
+
export type SampleGasPricesServiceMessenger = RestrictedMessenger<typeof serviceName, SampleGasPricesServiceActions | AllowedActions, SampleGasPricesServiceEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
|
|
32
|
+
/**
|
|
33
|
+
* What the API endpoint returns.
|
|
34
|
+
*/
|
|
35
|
+
type GasPricesResponse = {
|
|
36
|
+
data: {
|
|
37
|
+
low: number;
|
|
38
|
+
average: number;
|
|
39
|
+
high: number;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
2
42
|
/**
|
|
3
43
|
* This service object is responsible for fetching gas prices via an API.
|
|
4
44
|
*
|
|
5
45
|
* @example
|
|
6
46
|
*
|
|
7
|
-
* On its own:
|
|
8
|
-
*
|
|
9
47
|
* ``` ts
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* ```
|
|
48
|
+
* import type {
|
|
49
|
+
* SampleGasPricesServiceActions,
|
|
50
|
+
* SampleGasPricesServiceEvents
|
|
51
|
+
* } from '@metamask/sample-controllers';
|
|
15
52
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* const
|
|
21
|
-
*
|
|
22
|
-
*
|
|
53
|
+
* const globalMessenger = new Messenger<
|
|
54
|
+
* SampleGasPricesServiceActions
|
|
55
|
+
* SampleGasPricesServiceEvents
|
|
56
|
+
* >();
|
|
57
|
+
* const gasPricesServiceMessenger = globalMessenger.getRestricted({
|
|
58
|
+
* name: 'SampleGasPricesService',
|
|
59
|
+
* allowedActions: [],
|
|
60
|
+
* allowedEvents: [],
|
|
61
|
+
* });
|
|
62
|
+
* // Instantiate the service to register its actions on the messenger
|
|
63
|
+
* new SampleGasPricesService({
|
|
64
|
+
* messenger: gasPricesServiceMessenger,
|
|
65
|
+
* fetch,
|
|
23
66
|
* });
|
|
24
|
-
*
|
|
25
|
-
*
|
|
67
|
+
*
|
|
68
|
+
* // Later...
|
|
69
|
+
* // Fetch gas prices for Mainnet
|
|
70
|
+
* const gasPrices = await globalMessenger.call(
|
|
71
|
+
* 'SampleGasPricesService:fetchGasPrices',
|
|
72
|
+
* '0x1',
|
|
73
|
+
* );
|
|
74
|
+
* // ... Do something with the gas prices ...
|
|
26
75
|
* ```
|
|
27
76
|
*/
|
|
28
77
|
export declare class SampleGasPricesService {
|
|
29
78
|
#private;
|
|
79
|
+
/**
|
|
80
|
+
* The name of the service.
|
|
81
|
+
*/
|
|
82
|
+
readonly name: typeof serviceName;
|
|
30
83
|
/**
|
|
31
84
|
* Constructs a new SampleGasPricesService object.
|
|
32
85
|
*
|
|
33
|
-
* @param args - The arguments.
|
|
34
|
-
* @param args.
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
86
|
+
* @param args - The constructor arguments.
|
|
87
|
+
* @param args.messenger - The messenger suited for this service.
|
|
88
|
+
* @param args.fetch - A function that can be used to make an HTTP request. If
|
|
89
|
+
* your JavaScript environment supports `fetch` natively, you'll probably want
|
|
90
|
+
* to pass that; otherwise you can pass an equivalent (such as `fetch` via
|
|
91
|
+
* `node-fetch`).
|
|
92
|
+
* @param args.policyOptions - Options to pass to `createServicePolicy`, which
|
|
93
|
+
* is used to wrap each request. See {@link CreateServicePolicyOptions}.
|
|
38
94
|
*/
|
|
39
|
-
constructor({ fetch: fetchFunction }: {
|
|
95
|
+
constructor({ messenger, fetch: fetchFunction, policyOptions, }: {
|
|
96
|
+
messenger: SampleGasPricesServiceMessenger;
|
|
40
97
|
fetch: typeof fetch;
|
|
98
|
+
policyOptions?: CreateServicePolicyOptions;
|
|
41
99
|
});
|
|
100
|
+
/**
|
|
101
|
+
* Registers a handler that will be called after a request returns a non-500
|
|
102
|
+
* response, causing a retry. Primarily useful in tests where timers are being
|
|
103
|
+
* mocked.
|
|
104
|
+
*
|
|
105
|
+
* @param listener - The handler to be called.
|
|
106
|
+
* @returns An object that can be used to unregister the handler. See
|
|
107
|
+
* {@link CockatielEvent}.
|
|
108
|
+
* @see {@link createServicePolicy}
|
|
109
|
+
*/
|
|
110
|
+
onRetry(listener: Parameters<ServicePolicy['onRetry']>[0]): import("cockatiel").IDisposable;
|
|
111
|
+
/**
|
|
112
|
+
* Registers a handler that will be called after a set number of retry rounds
|
|
113
|
+
* prove that requests to the API endpoint consistently return a 5xx response.
|
|
114
|
+
*
|
|
115
|
+
* @param listener - The handler to be called.
|
|
116
|
+
* @returns An object that can be used to unregister the handler. See
|
|
117
|
+
* {@link CockatielEvent}.
|
|
118
|
+
* @see {@link createServicePolicy}
|
|
119
|
+
*/
|
|
120
|
+
onBreak(listener: Parameters<ServicePolicy['onBreak']>[0]): import("cockatiel").IDisposable;
|
|
121
|
+
/**
|
|
122
|
+
* Registers a handler that will be called under one of two circumstances:
|
|
123
|
+
*
|
|
124
|
+
* 1. After a set number of retries prove that requests to the API
|
|
125
|
+
* consistently result in one of the following failures:
|
|
126
|
+
* 1. A connection initiation error
|
|
127
|
+
* 2. A connection reset error
|
|
128
|
+
* 3. A timeout error
|
|
129
|
+
* 4. A non-JSON response
|
|
130
|
+
* 5. A 502, 503, or 504 response
|
|
131
|
+
* 2. After a successful request is made to the API, but the response takes
|
|
132
|
+
* longer than a set duration to return.
|
|
133
|
+
*
|
|
134
|
+
* @param listener - The handler to be called.
|
|
135
|
+
* @returns An object that can be used to unregister the handler. See
|
|
136
|
+
* {@link CockatielEvent}.
|
|
137
|
+
*/
|
|
138
|
+
onDegraded(listener: Parameters<ServicePolicy['onDegraded']>[0]): import("cockatiel").IDisposable;
|
|
42
139
|
/**
|
|
43
140
|
* Makes a request to the API in order to retrieve gas prices for a particular
|
|
44
141
|
* chain.
|
|
@@ -46,10 +143,7 @@ export declare class SampleGasPricesService {
|
|
|
46
143
|
* @param chainId - The chain ID for which you want to fetch gas prices.
|
|
47
144
|
* @returns The gas prices for the given chain.
|
|
48
145
|
*/
|
|
49
|
-
fetchGasPrices(chainId: Hex): Promise<
|
|
50
|
-
low: number;
|
|
51
|
-
average: number;
|
|
52
|
-
high: number;
|
|
53
|
-
}>;
|
|
146
|
+
fetchGasPrices(chainId: Hex): Promise<GasPricesResponse['data']>;
|
|
54
147
|
}
|
|
148
|
+
export {};
|
|
55
149
|
//# sourceMappingURL=sample-gas-prices-service.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sample-gas-prices-service.d.cts","sourceRoot":"","sources":["../../src/sample-gas-prices-service/sample-gas-prices-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"sample-gas-prices-service.d.cts","sourceRoot":"","sources":["../../src/sample-gas-prices-service/sample-gas-prices-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,kCAAkC;AACrE,OAAO,KAAK,EACV,0BAA0B,EAC1B,aAAa,EACd,mCAAmC;AAMpC,OAAO,EAA8B,KAAK,GAAG,EAAE,wBAAwB;AAEvE,OAAO,KAAK,EAAE,mCAAmC,EAAE,4DAAwD;AAI3G;;;GAGG;AACH,eAAO,MAAM,WAAW,2BAA2B,CAAC;AAMpD;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,mCAAmC,CAAC;AAEhF;;GAEG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG,KAAK,CAAC;AAEjD;;;GAGG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,+BAA+B,GAAG,mBAAmB,CAC/D,OAAO,WAAW,EAClB,6BAA6B,GAAG,cAAc,EAC9C,4BAA4B,GAAG,aAAa,EAC5C,cAAc,CAAC,MAAM,CAAC,EACtB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC;AAIF;;GAEG;AACH,KAAK,iBAAiB,GAAG;IACvB,IAAI,EAAE;QACJ,GAAG,EAAE,MAAM,CAAC;QACZ,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,qBAAa,sBAAsB;;IACjC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,OAAO,WAAW,CAAC;IAuBlC;;;;;;;;;;;OAWG;gBACS,EACV,SAAS,EACT,KAAK,EAAE,aAAa,EACpB,aAAkB,GACnB,EAAE;QACD,SAAS,EAAE,+BAA+B,CAAC;QAC3C,KAAK,EAAE,OAAO,KAAK,CAAC;QACpB,aAAa,CAAC,EAAE,0BAA0B,CAAC;KAC5C;IAYD;;;;;;;;;OASG;IACH,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IAIzD;;;;;;;;OAQG;IACH,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IAKzD;;;;;;;;;;;;;;;;OAgBG;IAEH,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAI/D;;;;;;OAMG;IACG,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;CAqCvE"}
|