@metamask-previews/sample-controllers 5.0.6-preview-8bfa290fb → 6.0.0-preview-0a30e47
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 +13 -1
- package/dist/{index.d.mts → index.d.ts} +10 -10
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/{index.cjs.map → index.js.map} +1 -1
- package/dist/{sample-gas-prices-controller-method-action-types.d.cts → sample-gas-prices-controller-method-action-types.d.ts} +2 -2
- package/dist/sample-gas-prices-controller-method-action-types.d.ts.map +1 -0
- package/dist/{sample-gas-prices-controller-method-action-types.mjs → sample-gas-prices-controller-method-action-types.js} +1 -1
- package/dist/sample-gas-prices-controller-method-action-types.js.map +1 -0
- package/dist/{sample-gas-prices-controller.d.cts → sample-gas-prices-controller.d.ts} +8 -8
- package/dist/sample-gas-prices-controller.d.ts.map +1 -0
- package/dist/{sample-gas-prices-controller.mjs → sample-gas-prices-controller.js} +22 -29
- package/dist/sample-gas-prices-controller.js.map +1 -0
- package/dist/sample-gas-prices-service/{sample-gas-prices-service-method-action-types.d.cts → sample-gas-prices-service-method-action-types.d.ts} +2 -2
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.ts.map +1 -0
- package/dist/sample-gas-prices-service/{sample-gas-prices-service-method-action-types.mjs → sample-gas-prices-service-method-action-types.js} +1 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.js.map +1 -0
- package/dist/sample-gas-prices-service/{sample-gas-prices-service.d.mts → sample-gas-prices-service.d.ts} +9 -9
- package/dist/sample-gas-prices-service/sample-gas-prices-service.d.ts.map +1 -0
- package/dist/sample-gas-prices-service/{sample-gas-prices-service.mjs → sample-gas-prices-service.js} +4 -4
- package/dist/sample-gas-prices-service/sample-gas-prices-service.js.map +1 -0
- package/dist/{sample-petnames-controller-method-action-types.d.cts → sample-petnames-controller-method-action-types.d.ts} +2 -2
- package/dist/sample-petnames-controller-method-action-types.d.ts.map +1 -0
- package/dist/{sample-petnames-controller-method-action-types.mjs → sample-petnames-controller-method-action-types.js} +1 -1
- package/dist/sample-petnames-controller-method-action-types.js.map +1 -0
- package/dist/{sample-petnames-controller.d.mts → sample-petnames-controller.d.ts} +6 -6
- package/dist/sample-petnames-controller.d.ts.map +1 -0
- package/dist/{sample-petnames-controller.mjs → sample-petnames-controller.js} +4 -5
- package/dist/sample-petnames-controller.js.map +1 -0
- package/package.json +17 -21
- package/dist/index.cjs +0 -12
- package/dist/index.d.cts +0 -10
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -4
- package/dist/index.mjs.map +0 -1
- package/dist/sample-gas-prices-controller-method-action-types.cjs +0 -7
- package/dist/sample-gas-prices-controller-method-action-types.cjs.map +0 -1
- package/dist/sample-gas-prices-controller-method-action-types.d.cts.map +0 -1
- package/dist/sample-gas-prices-controller-method-action-types.d.mts +0 -21
- package/dist/sample-gas-prices-controller-method-action-types.d.mts.map +0 -1
- package/dist/sample-gas-prices-controller-method-action-types.mjs.map +0 -1
- package/dist/sample-gas-prices-controller.cjs +0 -179
- package/dist/sample-gas-prices-controller.cjs.map +0 -1
- package/dist/sample-gas-prices-controller.d.cts.map +0 -1
- package/dist/sample-gas-prices-controller.d.mts +0 -184
- package/dist/sample-gas-prices-controller.d.mts.map +0 -1
- package/dist/sample-gas-prices-controller.mjs.map +0 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.cjs +0 -7
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.cjs.map +0 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.cts.map +0 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.mts +0 -21
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.mts.map +0 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.mjs.map +0 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service.cjs +0 -121
- package/dist/sample-gas-prices-service/sample-gas-prices-service.cjs.map +0 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service.d.cts +0 -139
- package/dist/sample-gas-prices-service/sample-gas-prices-service.d.cts.map +0 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service.d.mts.map +0 -1
- package/dist/sample-gas-prices-service/sample-gas-prices-service.mjs.map +0 -1
- package/dist/sample-petnames-controller-method-action-types.cjs +0 -7
- package/dist/sample-petnames-controller-method-action-types.cjs.map +0 -1
- package/dist/sample-petnames-controller-method-action-types.d.cts.map +0 -1
- package/dist/sample-petnames-controller-method-action-types.d.mts +0 -22
- package/dist/sample-petnames-controller-method-action-types.d.mts.map +0 -1
- package/dist/sample-petnames-controller-method-action-types.mjs.map +0 -1
- package/dist/sample-petnames-controller.cjs +0 -130
- package/dist/sample-petnames-controller.cjs.map +0 -1
- package/dist/sample-petnames-controller.d.cts +0 -136
- package/dist/sample-petnames-controller.d.cts.map +0 -1
- package/dist/sample-petnames-controller.d.mts.map +0 -1
- package/dist/sample-petnames-controller.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,9 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [6.0.0]
|
|
11
|
+
|
|
10
12
|
### Changed
|
|
11
13
|
|
|
14
|
+
- **BREAKING:** Drop CommonJS support ([#9536](https://github.com/MetaMask/core/pull/9536))
|
|
15
|
+
- This package is now ESM-only, but can still be used in CommonJS projects via `require(esm)` in modern Node.js versions (22+), or dynamic imports in older Node.js versions.
|
|
16
|
+
- **BREAKING:** Bump minimum Node.js version to 22 ([#9976](https://github.com/MetaMask/core/pull/9976))
|
|
17
|
+
- **BREAKING:** Bump TypeScript target to ES2022 ([#10019](https://github.com/MetaMask/core/pull/10019))
|
|
18
|
+
- This package now ships ES2022 code, requiring a compatible modern environment or bundler configuration to consume.
|
|
12
19
|
- Bump `@metamask/utils` from `^11.11.0` to `^11.12.0` ([#10076](https://github.com/MetaMask/core/pull/10076))
|
|
20
|
+
- Bump `@metamask/base-controller` from `^9.1.0` to `^10.0.0` ([#10160](https://github.com/MetaMask/core/pull/10160))
|
|
21
|
+
- Bump `@metamask/base-data-service` from `^1.0.0` to `^2.0.0` ([#10160](https://github.com/MetaMask/core/pull/10160))
|
|
22
|
+
- Bump `@metamask/messenger` from `^2.0.0` to `^3.0.0` ([#10160](https://github.com/MetaMask/core/pull/10160))
|
|
23
|
+
- Bump `@metamask/network-controller` from `^36.0.0` to `^37.0.0` ([#10160](https://github.com/MetaMask/core/pull/10160))
|
|
13
24
|
|
|
14
25
|
## [5.0.6]
|
|
15
26
|
|
|
@@ -190,7 +201,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
190
201
|
|
|
191
202
|
- Initial release of @metamask/sample-controllers.
|
|
192
203
|
|
|
193
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/sample-controllers@
|
|
204
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/sample-controllers@6.0.0...HEAD
|
|
205
|
+
[6.0.0]: https://github.com/MetaMask/core/compare/@metamask/sample-controllers@5.0.6...@metamask/sample-controllers@6.0.0
|
|
194
206
|
[5.0.6]: https://github.com/MetaMask/core/compare/@metamask/sample-controllers@5.0.5...@metamask/sample-controllers@5.0.6
|
|
195
207
|
[5.0.5]: https://github.com/MetaMask/core/compare/@metamask/sample-controllers@5.0.4...@metamask/sample-controllers@5.0.5
|
|
196
208
|
[5.0.4]: https://github.com/MetaMask/core/compare/@metamask/sample-controllers@5.0.3...@metamask/sample-controllers@5.0.4
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export type { SampleGasPricesServiceInvalidateQueriesAction, SampleGasPricesServiceActions, SampleGasPricesServiceCacheUpdatedEvent, SampleGasPricesServiceGranularCacheUpdatedEvent, SampleGasPricesServiceEvents, SampleGasPricesServiceMessenger, } from
|
|
2
|
-
export type { SampleGasPricesServiceFetchGasPricesAction } from
|
|
3
|
-
export { SampleGasPricesService } from
|
|
4
|
-
export type { SampleGasPricesControllerActions, SampleGasPricesControllerEvents, SampleGasPricesControllerGetStateAction, SampleGasPricesControllerMessenger, SampleGasPricesControllerState, SampleGasPricesControllerStateChangeEvent, } from
|
|
5
|
-
export { SampleGasPricesController, getDefaultSampleGasPricesControllerState, } from
|
|
6
|
-
export type { SampleGasPricesControllerUpdateGasPricesAction } from
|
|
7
|
-
export type { SamplePetnamesControllerActions, SamplePetnamesControllerEvents, SamplePetnamesControllerGetStateAction, SamplePetnamesControllerMessenger, SamplePetnamesControllerState, SamplePetnamesControllerStateChangeEvent, } from
|
|
8
|
-
export { SamplePetnamesController, getDefaultPetnamesControllerState, } from
|
|
9
|
-
export type { SamplePetnamesControllerAssignPetnameAction } from
|
|
10
|
-
//# sourceMappingURL=index.d.
|
|
1
|
+
export type { SampleGasPricesServiceInvalidateQueriesAction, SampleGasPricesServiceActions, SampleGasPricesServiceCacheUpdatedEvent, SampleGasPricesServiceGranularCacheUpdatedEvent, SampleGasPricesServiceEvents, SampleGasPricesServiceMessenger, } from './sample-gas-prices-service/sample-gas-prices-service.js';
|
|
2
|
+
export type { SampleGasPricesServiceFetchGasPricesAction } from './sample-gas-prices-service/sample-gas-prices-service-method-action-types.js';
|
|
3
|
+
export { SampleGasPricesService } from './sample-gas-prices-service/sample-gas-prices-service.js';
|
|
4
|
+
export type { SampleGasPricesControllerActions, SampleGasPricesControllerEvents, SampleGasPricesControllerGetStateAction, SampleGasPricesControllerMessenger, SampleGasPricesControllerState, SampleGasPricesControllerStateChangeEvent, } from './sample-gas-prices-controller.js';
|
|
5
|
+
export { SampleGasPricesController, getDefaultSampleGasPricesControllerState, } from './sample-gas-prices-controller.js';
|
|
6
|
+
export type { SampleGasPricesControllerUpdateGasPricesAction } from './sample-gas-prices-controller-method-action-types.js';
|
|
7
|
+
export type { SamplePetnamesControllerActions, SamplePetnamesControllerEvents, SamplePetnamesControllerGetStateAction, SamplePetnamesControllerMessenger, SamplePetnamesControllerState, SamplePetnamesControllerStateChangeEvent, } from './sample-petnames-controller.js';
|
|
8
|
+
export { SamplePetnamesController, getDefaultPetnamesControllerState, } from './sample-petnames-controller.js';
|
|
9
|
+
export type { SamplePetnamesControllerAssignPetnameAction } from './sample-petnames-controller-method-action-types.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,6CAA6C,EAC7C,6BAA6B,EAC7B,uCAAuC,EACvC,+CAA+C,EAC/C,4BAA4B,EAC5B,+BAA+B,GAChC,MAAM,0DAA0D,CAAC;AAClE,YAAY,EAAE,0CAA0C,EAAE,MAAM,8EAA8E,CAAC;AAC/I,OAAO,EAAE,sBAAsB,EAAE,MAAM,0DAA0D,CAAC;AAClG,YAAY,EACV,gCAAgC,EAChC,+BAA+B,EAC/B,uCAAuC,EACvC,kCAAkC,EAClC,8BAA8B,EAC9B,yCAAyC,GAC1C,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,yBAAyB,EACzB,wCAAwC,GACzC,MAAM,mCAAmC,CAAC;AAC3C,YAAY,EAAE,8CAA8C,EAAE,MAAM,uDAAuD,CAAC;AAC5H,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,sCAAsC,EACtC,iCAAiC,EACjC,6BAA6B,EAC7B,wCAAwC,GACzC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,wBAAwB,EACxB,iCAAiC,GAClC,MAAM,iCAAiC,CAAC;AACzC,YAAY,EAAE,2CAA2C,EAAE,MAAM,qDAAqD,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { SampleGasPricesService } from './sample-gas-prices-service/sample-gas-prices-service.js';
|
|
2
|
+
export { SampleGasPricesController, getDefaultSampleGasPricesControllerState, } from './sample-gas-prices-controller.js';
|
|
3
|
+
export { SamplePetnamesController, getDefaultPetnamesControllerState, } from './sample-petnames-controller.js';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0DAA0D,CAAC;AASlG,OAAO,EACL,yBAAyB,EACzB,wCAAwC,GACzC,MAAM,mCAAmC,CAAC;AAU3C,OAAO,EACL,wBAAwB,EACxB,iCAAiC,GAClC,MAAM,iCAAiC,CAAC","sourcesContent":["export type {\n SampleGasPricesServiceInvalidateQueriesAction,\n SampleGasPricesServiceActions,\n SampleGasPricesServiceCacheUpdatedEvent,\n SampleGasPricesServiceGranularCacheUpdatedEvent,\n SampleGasPricesServiceEvents,\n SampleGasPricesServiceMessenger,\n} from './sample-gas-prices-service/sample-gas-prices-service.js';\nexport type { SampleGasPricesServiceFetchGasPricesAction } from './sample-gas-prices-service/sample-gas-prices-service-method-action-types.js';\nexport { SampleGasPricesService } from './sample-gas-prices-service/sample-gas-prices-service.js';\nexport type {\n SampleGasPricesControllerActions,\n SampleGasPricesControllerEvents,\n SampleGasPricesControllerGetStateAction,\n SampleGasPricesControllerMessenger,\n SampleGasPricesControllerState,\n SampleGasPricesControllerStateChangeEvent,\n} from './sample-gas-prices-controller.js';\nexport {\n SampleGasPricesController,\n getDefaultSampleGasPricesControllerState,\n} from './sample-gas-prices-controller.js';\nexport type { SampleGasPricesControllerUpdateGasPricesAction } from './sample-gas-prices-controller-method-action-types.js';\nexport type {\n SamplePetnamesControllerActions,\n SamplePetnamesControllerEvents,\n SamplePetnamesControllerGetStateAction,\n SamplePetnamesControllerMessenger,\n SamplePetnamesControllerState,\n SamplePetnamesControllerStateChangeEvent,\n} from './sample-petnames-controller.js';\nexport {\n SamplePetnamesController,\n getDefaultPetnamesControllerState,\n} from './sample-petnames-controller.js';\nexport type { SamplePetnamesControllerAssignPetnameAction } from './sample-petnames-controller-method-action-types.js';\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* This file is auto generated.
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
*/
|
|
5
|
-
import type { SampleGasPricesController } from
|
|
5
|
+
import type { SampleGasPricesController } from './sample-gas-prices-controller.js';
|
|
6
6
|
/**
|
|
7
7
|
* Fetches the latest gas prices for the given chain and persists them to
|
|
8
8
|
* state.
|
|
@@ -18,4 +18,4 @@ export type SampleGasPricesControllerUpdateGasPricesAction = {
|
|
|
18
18
|
* Union of all SampleGasPricesController action types.
|
|
19
19
|
*/
|
|
20
20
|
export type SampleGasPricesControllerMethodActions = SampleGasPricesControllerUpdateGasPricesAction;
|
|
21
|
-
//# sourceMappingURL=sample-gas-prices-controller-method-action-types.d.
|
|
21
|
+
//# sourceMappingURL=sample-gas-prices-controller-method-action-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sample-gas-prices-controller-method-action-types.d.ts","sourceRoot":"","sources":["../src/sample-gas-prices-controller-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAEnF;;;;;;GAMG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,yBAAyB,CAAC,iBAAiB,CAAC,CAAC;CACvD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,sCAAsC,GAChD,8CAA8C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sample-gas-prices-controller-method-action-types.js","sourceRoot":"","sources":["../src/sample-gas-prices-controller-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { SampleGasPricesController } from './sample-gas-prices-controller.js';\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 SampleGasPricesControllerUpdateGasPricesAction = {\n type: `SampleGasPricesController:updateGasPrices`;\n handler: SampleGasPricesController['updateGasPrices'];\n};\n\n/**\n * Union of all SampleGasPricesController action types.\n */\nexport type SampleGasPricesControllerMethodActions =\n SampleGasPricesControllerUpdateGasPricesAction;\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { ControllerGetStateAction, ControllerStateChangeEvent } from
|
|
2
|
-
import { BaseController } from
|
|
3
|
-
import type { Messenger } from
|
|
4
|
-
import type { NetworkControllerGetNetworkClientByIdAction, NetworkControllerStateChangeEvent } from
|
|
5
|
-
import type { Hex } from
|
|
6
|
-
import type { SampleGasPricesControllerMethodActions } from
|
|
7
|
-
import type { SampleGasPricesServiceFetchGasPricesAction } from
|
|
1
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent } from '@metamask/base-controller';
|
|
2
|
+
import { BaseController } from '@metamask/base-controller';
|
|
3
|
+
import type { Messenger } from '@metamask/messenger';
|
|
4
|
+
import type { NetworkControllerGetNetworkClientByIdAction, NetworkControllerStateChangeEvent } from '@metamask/network-controller';
|
|
5
|
+
import type { Hex } from '@metamask/utils';
|
|
6
|
+
import type { SampleGasPricesControllerMethodActions } from './sample-gas-prices-controller-method-action-types.js';
|
|
7
|
+
import type { SampleGasPricesServiceFetchGasPricesAction } from './sample-gas-prices-service/sample-gas-prices-service-method-action-types.js';
|
|
8
8
|
/**
|
|
9
9
|
* The name of the {@link SampleGasPricesController}, used to namespace the
|
|
10
10
|
* controller's actions and events and to namespace the controller's state data
|
|
@@ -181,4 +181,4 @@ export declare class SampleGasPricesController extends BaseController<typeof CON
|
|
|
181
181
|
}): Promise<void>;
|
|
182
182
|
}
|
|
183
183
|
export {};
|
|
184
|
-
//# sourceMappingURL=sample-gas-prices-controller.d.
|
|
184
|
+
//# sourceMappingURL=sample-gas-prices-controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sample-gas-prices-controller.d.ts","sourceRoot":"","sources":["../src/sample-gas-prices-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAEV,2CAA2C,EAC3C,iCAAiC,EAClC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,KAAK,EAAE,sCAAsC,EAAE,MAAM,uDAAuD,CAAC;AACpH,OAAO,KAAK,EAAE,0CAA0C,EAAE,MAAM,8EAA8E,CAAC;AAI/I;;;;GAIG;AACH,QAAA,MAAM,eAAe,8BAA8B,CAAC;AAIpD;;GAEG;AACH,KAAK,SAAS,GAAG;IACf;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C;;OAEG;IACH,kBAAkB,EAAE;QAClB,CAAC,OAAO,EAAE,GAAG,GAAG,SAAS,CAAC;KAC3B,CAAC;CACH,CAAC;AAcF;;;;;;;GAOG;AACH,wBAAgB,wCAAwC,IAAI,8BAA8B,CAIzF;AAMD;;GAEG;AACH,MAAM,MAAM,uCAAuC,GAAG,wBAAwB,CAC5E,OAAO,eAAe,EACtB,8BAA8B,CAC/B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gCAAgC,GACxC,uCAAuC,GACvC,sCAAsC,CAAC;AAE3C;;GAEG;AACH,KAAK,cAAc,GACf,2CAA2C,GAC3C,0CAA0C,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,yCAAyC,GACnD,0BAA0B,CACxB,OAAO,eAAe,EACtB,8BAA8B,CAC/B,CAAC;AAEJ;;GAEG;AACH,MAAM,MAAM,+BAA+B,GACzC,yCAAyC,CAAC;AAE5C;;;GAGG;AACH,KAAK,aAAa,GAAG,iCAAiC,CAAC;AAEvD;;;GAGG;AACH,MAAM,MAAM,kCAAkC,GAAG,SAAS,CACxD,OAAO,eAAe,EACtB,gCAAgC,GAAG,cAAc,EACjD,+BAA+B,GAAG,aAAa,CAChD,CAAC;AAIF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwEG;AACH,qBAAa,yBAA0B,SAAQ,cAAc,CAC3D,OAAO,eAAe,EACtB,8BAA8B,EAC9B,kCAAkC,CACnC;;IAMC;;;;;;;OAOG;IACH,YAAY,EACV,SAAS,EACT,KAAK,GACN,EAAE;QACD,SAAS,EAAE,kCAAkC,CAAC;QAC9C,KAAK,CAAC,EAAE,OAAO,CAAC,8BAA8B,CAAC,CAAC;KACjD,EAsBA;IAED;;;;;;OAMG;IACG,eAAe,CAAC,EAAE,OAAO,EAAE,EAAE;QAAE,OAAO,EAAE,GAAG,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAYlE;CAyBF"}
|
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
-
};
|
|
6
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
-
};
|
|
12
|
-
var _SampleGasPricesController_instances, _SampleGasPricesController_selectedChainId, _SampleGasPricesController_onSelectedNetworkClientIdChange;
|
|
13
|
-
import { BaseController } from "@metamask/base-controller";
|
|
1
|
+
import { BaseController } from '@metamask/base-controller';
|
|
14
2
|
// === GENERAL ===
|
|
15
3
|
/**
|
|
16
4
|
* The name of the {@link SampleGasPricesController}, used to namespace the
|
|
@@ -119,6 +107,10 @@ const MESSENGER_EXPOSED_METHODS = ['updateGasPrices'];
|
|
|
119
107
|
* ```
|
|
120
108
|
*/
|
|
121
109
|
export class SampleGasPricesController extends BaseController {
|
|
110
|
+
/**
|
|
111
|
+
* The globally selected chain ID.
|
|
112
|
+
*/
|
|
113
|
+
#selectedChainId;
|
|
122
114
|
/**
|
|
123
115
|
* Constructs a new {@link SampleGasPricesController}.
|
|
124
116
|
*
|
|
@@ -137,13 +129,8 @@ export class SampleGasPricesController extends BaseController {
|
|
|
137
129
|
...state,
|
|
138
130
|
},
|
|
139
131
|
});
|
|
140
|
-
_SampleGasPricesController_instances.add(this);
|
|
141
|
-
/**
|
|
142
|
-
* The globally selected chain ID.
|
|
143
|
-
*/
|
|
144
|
-
_SampleGasPricesController_selectedChainId.set(this, void 0);
|
|
145
132
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
146
|
-
this.messenger.subscribe('NetworkController:stateChange',
|
|
133
|
+
this.messenger.subscribe('NetworkController:stateChange', this.#onSelectedNetworkClientIdChange.bind(this), (networkControllerState) => networkControllerState.selectedNetworkClientId);
|
|
147
134
|
}
|
|
148
135
|
/**
|
|
149
136
|
* Fetches the latest gas prices for the given chain and persists them to
|
|
@@ -161,14 +148,20 @@ export class SampleGasPricesController extends BaseController {
|
|
|
161
148
|
};
|
|
162
149
|
});
|
|
163
150
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
});
|
|
151
|
+
/**
|
|
152
|
+
* Callback to call when the globally selected network client ID changes,
|
|
153
|
+
* ensuring that gas prices get updated.
|
|
154
|
+
*
|
|
155
|
+
* @param selectedNetworkClientId - The globally selected network client ID.
|
|
156
|
+
*/
|
|
157
|
+
#onSelectedNetworkClientIdChange(selectedNetworkClientId) {
|
|
158
|
+
const { configuration: { chainId }, } = this.messenger.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
|
|
159
|
+
if (chainId !== this.#selectedChainId) {
|
|
160
|
+
this.#selectedChainId = chainId;
|
|
161
|
+
this.updateGasPrices({ chainId }).catch((error) => {
|
|
162
|
+
this.messenger.captureException?.(error);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
172
165
|
}
|
|
173
|
-
}
|
|
174
|
-
//# sourceMappingURL=sample-gas-prices-controller.
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=sample-gas-prices-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sample-gas-prices-controller.js","sourceRoot":"","sources":["../src/sample-gas-prices-controller.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAY3D,kBAAkB;AAElB;;;;GAIG;AACH,MAAM,eAAe,GAAG,2BAA2B,CAAC;AAsCpD;;GAEG;AACH,MAAM,2BAA2B,GAAG;IAClC,kBAAkB,EAAE;QAClB,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,IAAI;KACf;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;AAuD/D,gCAAgC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwEG;AACH,MAAM,OAAO,yBAA0B,SAAQ,cAI9C;IACC;;OAEG;IACH,gBAAgB,CAAkB;IAElC;;;;;;;OAOG;IACH,YAAY,EACV,SAAS,EACT,KAAK,GAIN;QACC,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,2BAA2B;YACrC,IAAI,EAAE,eAAe;YACrB,KAAK,EAAE;gBACL,GAAG,wCAAwC,EAAE;gBAC7C,GAAG,KAAK;aACT;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,CAAC,4BAA4B,CACzC,IAAI,EACJ,yBAAyB,CAC1B,CAAC;QAEF,IAAI,CAAC,SAAS,CAAC,SAAS,CACtB,+BAA+B,EAC/B,IAAI,CAAC,gCAAgC,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,SAAS,CAAC,IAAI,CACjD,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;IAED;;;;;OAKG;IACH,gCAAgC,CAC9B,uBAAwC;QAExC,MAAM,EACJ,aAAa,EAAE,EAAE,OAAO,EAAE,GAC3B,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CACrB,wCAAwC,EACxC,uBAAuB,CACxB,CAAC;QAEF,IAAI,OAAO,KAAK,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtC,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC;YAChC,IAAI,CAAC,eAAe,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;gBAChD,IAAI,CAAC,SAAS,CAAC,gBAAgB,EAAE,CAAC,KAAK,CAAC,CAAC;YAC3C,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\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.js';\nimport type { SampleGasPricesServiceFetchGasPricesAction } from './sample-gas-prices-service/sample-gas-prices-service-method-action-types.js';\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 */\nconst CONTROLLER_NAME = '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 includeInDebugSnapshot: false,\n includeInStateLogs: true,\n persist: true,\n usedInUi: true,\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 CONTROLLER_NAME,\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 CONTROLLER_NAME,\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 = Messenger<\n typeof CONTROLLER_NAME,\n SampleGasPricesControllerActions | AllowedActions,\n SampleGasPricesControllerEvents | AllowedEvents\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/messenger';\n * import type {\n * NetworkControllerActions,\n * NetworkControllerEvents,\n * } from '@metamask/network-controller';\n * import type {\n * SampleGasPricesControllerActions,\n * SampleGasPricesControllerEvents,\n * SampleGasPricesServiceActions,\n * SampleGasPricesServiceEvents,\n * } from '@metamask/sample-controllers';\n * import {\n * SampleGasPricesController,\n * SampleGasPricesService,\n * selectGasPrices,\n * } from '@metamask/sample-controllers';\n *\n * const rootMessenger = new Messenger<\n * 'Root',\n * SampleGasPricesServiceActions\n * | SampleGasPricesControllerActions\n * | NetworkControllerActions,\n * SampleGasPricesServiceEvents\n * | SampleGasPricesControllerEvents\n * | NetworkControllerEvents\n * >({ namespace: 'Root' });\n * const gasPricesServiceMessenger = new Messenger<\n * 'SampleGasPricesService',\n * SampleGasPricesServiceActions,\n * SampleGasPricesServiceEvents,\n * typeof rootMessenger,\n * >({\n * namespace: 'SampleGasPricesService',\n * parent: rootMessenger,\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 = new Messenger<\n * 'SampleGasPricesController',\n * SampleGasPricesControllerActions | NetworkControllerGetNetworkClientByIdAction,\n * SampleGasPricesControllerEvents | NetworkControllerStateChangeEvent,\n * typeof rootMessenger,\n * >({\n * namespace: 'SampleGasPricesController',\n * parent: rootMessenger,\n * });\n * // Instantiate the controller to register its actions on the messenger\n * new SampleGasPricesController({\n * messenger: gasPricesControllerMessenger,\n * });\n *\n * // Later...\n * await rootMessenger.call(\n * 'SampleGasPricesController:updateGasPrices',\n * { chainId: '0x42' },\n * );\n * const gasPricesControllerState = await rootMessenger.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 CONTROLLER_NAME,\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: CONTROLLER_NAME,\n state: {\n ...getDefaultSampleGasPricesControllerState(),\n ...state,\n },\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n this.messenger.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 }): Promise<void> {\n const gasPricesResponse = await this.messenger.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 #onSelectedNetworkClientIdChange(\n selectedNetworkClientId: NetworkClientId,\n ): void {\n const {\n configuration: { chainId },\n } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n );\n\n if (chainId !== this.#selectedChainId) {\n this.#selectedChainId = chainId;\n this.updateGasPrices({ chainId }).catch((error) => {\n this.messenger.captureException?.(error);\n });\n }\n }\n}\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* This file is auto generated.
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
*/
|
|
5
|
-
import type { SampleGasPricesService } from
|
|
5
|
+
import type { SampleGasPricesService } from './sample-gas-prices-service.js';
|
|
6
6
|
/**
|
|
7
7
|
* Makes a request to the API in order to retrieve gas prices for a particular
|
|
8
8
|
* chain.
|
|
@@ -18,4 +18,4 @@ export type SampleGasPricesServiceFetchGasPricesAction = {
|
|
|
18
18
|
* Union of all SampleGasPricesService action types.
|
|
19
19
|
*/
|
|
20
20
|
export type SampleGasPricesServiceMethodActions = SampleGasPricesServiceFetchGasPricesAction;
|
|
21
|
-
//# sourceMappingURL=sample-gas-prices-service-method-action-types.d.
|
|
21
|
+
//# sourceMappingURL=sample-gas-prices-service-method-action-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sample-gas-prices-service-method-action-types.d.ts","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,MAAM,gCAAgC,CAAC;AAE7E;;;;;;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.js","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.\n * Do not edit manually.\n */\n\nimport type { SampleGasPricesService } from './sample-gas-prices-service.js';\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 */\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"]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { BaseDataService } from
|
|
2
|
-
import type { DataServiceCacheUpdatedEvent, DataServiceGranularCacheUpdatedEvent, DataServiceInvalidateQueriesAction } from
|
|
3
|
-
import type { CreateServicePolicyOptions } from
|
|
4
|
-
import type { Messenger } from
|
|
5
|
-
import type { Infer } from
|
|
6
|
-
import type { Hex } from
|
|
7
|
-
import type { QueryClientConfig } from
|
|
8
|
-
import type { SampleGasPricesServiceMethodActions } from
|
|
1
|
+
import { BaseDataService } from '@metamask/base-data-service';
|
|
2
|
+
import type { DataServiceCacheUpdatedEvent, DataServiceGranularCacheUpdatedEvent, DataServiceInvalidateQueriesAction } from '@metamask/base-data-service';
|
|
3
|
+
import type { CreateServicePolicyOptions } from '@metamask/controller-utils';
|
|
4
|
+
import type { Messenger } from '@metamask/messenger';
|
|
5
|
+
import type { Infer } from '@metamask/superstruct';
|
|
6
|
+
import type { Hex } from '@metamask/utils';
|
|
7
|
+
import type { QueryClientConfig } from '@tanstack/query-core';
|
|
8
|
+
import type { SampleGasPricesServiceMethodActions } from './sample-gas-prices-service-method-action-types.js';
|
|
9
9
|
/**
|
|
10
10
|
* The name of the {@link SampleGasPricesService}, used to namespace the
|
|
11
11
|
* service's actions and events.
|
|
@@ -136,4 +136,4 @@ export declare class SampleGasPricesService extends BaseDataService<typeof servi
|
|
|
136
136
|
fetchGasPrices(chainId: Hex): Promise<GasPricesResponse['data']>;
|
|
137
137
|
}
|
|
138
138
|
export {};
|
|
139
|
-
//# sourceMappingURL=sample-gas-prices-service.d.
|
|
139
|
+
//# sourceMappingURL=sample-gas-prices-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sample-gas-prices-service.d.ts","sourceRoot":"","sources":["../../src/sample-gas-prices-service/sample-gas-prices-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAE7E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,oDAAoD,CAAC;AAI9G;;;GAGG;AACH,eAAO,MAAM,WAAW,2BAA2B,CAAC;AAUpD;;GAEG;AACH,MAAM,MAAM,6CAA6C,GACvD,kCAAkC,CAAC,OAAO,WAAW,CAAC,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,mCAAmC,GACnC,6CAA6C,CAAC;AAElD;;GAEG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;GAEG;AACH,MAAM,MAAM,uCAAuC,GACjD,4BAA4B,CAAC,OAAO,WAAW,CAAC,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,+CAA+C,GACzD,oCAAoC,CAAC,OAAO,WAAW,CAAC,CAAC;AAE3D;;GAEG;AACH,MAAM,MAAM,4BAA4B,GACpC,uCAAuC,GACvC,+CAA+C,CAAC;AAEpD;;;GAGG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,+BAA+B,GAAG,SAAS,CACrD,OAAO,WAAW,EAClB,6BAA6B,GAAG,cAAc,EAC9C,4BAA4B,GAAG,aAAa,CAC7C,CAAC;AAIF;;GAEG;AACH,QAAA,MAAM,uBAAuB;;;;;;;;;;;;;;;;EAM3B,CAAC;AAEH;;GAEG;AACH,KAAK,iBAAiB,GAAG,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAO/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,qBAAa,sBAAuB,SAAQ,eAAe,CACzD,OAAO,WAAW,EAClB,+BAA+B,CAChC;IACC;;;;;;;;;OASG;IACH,YAAY,EACV,SAAS,EACT,iBAAsB,EACtB,aAAkB,GACnB,EAAE;QACD,SAAS,EAAE,+BAA+B,CAAC;QAC3C,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;QACtC,aAAa,CAAC,EAAE,0BAA0B,CAAC;KAC5C,EAYA;IAED;;;;;;OAMG;IACG,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAyBrE;CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BaseDataService } from
|
|
2
|
-
import { HttpError, fromHex } from
|
|
3
|
-
import { is, number, type } from
|
|
1
|
+
import { BaseDataService } from '@metamask/base-data-service';
|
|
2
|
+
import { HttpError, fromHex } from '@metamask/controller-utils';
|
|
3
|
+
import { is, number, type } from '@metamask/superstruct';
|
|
4
4
|
// === GENERAL ===
|
|
5
5
|
/**
|
|
6
6
|
* The name of the {@link SampleGasPricesService}, used to namespace the
|
|
@@ -114,4 +114,4 @@ export class SampleGasPricesService extends BaseDataService {
|
|
|
114
114
|
return jsonResponse.data;
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
-
//# sourceMappingURL=sample-gas-prices-service.
|
|
117
|
+
//# sourceMappingURL=sample-gas-prices-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sample-gas-prices-service.js","sourceRoot":"","sources":["../../src/sample-gas-prices-service/sample-gas-prices-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAO9D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAGhE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAMzD,kBAAkB;AAElB;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,wBAAwB,CAAC;AAEpD,oBAAoB;AAEpB;;;GAGG;AACH,MAAM,yBAAyB,GAAG,CAAC,gBAAgB,CAAU,CAAC;AAwD9D,6BAA6B;AAE7B;;GAEG;AACH,MAAM,uBAAuB,GAAG,IAAI,CAAC;IACnC,IAAI,EAAE,IAAI,CAAC;QACT,GAAG,EAAE,MAAM,EAAE;QACb,OAAO,EAAE,MAAM,EAAE;QACjB,IAAI,EAAE,MAAM,EAAE;KACf,CAAC;CACH,CAAC,CAAC;AAOH;;GAEG;AACH,MAAM,QAAQ,GAAG,yBAAyB,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,OAAO,sBAAuB,SAAQ,eAG3C;IACC;;;;;;;;;OASG;IACH,YAAY,EACV,SAAS,EACT,iBAAiB,GAAG,EAAE,EACtB,aAAa,GAAG,EAAE,GAKnB;QACC,KAAK,CAAC;YACJ,IAAI,EAAE,WAAW;YACjB,SAAS;YACT,iBAAiB;YACjB,aAAa;SACd,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,CAAC,4BAA4B,CACzC,IAAI,EACJ,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,cAAc,CAAC,OAAY;QAC/B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;QAC7C,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,SAAS,EAAE,UAAU,OAAO,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAE5E,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC;YACzC,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,iBAAiB,EAAE,OAAO,CAAC;YAClD,OAAO,EAAE,KAAK,IAAI,EAAE;gBAClB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;gBAElC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;oBACjB,MAAM,IAAI,SAAS,CACjB,QAAQ,CAAC,MAAM,EACf,sCAAsC,QAAQ,CAAC,MAAM,GAAG,CACzD,CAAC;gBACJ,CAAC;gBAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;YACzB,CAAC;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,EAAE,CAAC,YAAY,EAAE,uBAAuB,CAAC,EAAE,CAAC;YAC/C,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACrE,CAAC;QAED,OAAO,YAAY,CAAC,IAAI,CAAC;IAC3B,CAAC;CACF","sourcesContent":["import { BaseDataService } from '@metamask/base-data-service';\nimport type {\n DataServiceCacheUpdatedEvent,\n DataServiceGranularCacheUpdatedEvent,\n DataServiceInvalidateQueriesAction,\n} from '@metamask/base-data-service';\nimport type { CreateServicePolicyOptions } from '@metamask/controller-utils';\nimport { HttpError, fromHex } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type { Infer } from '@metamask/superstruct';\nimport { is, number, type } from '@metamask/superstruct';\nimport type { Hex } from '@metamask/utils';\nimport type { QueryClientConfig } from '@tanstack/query-core';\n\nimport type { SampleGasPricesServiceMethodActions } from './sample-gas-prices-service-method-action-types.js';\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\n/**\n * All of the methods within {@link SampleGasPricesService} that are exposed via\n * the messenger.\n */\nconst MESSENGER_EXPOSED_METHODS = ['fetchGasPrices'] as const;\n\n/**\n * Invalidates cached queries for {@link SampleGasPricesService}.\n */\nexport type SampleGasPricesServiceInvalidateQueriesAction =\n DataServiceInvalidateQueriesAction<typeof serviceName>;\n\n/**\n * Actions that {@link SampleGasPricesService} exposes to other consumers.\n */\nexport type SampleGasPricesServiceActions =\n | SampleGasPricesServiceMethodActions\n | SampleGasPricesServiceInvalidateQueriesAction;\n\n/**\n * Actions from other messengers that {@link SampleGasPricesService} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Published when {@link SampleGasPricesService}'s cache is updated.\n */\nexport type SampleGasPricesServiceCacheUpdatedEvent =\n DataServiceCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Published when a key within {@link SampleGasPricesService}'s cache is\n * updated.\n */\nexport type SampleGasPricesServiceGranularCacheUpdatedEvent =\n DataServiceGranularCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Events that {@link SampleGasPricesService} exposes to other consumers.\n */\nexport type SampleGasPricesServiceEvents =\n | SampleGasPricesServiceCacheUpdatedEvent\n | SampleGasPricesServiceGranularCacheUpdatedEvent;\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 = Messenger<\n typeof serviceName,\n SampleGasPricesServiceActions | AllowedActions,\n SampleGasPricesServiceEvents | AllowedEvents\n>;\n\n// === SERVICE DEFINITION ===\n\n/**\n * Struct to validate what the API endpoint returns.\n */\nconst GasPricesResponseStruct = type({\n data: type({\n low: number(),\n average: number(),\n high: number(),\n }),\n});\n\n/**\n * What the API endpoint returns.\n */\ntype GasPricesResponse = Infer<typeof GasPricesResponseStruct>;\n\n/**\n * The base URL of the API that the service represents.\n */\nconst BASE_URL = 'https://api.example.com';\n\n/**\n * This service object is responsible for fetching gas prices via an API.\n *\n * @example\n *\n * ``` ts\n * import type { MessengerActions, MessengerEvents } from '@metamask/messenger';\n * import { Messenger } from '@metamask/messenger';\n * import type {\n * SampleGasPricesServiceMessenger,\n * } from '@metamask/sample-controllers';\n *\n * const rootMessenger = new Messenger<\n * 'Root',\n * SampleGasPricesServiceActions\n * SampleGasPricesServiceEvents\n * >({ namespace: 'Root' });\n * const gasPricesServiceMessenger = new Messenger<\n * 'SampleGasPricesService',\n * MessengerActions<SampleGasPricesServiceMessenger>,\n * MessengerEvents<SampleGasPricesServiceMessenger>,\n * typeof rootMessenger,\n * >({\n * namespace: 'SampleGasPricesService',\n * parent: rootMessenger,\n * });\n * // Instantiate the service to register its actions on the messenger\n * new SampleGasPricesService({\n * messenger: gasPricesServiceMessenger,\n * });\n *\n * // Later...\n * // Fetch gas prices for Mainnet\n * const gasPrices = await rootMessenger.call(\n * 'SampleGasPricesService:fetchGasPrices',\n * '0x1',\n * );\n * // ... Do something with the gas prices ...\n * ```\n */\nexport class SampleGasPricesService extends BaseDataService<\n typeof serviceName,\n SampleGasPricesServiceMessenger\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.queryClientConfig - Configuration for the underlying TanStack\n * Query client.\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 queryClientConfig = {},\n policyOptions = {},\n }: {\n messenger: SampleGasPricesServiceMessenger;\n queryClientConfig?: QueryClientConfig;\n policyOptions?: CreateServicePolicyOptions;\n }) {\n super({\n name: serviceName,\n messenger,\n queryClientConfig,\n policyOptions,\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\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 url = new URL('/gas-prices', BASE_URL);\n url.searchParams.append('chainId', `eip155:${fromHex(chainId).toString()}`);\n\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:fetchGasPrices`, chainId],\n queryFn: async () => {\n const response = await fetch(url);\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Gas prices API failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n if (!is(jsonResponse, GasPricesResponseStruct)) {\n throw new Error('Malformed response received from gas prices API');\n }\n\n return jsonResponse.data;\n }\n}\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* This file is auto generated.
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
*/
|
|
5
|
-
import type { SamplePetnamesController } from
|
|
5
|
+
import type { SamplePetnamesController } from './sample-petnames-controller.js';
|
|
6
6
|
/**
|
|
7
7
|
* Registers the given name with the given address (relative to the given
|
|
8
8
|
* chain).
|
|
@@ -19,4 +19,4 @@ export type SamplePetnamesControllerAssignPetnameAction = {
|
|
|
19
19
|
* Union of all SamplePetnamesController action types.
|
|
20
20
|
*/
|
|
21
21
|
export type SamplePetnamesControllerMethodActions = SamplePetnamesControllerAssignPetnameAction;
|
|
22
|
-
//# sourceMappingURL=sample-petnames-controller-method-action-types.d.
|
|
22
|
+
//# sourceMappingURL=sample-petnames-controller-method-action-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sample-petnames-controller-method-action-types.d.ts","sourceRoot":"","sources":["../src/sample-petnames-controller-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAEhF;;;;;;;GAOG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,wBAAwB,CAAC,eAAe,CAAC,CAAC;CACpD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qCAAqC,GAC/C,2CAA2C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sample-petnames-controller-method-action-types.js","sourceRoot":"","sources":["../src/sample-petnames-controller-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { SamplePetnamesController } from './sample-petnames-controller.js';\n\n/**\n * Registers the given name with the given address (relative to the given\n * chain).\n *\n * @param chainId - The chain ID that the address belongs to.\n * @param address - The account address to name.\n * @param name - The name to assign to the address.\n */\nexport type SamplePetnamesControllerAssignPetnameAction = {\n type: `SamplePetnamesController:assignPetname`;\n handler: SamplePetnamesController['assignPetname'];\n};\n\n/**\n * Union of all SamplePetnamesController action types.\n */\nexport type SamplePetnamesControllerMethodActions =\n SamplePetnamesControllerAssignPetnameAction;\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ControllerGetStateAction, ControllerStateChangeEvent } from
|
|
2
|
-
import { BaseController } from
|
|
3
|
-
import type { Messenger } from
|
|
4
|
-
import type { Hex } from
|
|
5
|
-
import type { SamplePetnamesControllerMethodActions } from
|
|
1
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent } from '@metamask/base-controller';
|
|
2
|
+
import { BaseController } from '@metamask/base-controller';
|
|
3
|
+
import type { Messenger } from '@metamask/messenger';
|
|
4
|
+
import type { Hex } from '@metamask/utils';
|
|
5
|
+
import type { SamplePetnamesControllerMethodActions } from './sample-petnames-controller-method-action-types.js';
|
|
6
6
|
/**
|
|
7
7
|
* The name of the {@link SamplePetnamesController}, used to namespace the
|
|
8
8
|
* controller's actions and events and to namespace the controller's state data
|
|
@@ -133,4 +133,4 @@ export declare class SamplePetnamesController extends BaseController<typeof CONT
|
|
|
133
133
|
assignPetname(chainId: Hex, address: Hex, name: string): void;
|
|
134
134
|
}
|
|
135
135
|
export {};
|
|
136
|
-
//# sourceMappingURL=sample-petnames-controller.d.
|
|
136
|
+
//# sourceMappingURL=sample-petnames-controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sample-petnames-controller.d.ts","sourceRoot":"","sources":["../src/sample-petnames-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,qDAAqD,CAAC;AAIjH;;;;GAIG;AACH,QAAA,MAAM,eAAe,6BAA6B,CAAC;AAInD;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C;;;OAGG;IACH,wBAAwB,EAAE;QACxB,CAAC,OAAO,EAAE,GAAG,GAAG;YACd,CAAC,OAAO,EAAE,GAAG,GAAG,MAAM,CAAC;SACxB,CAAC;KACH,CAAC;CACH,CAAC;AAcF;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,IAAI,6BAA6B,CAIjF;AAMD;;GAEG;AACH,MAAM,MAAM,sCAAsC,GAAG,wBAAwB,CAC3E,OAAO,eAAe,EACtB,6BAA6B,CAC9B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,+BAA+B,GACvC,sCAAsC,GACtC,qCAAqC,CAAC;AAE1C;;GAEG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;GAEG;AACH,MAAM,MAAM,wCAAwC,GAClD,0BAA0B,CACxB,OAAO,eAAe,EACtB,6BAA6B,CAC9B,CAAC;AAEJ;;GAEG;AACH,MAAM,MAAM,8BAA8B,GACxC,wCAAwC,CAAC;AAE3C;;;GAGG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,iCAAiC,GAAG,SAAS,CACvD,OAAO,eAAe,EACtB,+BAA+B,GAAG,cAAc,EAChD,8BAA8B,GAAG,aAAa,CAC/C,CAAC;AAIF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,qBAAa,wBAAyB,SAAQ,cAAc,CAC1D,OAAO,eAAe,EACtB,6BAA6B,EAC7B,iCAAiC,CAClC;IACC;;;;;;;OAOG;IACH,YAAY,EACV,SAAS,EACT,KAAK,GACN,EAAE;QACD,SAAS,EAAE,iCAAiC,CAAC;QAC7C,KAAK,CAAC,EAAE,OAAO,CAAC,6BAA6B,CAAC,CAAC;KAChD,EAeA;IAED;;;;;;;OAOG;IACH,aAAa,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAW5D;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BaseController } from
|
|
2
|
-
import { isSafeDynamicKey } from
|
|
1
|
+
import { BaseController } from '@metamask/base-controller';
|
|
2
|
+
import { isSafeDynamicKey } from '@metamask/controller-utils';
|
|
3
3
|
// === GENERAL ===
|
|
4
4
|
/**
|
|
5
5
|
* The name of the {@link SamplePetnamesController}, used to namespace the
|
|
@@ -116,10 +116,9 @@ export class SamplePetnamesController extends BaseController {
|
|
|
116
116
|
}
|
|
117
117
|
const normalizedAddress = address.toLowerCase();
|
|
118
118
|
this.update((state) => {
|
|
119
|
-
|
|
120
|
-
(_a = state.namesByChainIdAndAddress)[chainId] ?? (_a[chainId] = {});
|
|
119
|
+
state.namesByChainIdAndAddress[chainId] ??= {};
|
|
121
120
|
state.namesByChainIdAndAddress[chainId][normalizedAddress] = name;
|
|
122
121
|
});
|
|
123
122
|
}
|
|
124
123
|
}
|
|
125
|
-
//# sourceMappingURL=sample-petnames-controller.
|
|
124
|
+
//# sourceMappingURL=sample-petnames-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sample-petnames-controller.js","sourceRoot":"","sources":["../src/sample-petnames-controller.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAM9D,kBAAkB;AAElB;;;;GAIG;AACH,MAAM,eAAe,GAAG,0BAA0B,CAAC;AAmBnD;;GAEG;AACH,MAAM,gCAAgC,GAAG;IACvC,wBAAwB,EAAE;QACxB,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,IAAI;KACf;CACqD,CAAC;AAEzD;;;;;;;GAOG;AACH,MAAM,UAAU,iCAAiC;IAC/C,OAAO;QACL,wBAAwB,EAAE,EAAE;KAC7B,CAAC;AACJ,CAAC;AAED,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG,CAAC,eAAe,CAAU,CAAC;AAqD7D,gCAAgC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,OAAO,wBAAyB,SAAQ,cAI7C;IACC;;;;;;;OAOG;IACH,YAAY,EACV,SAAS,EACT,KAAK,GAIN;QACC,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,gCAAgC;YAC1C,IAAI,EAAE,eAAe;YACrB,KAAK,EAAE;gBACL,GAAG,iCAAiC,EAAE;gBACtC,GAAG,KAAK;aACT;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,CAAC,4BAA4B,CACzC,IAAI,EACJ,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACH,aAAa,CAAC,OAAY,EAAE,OAAY,EAAE,IAAY;QACpD,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;QACtC,CAAC;QAED,MAAM,iBAAiB,GAAG,OAAO,CAAC,WAAW,EAAS,CAAC;QAEvD,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,wBAAwB,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YAC/C,KAAK,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAAC;QACpE,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { isSafeDynamicKey } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type { Hex } from '@metamask/utils';\n\nimport type { SamplePetnamesControllerMethodActions } from './sample-petnames-controller-method-action-types.js';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link SamplePetnamesController}, 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 */\nconst CONTROLLER_NAME = 'SamplePetnamesController';\n\n// === STATE ===\n\n/**\n * Describes the shape of the state object for {@link SamplePetnamesController}.\n */\nexport type SamplePetnamesControllerState = {\n /**\n * The registry of pet names, categorized by chain ID first and address\n * second.\n */\n namesByChainIdAndAddress: {\n [chainId: Hex]: {\n [address: Hex]: string;\n };\n };\n};\n\n/**\n * The metadata for each property in {@link SamplePetnamesControllerState}.\n */\nconst samplePetnamesControllerMetadata = {\n namesByChainIdAndAddress: {\n includeInDebugSnapshot: false,\n includeInStateLogs: true,\n persist: true,\n usedInUi: true,\n },\n} satisfies StateMetadata<SamplePetnamesControllerState>;\n\n/**\n * Constructs the default {@link SamplePetnamesController} 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 SamplePetnamesController} state.\n */\nexport function getDefaultPetnamesControllerState(): SamplePetnamesControllerState {\n return {\n namesByChainIdAndAddress: {},\n };\n}\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = ['assignPetname'] as const;\n\n/**\n * Retrieves the state of the {@link SamplePetnamesController}.\n */\nexport type SamplePetnamesControllerGetStateAction = ControllerGetStateAction<\n typeof CONTROLLER_NAME,\n SamplePetnamesControllerState\n>;\n\n/**\n * Actions that {@link SampleGasPricesMessenger} exposes to other consumers.\n */\nexport type SamplePetnamesControllerActions =\n | SamplePetnamesControllerGetStateAction\n | SamplePetnamesControllerMethodActions;\n\n/**\n * Actions from other messengers that {@link SampleGasPricesMessenger} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Published when the state of {@link SamplePetnamesController} changes.\n */\nexport type SamplePetnamesControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof CONTROLLER_NAME,\n SamplePetnamesControllerState\n >;\n\n/**\n * Events that {@link SampleGasPricesMessenger} exposes to other consumers.\n */\nexport type SamplePetnamesControllerEvents =\n SamplePetnamesControllerStateChangeEvent;\n\n/**\n * Events from other messengers that {@link SampleGasPricesMessenger} subscribes\n * to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link SamplePetnamesController}.\n */\nexport type SamplePetnamesControllerMessenger = Messenger<\n typeof CONTROLLER_NAME,\n SamplePetnamesControllerActions | AllowedActions,\n SamplePetnamesControllerEvents | AllowedEvents\n>;\n\n// === CONTROLLER DEFINITION ===\n\n/**\n * `SamplePetnamesController` records user-provided nicknames for various\n * addresses on various chains.\n *\n * @example\n *\n * ``` ts\n * import { Messenger } from '@metamask/messenger';\n * import type {\n * SamplePetnamesControllerActions,\n * SamplePetnamesControllerEvents,\n * } from '@metamask/sample-controllers';\n *\n * const rootMessenger = new Messenger<\n * 'Root',\n * SamplePetnamesControllerActions,\n * SamplePetnamesControllerEvents\n * >({ namespace: 'Root' });\n * const samplePetnamesMessenger = new Messenger<\n * 'SamplePetnamesController',\n * SamplePetnamesControllerActions,\n * SamplePetnamesControllerEvents,\n * typeof rootMessenger,\n * >({\n * namespace: 'SamplePetnamesController',\n * parent: rootMessenger,\n * });\n * // Instantiate the controller to register its actions on the messenger\n * new SamplePetnamesController({\n * messenger: samplePetnamesMessenger,\n * });\n *\n * rootMessenger.call(\n * 'SamplePetnamesController:assignPetname',\n * [\n * '0x1',\n * '0xF57F855e17483B1f09bFec62783C9d3b6c8b3A99',\n * 'Primary Account',\n * ],\n * );\n * const samplePetnamesControllerState = await rootMessenger.call(\n * 'SamplePetnamesController:getState',\n * );\n * samplePetnamesControllerState.namesByChainIdAndAddress\n * // => { '0x1': { '0xF57F855e17483B1f09bFec62783C9d3b6c8b3A99': 'Primary Account' } }\n * ```\n */\nexport class SamplePetnamesController extends BaseController<\n typeof CONTROLLER_NAME,\n SamplePetnamesControllerState,\n SamplePetnamesControllerMessenger\n> {\n /**\n * Constructs a new {@link SamplePetnamesController}.\n *\n * @param args - The arguments to this 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 */\n constructor({\n messenger,\n state,\n }: {\n messenger: SamplePetnamesControllerMessenger;\n state?: Partial<SamplePetnamesControllerState>;\n }) {\n super({\n messenger,\n metadata: samplePetnamesControllerMetadata,\n name: CONTROLLER_NAME,\n state: {\n ...getDefaultPetnamesControllerState(),\n ...state,\n },\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Registers the given name with the given address (relative to the given\n * chain).\n *\n * @param chainId - The chain ID that the address belongs to.\n * @param address - The account address to name.\n * @param name - The name to assign to the address.\n */\n assignPetname(chainId: Hex, address: Hex, name: string): void {\n if (!isSafeDynamicKey(chainId)) {\n throw new Error('Invalid chain ID');\n }\n\n const normalizedAddress = address.toLowerCase() as Hex;\n\n this.update((state) => {\n state.namesByChainIdAndAddress[chainId] ??= {};\n state.namesByChainIdAndAddress[chainId][normalizedAddress] = name;\n });\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/sample-controllers",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-preview-0a30e47",
|
|
4
4
|
"description": "Sample package to illustrate best practices for controllers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -18,19 +18,12 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"dist/"
|
|
20
20
|
],
|
|
21
|
+
"type": "module",
|
|
21
22
|
"sideEffects": false,
|
|
22
|
-
"main": "./dist/index.cjs",
|
|
23
|
-
"types": "./dist/index.d.cts",
|
|
24
23
|
"exports": {
|
|
25
24
|
".": {
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
"default": "./dist/index.mjs"
|
|
29
|
-
},
|
|
30
|
-
"require": {
|
|
31
|
-
"types": "./dist/index.d.cts",
|
|
32
|
-
"default": "./dist/index.cjs"
|
|
33
|
-
}
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
34
27
|
},
|
|
35
28
|
"./package.json": "./package.json"
|
|
36
29
|
},
|
|
@@ -39,9 +32,11 @@
|
|
|
39
32
|
"registry": "https://registry.npmjs.org/"
|
|
40
33
|
},
|
|
41
34
|
"scripts": {
|
|
42
|
-
"build": "
|
|
43
|
-
"build:all": "
|
|
35
|
+
"build": "tsc --project tsconfig.build.json",
|
|
36
|
+
"build:all": "tsc --build tsconfig.build.json --verbose",
|
|
37
|
+
"build:clean": "yarn build:only-clean && yarn build",
|
|
44
38
|
"build:docs": "typedoc",
|
|
39
|
+
"build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
|
|
45
40
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/sample-controllers",
|
|
46
41
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/sample-controllers",
|
|
47
42
|
"lint:tsconfigs": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts",
|
|
@@ -55,29 +50,30 @@
|
|
|
55
50
|
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
56
51
|
},
|
|
57
52
|
"dependencies": {
|
|
58
|
-
"@metamask/base-controller": "^
|
|
59
|
-
"@metamask/base-data-service": "^
|
|
60
|
-
"@metamask/messenger": "^
|
|
61
|
-
"@metamask/network-controller": "^
|
|
53
|
+
"@metamask/base-controller": "^10.0.0",
|
|
54
|
+
"@metamask/base-data-service": "^2.0.0",
|
|
55
|
+
"@metamask/messenger": "^3.0.0",
|
|
56
|
+
"@metamask/network-controller": "^37.0.0",
|
|
62
57
|
"@metamask/superstruct": "^3.4.1",
|
|
63
58
|
"@metamask/utils": "^11.12.0",
|
|
64
59
|
"@tanstack/query-core": "^5.62.16"
|
|
65
60
|
},
|
|
66
61
|
"devDependencies": {
|
|
67
62
|
"@metamask/auto-changelog": "^6.1.0",
|
|
68
|
-
"@metamask/controller-utils": "^
|
|
69
|
-
"@ts-bridge/cli": "^0.6.4",
|
|
63
|
+
"@metamask/controller-utils": "^13.0.0",
|
|
70
64
|
"@types/jest": "^30.0.0",
|
|
65
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
71
66
|
"deepmerge": "^4.2.2",
|
|
72
67
|
"jest": "^30.4.2",
|
|
73
68
|
"nock": "^13.3.1",
|
|
69
|
+
"rimraf": "^5.0.5",
|
|
74
70
|
"ts-jest": "^29.4.11",
|
|
75
71
|
"tsx": "^4.20.5",
|
|
76
72
|
"typedoc": "^0.25.13",
|
|
77
73
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
78
|
-
"typescript": "
|
|
74
|
+
"typescript": "npm:@typescript/typescript6@^6.0.2"
|
|
79
75
|
},
|
|
80
76
|
"engines": {
|
|
81
|
-
"node": "^
|
|
77
|
+
"node": "^22.14.0 || ^24"
|
|
82
78
|
}
|
|
83
79
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDefaultPetnamesControllerState = exports.SamplePetnamesController = exports.getDefaultSampleGasPricesControllerState = exports.SampleGasPricesController = exports.SampleGasPricesService = void 0;
|
|
4
|
-
var sample_gas_prices_service_js_1 = require("./sample-gas-prices-service/sample-gas-prices-service.cjs");
|
|
5
|
-
Object.defineProperty(exports, "SampleGasPricesService", { enumerable: true, get: function () { return sample_gas_prices_service_js_1.SampleGasPricesService; } });
|
|
6
|
-
var sample_gas_prices_controller_js_1 = require("./sample-gas-prices-controller.cjs");
|
|
7
|
-
Object.defineProperty(exports, "SampleGasPricesController", { enumerable: true, get: function () { return sample_gas_prices_controller_js_1.SampleGasPricesController; } });
|
|
8
|
-
Object.defineProperty(exports, "getDefaultSampleGasPricesControllerState", { enumerable: true, get: function () { return sample_gas_prices_controller_js_1.getDefaultSampleGasPricesControllerState; } });
|
|
9
|
-
var sample_petnames_controller_js_1 = require("./sample-petnames-controller.cjs");
|
|
10
|
-
Object.defineProperty(exports, "SamplePetnamesController", { enumerable: true, get: function () { return sample_petnames_controller_js_1.SamplePetnamesController; } });
|
|
11
|
-
Object.defineProperty(exports, "getDefaultPetnamesControllerState", { enumerable: true, get: function () { return sample_petnames_controller_js_1.getDefaultPetnamesControllerState; } });
|
|
12
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export type { SampleGasPricesServiceInvalidateQueriesAction, SampleGasPricesServiceActions, SampleGasPricesServiceCacheUpdatedEvent, SampleGasPricesServiceGranularCacheUpdatedEvent, SampleGasPricesServiceEvents, SampleGasPricesServiceMessenger, } from "./sample-gas-prices-service/sample-gas-prices-service.cjs";
|
|
2
|
-
export type { SampleGasPricesServiceFetchGasPricesAction } from "./sample-gas-prices-service/sample-gas-prices-service-method-action-types.cjs";
|
|
3
|
-
export { SampleGasPricesService } from "./sample-gas-prices-service/sample-gas-prices-service.cjs";
|
|
4
|
-
export type { SampleGasPricesControllerActions, SampleGasPricesControllerEvents, SampleGasPricesControllerGetStateAction, SampleGasPricesControllerMessenger, SampleGasPricesControllerState, SampleGasPricesControllerStateChangeEvent, } from "./sample-gas-prices-controller.cjs";
|
|
5
|
-
export { SampleGasPricesController, getDefaultSampleGasPricesControllerState, } from "./sample-gas-prices-controller.cjs";
|
|
6
|
-
export type { SampleGasPricesControllerUpdateGasPricesAction } from "./sample-gas-prices-controller-method-action-types.cjs";
|
|
7
|
-
export type { SamplePetnamesControllerActions, SamplePetnamesControllerEvents, SamplePetnamesControllerGetStateAction, SamplePetnamesControllerMessenger, SamplePetnamesControllerState, SamplePetnamesControllerStateChangeEvent, } from "./sample-petnames-controller.cjs";
|
|
8
|
-
export { SamplePetnamesController, getDefaultPetnamesControllerState, } from "./sample-petnames-controller.cjs";
|
|
9
|
-
export type { SamplePetnamesControllerAssignPetnameAction } from "./sample-petnames-controller-method-action-types.cjs";
|
|
10
|
-
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,6CAA6C,EAC7C,6BAA6B,EAC7B,uCAAuC,EACvC,+CAA+C,EAC/C,4BAA4B,EAC5B,+BAA+B,GAChC,kEAAiE;AAClE,YAAY,EAAE,0CAA0C,EAAE,sFAAqF;AAC/I,OAAO,EAAE,sBAAsB,EAAE,kEAAiE;AAClG,YAAY,EACV,gCAAgC,EAChC,+BAA+B,EAC/B,uCAAuC,EACvC,kCAAkC,EAClC,8BAA8B,EAC9B,yCAAyC,GAC1C,2CAA0C;AAC3C,OAAO,EACL,yBAAyB,EACzB,wCAAwC,GACzC,2CAA0C;AAC3C,YAAY,EAAE,8CAA8C,EAAE,+DAA8D;AAC5H,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,sCAAsC,EACtC,iCAAiC,EACjC,6BAA6B,EAC7B,wCAAwC,GACzC,yCAAwC;AACzC,OAAO,EACL,wBAAwB,EACxB,iCAAiC,GAClC,yCAAwC;AACzC,YAAY,EAAE,2CAA2C,EAAE,6DAA4D"}
|
package/dist/index.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,6CAA6C,EAC7C,6BAA6B,EAC7B,uCAAuC,EACvC,+CAA+C,EAC/C,4BAA4B,EAC5B,+BAA+B,GAChC,kEAAiE;AAClE,YAAY,EAAE,0CAA0C,EAAE,sFAAqF;AAC/I,OAAO,EAAE,sBAAsB,EAAE,kEAAiE;AAClG,YAAY,EACV,gCAAgC,EAChC,+BAA+B,EAC/B,uCAAuC,EACvC,kCAAkC,EAClC,8BAA8B,EAC9B,yCAAyC,GAC1C,2CAA0C;AAC3C,OAAO,EACL,yBAAyB,EACzB,wCAAwC,GACzC,2CAA0C;AAC3C,YAAY,EAAE,8CAA8C,EAAE,+DAA8D;AAC5H,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,sCAAsC,EACtC,iCAAiC,EACjC,6BAA6B,EAC7B,wCAAwC,GACzC,yCAAwC;AACzC,OAAO,EACL,wBAAwB,EACxB,iCAAiC,GAClC,yCAAwC;AACzC,YAAY,EAAE,2CAA2C,EAAE,6DAA4D"}
|
package/dist/index.mjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { SampleGasPricesService } from "./sample-gas-prices-service/sample-gas-prices-service.mjs";
|
|
2
|
-
export { SampleGasPricesController, getDefaultSampleGasPricesControllerState } from "./sample-gas-prices-controller.mjs";
|
|
3
|
-
export { SamplePetnamesController, getDefaultPetnamesControllerState } from "./sample-petnames-controller.mjs";
|
|
4
|
-
//# sourceMappingURL=index.mjs.map
|