@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
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SampleGasPricesService = exports.serviceName = void 0;
|
|
4
|
-
const base_data_service_1 = require("@metamask/base-data-service");
|
|
5
|
-
const controller_utils_1 = require("@metamask/controller-utils");
|
|
6
|
-
const superstruct_1 = require("@metamask/superstruct");
|
|
7
|
-
// === GENERAL ===
|
|
8
|
-
/**
|
|
9
|
-
* The name of the {@link SampleGasPricesService}, used to namespace the
|
|
10
|
-
* service's actions and events.
|
|
11
|
-
*/
|
|
12
|
-
exports.serviceName = 'SampleGasPricesService';
|
|
13
|
-
// === MESSENGER ===
|
|
14
|
-
/**
|
|
15
|
-
* All of the methods within {@link SampleGasPricesService} that are exposed via
|
|
16
|
-
* the messenger.
|
|
17
|
-
*/
|
|
18
|
-
const MESSENGER_EXPOSED_METHODS = ['fetchGasPrices'];
|
|
19
|
-
// === SERVICE DEFINITION ===
|
|
20
|
-
/**
|
|
21
|
-
* Struct to validate what the API endpoint returns.
|
|
22
|
-
*/
|
|
23
|
-
const GasPricesResponseStruct = (0, superstruct_1.type)({
|
|
24
|
-
data: (0, superstruct_1.type)({
|
|
25
|
-
low: (0, superstruct_1.number)(),
|
|
26
|
-
average: (0, superstruct_1.number)(),
|
|
27
|
-
high: (0, superstruct_1.number)(),
|
|
28
|
-
}),
|
|
29
|
-
});
|
|
30
|
-
/**
|
|
31
|
-
* The base URL of the API that the service represents.
|
|
32
|
-
*/
|
|
33
|
-
const BASE_URL = 'https://api.example.com';
|
|
34
|
-
/**
|
|
35
|
-
* This service object is responsible for fetching gas prices via an API.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
*
|
|
39
|
-
* ``` ts
|
|
40
|
-
* import type { MessengerActions, MessengerEvents } from '@metamask/messenger';
|
|
41
|
-
* import { Messenger } from '@metamask/messenger';
|
|
42
|
-
* import type {
|
|
43
|
-
* SampleGasPricesServiceMessenger,
|
|
44
|
-
* } from '@metamask/sample-controllers';
|
|
45
|
-
*
|
|
46
|
-
* const rootMessenger = new Messenger<
|
|
47
|
-
* 'Root',
|
|
48
|
-
* SampleGasPricesServiceActions
|
|
49
|
-
* SampleGasPricesServiceEvents
|
|
50
|
-
* >({ namespace: 'Root' });
|
|
51
|
-
* const gasPricesServiceMessenger = new Messenger<
|
|
52
|
-
* 'SampleGasPricesService',
|
|
53
|
-
* MessengerActions<SampleGasPricesServiceMessenger>,
|
|
54
|
-
* MessengerEvents<SampleGasPricesServiceMessenger>,
|
|
55
|
-
* typeof rootMessenger,
|
|
56
|
-
* >({
|
|
57
|
-
* namespace: 'SampleGasPricesService',
|
|
58
|
-
* parent: rootMessenger,
|
|
59
|
-
* });
|
|
60
|
-
* // Instantiate the service to register its actions on the messenger
|
|
61
|
-
* new SampleGasPricesService({
|
|
62
|
-
* messenger: gasPricesServiceMessenger,
|
|
63
|
-
* });
|
|
64
|
-
*
|
|
65
|
-
* // Later...
|
|
66
|
-
* // Fetch gas prices for Mainnet
|
|
67
|
-
* const gasPrices = await rootMessenger.call(
|
|
68
|
-
* 'SampleGasPricesService:fetchGasPrices',
|
|
69
|
-
* '0x1',
|
|
70
|
-
* );
|
|
71
|
-
* // ... Do something with the gas prices ...
|
|
72
|
-
* ```
|
|
73
|
-
*/
|
|
74
|
-
class SampleGasPricesService extends base_data_service_1.BaseDataService {
|
|
75
|
-
/**
|
|
76
|
-
* Constructs a new SampleGasPricesService object.
|
|
77
|
-
*
|
|
78
|
-
* @param args - The constructor arguments.
|
|
79
|
-
* @param args.messenger - The messenger suited for this service.
|
|
80
|
-
* @param args.queryClientConfig - Configuration for the underlying TanStack
|
|
81
|
-
* Query client.
|
|
82
|
-
* @param args.policyOptions - Options to pass to `createServicePolicy`, which
|
|
83
|
-
* is used to wrap each request. See {@link CreateServicePolicyOptions}.
|
|
84
|
-
*/
|
|
85
|
-
constructor({ messenger, queryClientConfig = {}, policyOptions = {}, }) {
|
|
86
|
-
super({
|
|
87
|
-
name: exports.serviceName,
|
|
88
|
-
messenger,
|
|
89
|
-
queryClientConfig,
|
|
90
|
-
policyOptions,
|
|
91
|
-
});
|
|
92
|
-
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Makes a request to the API in order to retrieve gas prices for a particular
|
|
96
|
-
* chain.
|
|
97
|
-
*
|
|
98
|
-
* @param chainId - The chain ID for which you want to fetch gas prices.
|
|
99
|
-
* @returns The gas prices for the given chain.
|
|
100
|
-
*/
|
|
101
|
-
async fetchGasPrices(chainId) {
|
|
102
|
-
const url = new URL('/gas-prices', BASE_URL);
|
|
103
|
-
url.searchParams.append('chainId', `eip155:${(0, controller_utils_1.fromHex)(chainId).toString()}`);
|
|
104
|
-
const jsonResponse = await this.fetchQuery({
|
|
105
|
-
queryKey: [`${this.name}:fetchGasPrices`, chainId],
|
|
106
|
-
queryFn: async () => {
|
|
107
|
-
const response = await fetch(url);
|
|
108
|
-
if (!response.ok) {
|
|
109
|
-
throw new controller_utils_1.HttpError(response.status, `Gas prices API failed with status '${response.status}'`);
|
|
110
|
-
}
|
|
111
|
-
return response.json();
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
if (!(0, superstruct_1.is)(jsonResponse, GasPricesResponseStruct)) {
|
|
115
|
-
throw new Error('Malformed response received from gas prices API');
|
|
116
|
-
}
|
|
117
|
-
return jsonResponse.data;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
exports.SampleGasPricesService = SampleGasPricesService;
|
|
121
|
-
//# sourceMappingURL=sample-gas-prices-service.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sample-gas-prices-service.cjs","sourceRoot":"","sources":["../../src/sample-gas-prices-service/sample-gas-prices-service.ts"],"names":[],"mappings":";;;AAAA,mEAA8D;AAO9D,iEAAgE;AAGhE,uDAAyD;AAMzD,kBAAkB;AAElB;;;GAGG;AACU,QAAA,WAAW,GAAG,wBAAwB,CAAC;AAEpD,oBAAoB;AAEpB;;;GAGG;AACH,MAAM,yBAAyB,GAAG,CAAC,gBAAgB,CAAU,CAAC;AAwD9D,6BAA6B;AAE7B;;GAEG;AACH,MAAM,uBAAuB,GAAG,IAAA,kBAAI,EAAC;IACnC,IAAI,EAAE,IAAA,kBAAI,EAAC;QACT,GAAG,EAAE,IAAA,oBAAM,GAAE;QACb,OAAO,EAAE,IAAA,oBAAM,GAAE;QACjB,IAAI,EAAE,IAAA,oBAAM,GAAE;KACf,CAAC;CACH,CAAC,CAAC;AAOH;;GAEG;AACH,MAAM,QAAQ,GAAG,yBAAyB,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAa,sBAAuB,SAAQ,mCAG3C;IACC;;;;;;;;;OASG;IACH,YAAY,EACV,SAAS,EACT,iBAAiB,GAAG,EAAE,EACtB,aAAa,GAAG,EAAE,GAKnB;QACC,KAAK,CAAC;YACJ,IAAI,EAAE,mBAAW;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,IAAA,0BAAO,EAAC,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,4BAAS,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,IAAA,gBAAE,EAAC,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;AArED,wDAqEC","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"]}
|
|
@@ -1,139 +0,0 @@
|
|
|
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.cjs";
|
|
9
|
-
/**
|
|
10
|
-
* The name of the {@link SampleGasPricesService}, used to namespace the
|
|
11
|
-
* service's actions and events.
|
|
12
|
-
*/
|
|
13
|
-
export declare const serviceName = "SampleGasPricesService";
|
|
14
|
-
/**
|
|
15
|
-
* Invalidates cached queries for {@link SampleGasPricesService}.
|
|
16
|
-
*/
|
|
17
|
-
export type SampleGasPricesServiceInvalidateQueriesAction = DataServiceInvalidateQueriesAction<typeof serviceName>;
|
|
18
|
-
/**
|
|
19
|
-
* Actions that {@link SampleGasPricesService} exposes to other consumers.
|
|
20
|
-
*/
|
|
21
|
-
export type SampleGasPricesServiceActions = SampleGasPricesServiceMethodActions | SampleGasPricesServiceInvalidateQueriesAction;
|
|
22
|
-
/**
|
|
23
|
-
* Actions from other messengers that {@link SampleGasPricesService} calls.
|
|
24
|
-
*/
|
|
25
|
-
type AllowedActions = never;
|
|
26
|
-
/**
|
|
27
|
-
* Published when {@link SampleGasPricesService}'s cache is updated.
|
|
28
|
-
*/
|
|
29
|
-
export type SampleGasPricesServiceCacheUpdatedEvent = DataServiceCacheUpdatedEvent<typeof serviceName>;
|
|
30
|
-
/**
|
|
31
|
-
* Published when a key within {@link SampleGasPricesService}'s cache is
|
|
32
|
-
* updated.
|
|
33
|
-
*/
|
|
34
|
-
export type SampleGasPricesServiceGranularCacheUpdatedEvent = DataServiceGranularCacheUpdatedEvent<typeof serviceName>;
|
|
35
|
-
/**
|
|
36
|
-
* Events that {@link SampleGasPricesService} exposes to other consumers.
|
|
37
|
-
*/
|
|
38
|
-
export type SampleGasPricesServiceEvents = SampleGasPricesServiceCacheUpdatedEvent | SampleGasPricesServiceGranularCacheUpdatedEvent;
|
|
39
|
-
/**
|
|
40
|
-
* Events from other messengers that {@link SampleGasPricesService} subscribes
|
|
41
|
-
* to.
|
|
42
|
-
*/
|
|
43
|
-
type AllowedEvents = never;
|
|
44
|
-
/**
|
|
45
|
-
* The messenger which is restricted to actions and events accessed by
|
|
46
|
-
* {@link SampleGasPricesService}.
|
|
47
|
-
*/
|
|
48
|
-
export type SampleGasPricesServiceMessenger = Messenger<typeof serviceName, SampleGasPricesServiceActions | AllowedActions, SampleGasPricesServiceEvents | AllowedEvents>;
|
|
49
|
-
/**
|
|
50
|
-
* Struct to validate what the API endpoint returns.
|
|
51
|
-
*/
|
|
52
|
-
declare const GasPricesResponseStruct: import("@metamask/superstruct").Struct<{
|
|
53
|
-
data: {
|
|
54
|
-
low: number;
|
|
55
|
-
average: number;
|
|
56
|
-
high: number;
|
|
57
|
-
};
|
|
58
|
-
}, {
|
|
59
|
-
data: import("@metamask/superstruct").Struct<{
|
|
60
|
-
low: number;
|
|
61
|
-
average: number;
|
|
62
|
-
high: number;
|
|
63
|
-
}, {
|
|
64
|
-
low: import("@metamask/superstruct").Struct<number, null>;
|
|
65
|
-
average: import("@metamask/superstruct").Struct<number, null>;
|
|
66
|
-
high: import("@metamask/superstruct").Struct<number, null>;
|
|
67
|
-
}>;
|
|
68
|
-
}>;
|
|
69
|
-
/**
|
|
70
|
-
* What the API endpoint returns.
|
|
71
|
-
*/
|
|
72
|
-
type GasPricesResponse = Infer<typeof GasPricesResponseStruct>;
|
|
73
|
-
/**
|
|
74
|
-
* This service object is responsible for fetching gas prices via an API.
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
*
|
|
78
|
-
* ``` ts
|
|
79
|
-
* import type { MessengerActions, MessengerEvents } from '@metamask/messenger';
|
|
80
|
-
* import { Messenger } from '@metamask/messenger';
|
|
81
|
-
* import type {
|
|
82
|
-
* SampleGasPricesServiceMessenger,
|
|
83
|
-
* } from '@metamask/sample-controllers';
|
|
84
|
-
*
|
|
85
|
-
* const rootMessenger = new Messenger<
|
|
86
|
-
* 'Root',
|
|
87
|
-
* SampleGasPricesServiceActions
|
|
88
|
-
* SampleGasPricesServiceEvents
|
|
89
|
-
* >({ namespace: 'Root' });
|
|
90
|
-
* const gasPricesServiceMessenger = new Messenger<
|
|
91
|
-
* 'SampleGasPricesService',
|
|
92
|
-
* MessengerActions<SampleGasPricesServiceMessenger>,
|
|
93
|
-
* MessengerEvents<SampleGasPricesServiceMessenger>,
|
|
94
|
-
* typeof rootMessenger,
|
|
95
|
-
* >({
|
|
96
|
-
* namespace: 'SampleGasPricesService',
|
|
97
|
-
* parent: rootMessenger,
|
|
98
|
-
* });
|
|
99
|
-
* // Instantiate the service to register its actions on the messenger
|
|
100
|
-
* new SampleGasPricesService({
|
|
101
|
-
* messenger: gasPricesServiceMessenger,
|
|
102
|
-
* });
|
|
103
|
-
*
|
|
104
|
-
* // Later...
|
|
105
|
-
* // Fetch gas prices for Mainnet
|
|
106
|
-
* const gasPrices = await rootMessenger.call(
|
|
107
|
-
* 'SampleGasPricesService:fetchGasPrices',
|
|
108
|
-
* '0x1',
|
|
109
|
-
* );
|
|
110
|
-
* // ... Do something with the gas prices ...
|
|
111
|
-
* ```
|
|
112
|
-
*/
|
|
113
|
-
export declare class SampleGasPricesService extends BaseDataService<typeof serviceName, SampleGasPricesServiceMessenger> {
|
|
114
|
-
/**
|
|
115
|
-
* Constructs a new SampleGasPricesService object.
|
|
116
|
-
*
|
|
117
|
-
* @param args - The constructor arguments.
|
|
118
|
-
* @param args.messenger - The messenger suited for this service.
|
|
119
|
-
* @param args.queryClientConfig - Configuration for the underlying TanStack
|
|
120
|
-
* Query client.
|
|
121
|
-
* @param args.policyOptions - Options to pass to `createServicePolicy`, which
|
|
122
|
-
* is used to wrap each request. See {@link CreateServicePolicyOptions}.
|
|
123
|
-
*/
|
|
124
|
-
constructor({ messenger, queryClientConfig, policyOptions, }: {
|
|
125
|
-
messenger: SampleGasPricesServiceMessenger;
|
|
126
|
-
queryClientConfig?: QueryClientConfig;
|
|
127
|
-
policyOptions?: CreateServicePolicyOptions;
|
|
128
|
-
});
|
|
129
|
-
/**
|
|
130
|
-
* Makes a request to the API in order to retrieve gas prices for a particular
|
|
131
|
-
* chain.
|
|
132
|
-
*
|
|
133
|
-
* @param chainId - The chain ID for which you want to fetch gas prices.
|
|
134
|
-
* @returns The gas prices for the given chain.
|
|
135
|
-
*/
|
|
136
|
-
fetchGasPrices(chainId: Hex): Promise<GasPricesResponse['data']>;
|
|
137
|
-
}
|
|
138
|
-
export {};
|
|
139
|
-
//# sourceMappingURL=sample-gas-prices-service.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,EAAE,eAAe,EAAE,oCAAoC;AAC9D,OAAO,KAAK,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,oCAAoC;AACrC,OAAO,KAAK,EAAE,0BAA0B,EAAE,mCAAmC;AAE7E,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAEnD,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAC3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,6BAA6B;AAE9D,OAAO,KAAK,EAAE,mCAAmC,EAAE,4DAA2D;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;gBACS,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;IAcD;;;;;;OAMG;IACG,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;CA0BvE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sample-gas-prices-service.d.mts","sourceRoot":"","sources":["../../src/sample-gas-prices-service/sample-gas-prices-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,oCAAoC;AAC9D,OAAO,KAAK,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,oCAAoC;AACrC,OAAO,KAAK,EAAE,0BAA0B,EAAE,mCAAmC;AAE7E,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAEnD,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAC3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,6BAA6B;AAE9D,OAAO,KAAK,EAAE,mCAAmC,EAAE,4DAA2D;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;gBACS,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;IAcD;;;;;;OAMG;IACG,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;CA0BvE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sample-gas-prices-service.mjs","sourceRoot":"","sources":["../../src/sample-gas-prices-service/sample-gas-prices-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,oCAAoC;AAO9D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,mCAAmC;AAGhE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,8BAA8B;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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sample-petnames-controller-method-action-types.cjs","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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sample-petnames-controller-method-action-types.d.cts","sourceRoot":"","sources":["../src/sample-petnames-controller-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,yCAAwC;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"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is auto generated.
|
|
3
|
-
* Do not edit manually.
|
|
4
|
-
*/
|
|
5
|
-
import type { SamplePetnamesController } from "./sample-petnames-controller.mjs";
|
|
6
|
-
/**
|
|
7
|
-
* Registers the given name with the given address (relative to the given
|
|
8
|
-
* chain).
|
|
9
|
-
*
|
|
10
|
-
* @param chainId - The chain ID that the address belongs to.
|
|
11
|
-
* @param address - The account address to name.
|
|
12
|
-
* @param name - The name to assign to the address.
|
|
13
|
-
*/
|
|
14
|
-
export type SamplePetnamesControllerAssignPetnameAction = {
|
|
15
|
-
type: `SamplePetnamesController:assignPetname`;
|
|
16
|
-
handler: SamplePetnamesController['assignPetname'];
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Union of all SamplePetnamesController action types.
|
|
20
|
-
*/
|
|
21
|
-
export type SamplePetnamesControllerMethodActions = SamplePetnamesControllerAssignPetnameAction;
|
|
22
|
-
//# sourceMappingURL=sample-petnames-controller-method-action-types.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sample-petnames-controller-method-action-types.d.mts","sourceRoot":"","sources":["../src/sample-petnames-controller-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,yCAAwC;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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sample-petnames-controller-method-action-types.mjs","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,130 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SamplePetnamesController = exports.getDefaultPetnamesControllerState = void 0;
|
|
4
|
-
const base_controller_1 = require("@metamask/base-controller");
|
|
5
|
-
const controller_utils_1 = require("@metamask/controller-utils");
|
|
6
|
-
// === GENERAL ===
|
|
7
|
-
/**
|
|
8
|
-
* The name of the {@link SamplePetnamesController}, used to namespace the
|
|
9
|
-
* controller's actions and events and to namespace the controller's state data
|
|
10
|
-
* when composed with other controllers.
|
|
11
|
-
*/
|
|
12
|
-
const CONTROLLER_NAME = 'SamplePetnamesController';
|
|
13
|
-
/**
|
|
14
|
-
* The metadata for each property in {@link SamplePetnamesControllerState}.
|
|
15
|
-
*/
|
|
16
|
-
const samplePetnamesControllerMetadata = {
|
|
17
|
-
namesByChainIdAndAddress: {
|
|
18
|
-
includeInDebugSnapshot: false,
|
|
19
|
-
includeInStateLogs: true,
|
|
20
|
-
persist: true,
|
|
21
|
-
usedInUi: true,
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Constructs the default {@link SamplePetnamesController} state. This allows
|
|
26
|
-
* consumers to provide a partial state object when initializing the controller
|
|
27
|
-
* and also helps in constructing complete state objects for this controller in
|
|
28
|
-
* tests.
|
|
29
|
-
*
|
|
30
|
-
* @returns The default {@link SamplePetnamesController} state.
|
|
31
|
-
*/
|
|
32
|
-
function getDefaultPetnamesControllerState() {
|
|
33
|
-
return {
|
|
34
|
-
namesByChainIdAndAddress: {},
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
exports.getDefaultPetnamesControllerState = getDefaultPetnamesControllerState;
|
|
38
|
-
// === MESSENGER ===
|
|
39
|
-
const MESSENGER_EXPOSED_METHODS = ['assignPetname'];
|
|
40
|
-
// === CONTROLLER DEFINITION ===
|
|
41
|
-
/**
|
|
42
|
-
* `SamplePetnamesController` records user-provided nicknames for various
|
|
43
|
-
* addresses on various chains.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
*
|
|
47
|
-
* ``` ts
|
|
48
|
-
* import { Messenger } from '@metamask/messenger';
|
|
49
|
-
* import type {
|
|
50
|
-
* SamplePetnamesControllerActions,
|
|
51
|
-
* SamplePetnamesControllerEvents,
|
|
52
|
-
* } from '@metamask/sample-controllers';
|
|
53
|
-
*
|
|
54
|
-
* const rootMessenger = new Messenger<
|
|
55
|
-
* 'Root',
|
|
56
|
-
* SamplePetnamesControllerActions,
|
|
57
|
-
* SamplePetnamesControllerEvents
|
|
58
|
-
* >({ namespace: 'Root' });
|
|
59
|
-
* const samplePetnamesMessenger = new Messenger<
|
|
60
|
-
* 'SamplePetnamesController',
|
|
61
|
-
* SamplePetnamesControllerActions,
|
|
62
|
-
* SamplePetnamesControllerEvents,
|
|
63
|
-
* typeof rootMessenger,
|
|
64
|
-
* >({
|
|
65
|
-
* namespace: 'SamplePetnamesController',
|
|
66
|
-
* parent: rootMessenger,
|
|
67
|
-
* });
|
|
68
|
-
* // Instantiate the controller to register its actions on the messenger
|
|
69
|
-
* new SamplePetnamesController({
|
|
70
|
-
* messenger: samplePetnamesMessenger,
|
|
71
|
-
* });
|
|
72
|
-
*
|
|
73
|
-
* rootMessenger.call(
|
|
74
|
-
* 'SamplePetnamesController:assignPetname',
|
|
75
|
-
* [
|
|
76
|
-
* '0x1',
|
|
77
|
-
* '0xF57F855e17483B1f09bFec62783C9d3b6c8b3A99',
|
|
78
|
-
* 'Primary Account',
|
|
79
|
-
* ],
|
|
80
|
-
* );
|
|
81
|
-
* const samplePetnamesControllerState = await rootMessenger.call(
|
|
82
|
-
* 'SamplePetnamesController:getState',
|
|
83
|
-
* );
|
|
84
|
-
* samplePetnamesControllerState.namesByChainIdAndAddress
|
|
85
|
-
* // => { '0x1': { '0xF57F855e17483B1f09bFec62783C9d3b6c8b3A99': 'Primary Account' } }
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
|
-
class SamplePetnamesController extends base_controller_1.BaseController {
|
|
89
|
-
/**
|
|
90
|
-
* Constructs a new {@link SamplePetnamesController}.
|
|
91
|
-
*
|
|
92
|
-
* @param args - The arguments to this controller.
|
|
93
|
-
* @param args.messenger - The messenger suited for this controller.
|
|
94
|
-
* @param args.state - The desired state with which to initialize this
|
|
95
|
-
* controller. Missing properties will be filled in with defaults.
|
|
96
|
-
*/
|
|
97
|
-
constructor({ messenger, state, }) {
|
|
98
|
-
super({
|
|
99
|
-
messenger,
|
|
100
|
-
metadata: samplePetnamesControllerMetadata,
|
|
101
|
-
name: CONTROLLER_NAME,
|
|
102
|
-
state: {
|
|
103
|
-
...getDefaultPetnamesControllerState(),
|
|
104
|
-
...state,
|
|
105
|
-
},
|
|
106
|
-
});
|
|
107
|
-
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Registers the given name with the given address (relative to the given
|
|
111
|
-
* chain).
|
|
112
|
-
*
|
|
113
|
-
* @param chainId - The chain ID that the address belongs to.
|
|
114
|
-
* @param address - The account address to name.
|
|
115
|
-
* @param name - The name to assign to the address.
|
|
116
|
-
*/
|
|
117
|
-
assignPetname(chainId, address, name) {
|
|
118
|
-
if (!(0, controller_utils_1.isSafeDynamicKey)(chainId)) {
|
|
119
|
-
throw new Error('Invalid chain ID');
|
|
120
|
-
}
|
|
121
|
-
const normalizedAddress = address.toLowerCase();
|
|
122
|
-
this.update((state) => {
|
|
123
|
-
var _a;
|
|
124
|
-
(_a = state.namesByChainIdAndAddress)[chainId] ?? (_a[chainId] = {});
|
|
125
|
-
state.namesByChainIdAndAddress[chainId][normalizedAddress] = name;
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
exports.SamplePetnamesController = SamplePetnamesController;
|
|
130
|
-
//# sourceMappingURL=sample-petnames-controller.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sample-petnames-controller.cjs","sourceRoot":"","sources":["../src/sample-petnames-controller.ts"],"names":[],"mappings":";;;AAKA,+DAA2D;AAC3D,iEAA8D;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,SAAgB,iCAAiC;IAC/C,OAAO;QACL,wBAAwB,EAAE,EAAE;KAC7B,CAAC;AACJ,CAAC;AAJD,8EAIC;AAED,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG,CAAC,eAAe,CAAU,CAAC;AAqD7D,gCAAgC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAa,wBAAyB,SAAQ,gCAI7C;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,IAAA,mCAAgB,EAAC,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,MAAA,KAAK,CAAC,wBAAwB,EAAC,OAAO,SAAP,OAAO,IAAM,EAAE,EAAC;YAC/C,KAAK,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAAC;QACpE,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAxDD,4DAwDC","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"]}
|
|
@@ -1,136 +0,0 @@
|
|
|
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.cjs";
|
|
6
|
-
/**
|
|
7
|
-
* The name of the {@link SamplePetnamesController}, used to namespace the
|
|
8
|
-
* controller's actions and events and to namespace the controller's state data
|
|
9
|
-
* when composed with other controllers.
|
|
10
|
-
*/
|
|
11
|
-
declare const CONTROLLER_NAME = "SamplePetnamesController";
|
|
12
|
-
/**
|
|
13
|
-
* Describes the shape of the state object for {@link SamplePetnamesController}.
|
|
14
|
-
*/
|
|
15
|
-
export type SamplePetnamesControllerState = {
|
|
16
|
-
/**
|
|
17
|
-
* The registry of pet names, categorized by chain ID first and address
|
|
18
|
-
* second.
|
|
19
|
-
*/
|
|
20
|
-
namesByChainIdAndAddress: {
|
|
21
|
-
[chainId: Hex]: {
|
|
22
|
-
[address: Hex]: string;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Constructs the default {@link SamplePetnamesController} state. This allows
|
|
28
|
-
* consumers to provide a partial state object when initializing the controller
|
|
29
|
-
* and also helps in constructing complete state objects for this controller in
|
|
30
|
-
* tests.
|
|
31
|
-
*
|
|
32
|
-
* @returns The default {@link SamplePetnamesController} state.
|
|
33
|
-
*/
|
|
34
|
-
export declare function getDefaultPetnamesControllerState(): SamplePetnamesControllerState;
|
|
35
|
-
/**
|
|
36
|
-
* Retrieves the state of the {@link SamplePetnamesController}.
|
|
37
|
-
*/
|
|
38
|
-
export type SamplePetnamesControllerGetStateAction = ControllerGetStateAction<typeof CONTROLLER_NAME, SamplePetnamesControllerState>;
|
|
39
|
-
/**
|
|
40
|
-
* Actions that {@link SampleGasPricesMessenger} exposes to other consumers.
|
|
41
|
-
*/
|
|
42
|
-
export type SamplePetnamesControllerActions = SamplePetnamesControllerGetStateAction | SamplePetnamesControllerMethodActions;
|
|
43
|
-
/**
|
|
44
|
-
* Actions from other messengers that {@link SampleGasPricesMessenger} calls.
|
|
45
|
-
*/
|
|
46
|
-
type AllowedActions = never;
|
|
47
|
-
/**
|
|
48
|
-
* Published when the state of {@link SamplePetnamesController} changes.
|
|
49
|
-
*/
|
|
50
|
-
export type SamplePetnamesControllerStateChangeEvent = ControllerStateChangeEvent<typeof CONTROLLER_NAME, SamplePetnamesControllerState>;
|
|
51
|
-
/**
|
|
52
|
-
* Events that {@link SampleGasPricesMessenger} exposes to other consumers.
|
|
53
|
-
*/
|
|
54
|
-
export type SamplePetnamesControllerEvents = SamplePetnamesControllerStateChangeEvent;
|
|
55
|
-
/**
|
|
56
|
-
* Events from other messengers that {@link SampleGasPricesMessenger} subscribes
|
|
57
|
-
* to.
|
|
58
|
-
*/
|
|
59
|
-
type AllowedEvents = never;
|
|
60
|
-
/**
|
|
61
|
-
* The messenger restricted to actions and events accessed by
|
|
62
|
-
* {@link SamplePetnamesController}.
|
|
63
|
-
*/
|
|
64
|
-
export type SamplePetnamesControllerMessenger = Messenger<typeof CONTROLLER_NAME, SamplePetnamesControllerActions | AllowedActions, SamplePetnamesControllerEvents | AllowedEvents>;
|
|
65
|
-
/**
|
|
66
|
-
* `SamplePetnamesController` records user-provided nicknames for various
|
|
67
|
-
* addresses on various chains.
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
*
|
|
71
|
-
* ``` ts
|
|
72
|
-
* import { Messenger } from '@metamask/messenger';
|
|
73
|
-
* import type {
|
|
74
|
-
* SamplePetnamesControllerActions,
|
|
75
|
-
* SamplePetnamesControllerEvents,
|
|
76
|
-
* } from '@metamask/sample-controllers';
|
|
77
|
-
*
|
|
78
|
-
* const rootMessenger = new Messenger<
|
|
79
|
-
* 'Root',
|
|
80
|
-
* SamplePetnamesControllerActions,
|
|
81
|
-
* SamplePetnamesControllerEvents
|
|
82
|
-
* >({ namespace: 'Root' });
|
|
83
|
-
* const samplePetnamesMessenger = new Messenger<
|
|
84
|
-
* 'SamplePetnamesController',
|
|
85
|
-
* SamplePetnamesControllerActions,
|
|
86
|
-
* SamplePetnamesControllerEvents,
|
|
87
|
-
* typeof rootMessenger,
|
|
88
|
-
* >({
|
|
89
|
-
* namespace: 'SamplePetnamesController',
|
|
90
|
-
* parent: rootMessenger,
|
|
91
|
-
* });
|
|
92
|
-
* // Instantiate the controller to register its actions on the messenger
|
|
93
|
-
* new SamplePetnamesController({
|
|
94
|
-
* messenger: samplePetnamesMessenger,
|
|
95
|
-
* });
|
|
96
|
-
*
|
|
97
|
-
* rootMessenger.call(
|
|
98
|
-
* 'SamplePetnamesController:assignPetname',
|
|
99
|
-
* [
|
|
100
|
-
* '0x1',
|
|
101
|
-
* '0xF57F855e17483B1f09bFec62783C9d3b6c8b3A99',
|
|
102
|
-
* 'Primary Account',
|
|
103
|
-
* ],
|
|
104
|
-
* );
|
|
105
|
-
* const samplePetnamesControllerState = await rootMessenger.call(
|
|
106
|
-
* 'SamplePetnamesController:getState',
|
|
107
|
-
* );
|
|
108
|
-
* samplePetnamesControllerState.namesByChainIdAndAddress
|
|
109
|
-
* // => { '0x1': { '0xF57F855e17483B1f09bFec62783C9d3b6c8b3A99': 'Primary Account' } }
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
export declare class SamplePetnamesController extends BaseController<typeof CONTROLLER_NAME, SamplePetnamesControllerState, SamplePetnamesControllerMessenger> {
|
|
113
|
-
/**
|
|
114
|
-
* Constructs a new {@link SamplePetnamesController}.
|
|
115
|
-
*
|
|
116
|
-
* @param args - The arguments to this controller.
|
|
117
|
-
* @param args.messenger - The messenger suited for this controller.
|
|
118
|
-
* @param args.state - The desired state with which to initialize this
|
|
119
|
-
* controller. Missing properties will be filled in with defaults.
|
|
120
|
-
*/
|
|
121
|
-
constructor({ messenger, state, }: {
|
|
122
|
-
messenger: SamplePetnamesControllerMessenger;
|
|
123
|
-
state?: Partial<SamplePetnamesControllerState>;
|
|
124
|
-
});
|
|
125
|
-
/**
|
|
126
|
-
* Registers the given name with the given address (relative to the given
|
|
127
|
-
* chain).
|
|
128
|
-
*
|
|
129
|
-
* @param chainId - The chain ID that the address belongs to.
|
|
130
|
-
* @param address - The account address to name.
|
|
131
|
-
* @param name - The name to assign to the address.
|
|
132
|
-
*/
|
|
133
|
-
assignPetname(chainId: Hex, address: Hex, name: string): void;
|
|
134
|
-
}
|
|
135
|
-
export {};
|
|
136
|
-
//# sourceMappingURL=sample-petnames-controller.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sample-petnames-controller.d.cts","sourceRoot":"","sources":["../src/sample-petnames-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EAAE,qCAAqC,EAAE,6DAA4D;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;gBACS,EACV,SAAS,EACT,KAAK,GACN,EAAE;QACD,SAAS,EAAE,iCAAiC,CAAC;QAC7C,KAAK,CAAC,EAAE,OAAO,CAAC,6BAA6B,CAAC,CAAC;KAChD;IAiBD;;;;;;;OAOG;IACH,aAAa,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;CAY9D"}
|