@metamask/ramps-controller 1.0.0
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 +20 -0
- package/LICENSE +20 -0
- package/README.md +15 -0
- package/dist/OnRampService-method-action-types.cjs +7 -0
- package/dist/OnRampService-method-action-types.cjs.map +1 -0
- package/dist/OnRampService-method-action-types.d.cts +20 -0
- package/dist/OnRampService-method-action-types.d.cts.map +1 -0
- package/dist/OnRampService-method-action-types.d.mts +20 -0
- package/dist/OnRampService-method-action-types.d.mts.map +1 -0
- package/dist/OnRampService-method-action-types.mjs +6 -0
- package/dist/OnRampService-method-action-types.mjs.map +1 -0
- package/dist/OnRampService.cjs +204 -0
- package/dist/OnRampService.cjs.map +1 -0
- package/dist/OnRampService.d.cts +152 -0
- package/dist/OnRampService.d.cts.map +1 -0
- package/dist/OnRampService.d.mts +152 -0
- package/dist/OnRampService.d.mts.map +1 -0
- package/dist/OnRampService.mjs +200 -0
- package/dist/OnRampService.mjs.map +1 -0
- package/dist/RampsController.cjs +74 -0
- package/dist/RampsController.cjs.map +1 -0
- package/dist/RampsController.d.cts +82 -0
- package/dist/RampsController.d.cts.map +1 -0
- package/dist/RampsController.d.mts +82 -0
- package/dist/RampsController.d.mts.map +1 -0
- package/dist/RampsController.mjs +69 -0
- package/dist/RampsController.mjs.map +1 -0
- package/dist/index.cjs +10 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { BaseController } from "@metamask/base-controller";
|
|
2
|
+
// === GENERAL ===
|
|
3
|
+
/**
|
|
4
|
+
* The name of the {@link RampsController}, used to namespace the
|
|
5
|
+
* controller's actions and events and to namespace the controller's state data
|
|
6
|
+
* when composed with other controllers.
|
|
7
|
+
*/
|
|
8
|
+
export const controllerName = 'RampsController';
|
|
9
|
+
/**
|
|
10
|
+
* The metadata for each property in {@link RampsControllerState}.
|
|
11
|
+
*/
|
|
12
|
+
const rampsControllerMetadata = {
|
|
13
|
+
geolocation: {
|
|
14
|
+
persist: true,
|
|
15
|
+
includeInDebugSnapshot: true,
|
|
16
|
+
includeInStateLogs: true,
|
|
17
|
+
usedInUi: true,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Constructs the default {@link RampsController} state. This allows
|
|
22
|
+
* consumers to provide a partial state object when initializing the controller
|
|
23
|
+
* and also helps in constructing complete state objects for this controller in
|
|
24
|
+
* tests.
|
|
25
|
+
*
|
|
26
|
+
* @returns The default {@link RampsController} state.
|
|
27
|
+
*/
|
|
28
|
+
export function getDefaultRampsControllerState() {
|
|
29
|
+
return {
|
|
30
|
+
geolocation: null,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
// === CONTROLLER DEFINITION ===
|
|
34
|
+
/**
|
|
35
|
+
* Manages cryptocurrency on/off ramps functionality.
|
|
36
|
+
*/
|
|
37
|
+
export class RampsController extends BaseController {
|
|
38
|
+
/**
|
|
39
|
+
* Constructs a new {@link RampsController}.
|
|
40
|
+
*
|
|
41
|
+
* @param args - The constructor arguments.
|
|
42
|
+
* @param args.messenger - The messenger suited for this controller.
|
|
43
|
+
* @param args.state - The desired state with which to initialize this
|
|
44
|
+
* controller. Missing properties will be filled in with defaults.
|
|
45
|
+
*/
|
|
46
|
+
constructor({ messenger, state = {}, }) {
|
|
47
|
+
super({
|
|
48
|
+
messenger,
|
|
49
|
+
metadata: rampsControllerMetadata,
|
|
50
|
+
name: controllerName,
|
|
51
|
+
state: {
|
|
52
|
+
...getDefaultRampsControllerState(),
|
|
53
|
+
...state,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Updates the user's geolocation.
|
|
59
|
+
* This method calls the OnRampService to get the geolocation
|
|
60
|
+
* and stores the result in state.
|
|
61
|
+
*/
|
|
62
|
+
async updateGeolocation() {
|
|
63
|
+
const geolocation = await this.messenger.call('OnRampService:getGeolocation');
|
|
64
|
+
this.update((state) => {
|
|
65
|
+
state.geolocation = geolocation;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=RampsController.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RampsController.mjs","sourceRoot":"","sources":["../src/RampsController.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAK3D,kBAAkB;AAElB;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,iBAAiB,CAAC;AAchD;;GAEG;AACH,MAAM,uBAAuB,GAAG;IAC9B,WAAW,EAAE;QACX,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,kBAAkB,EAAE,IAAI;QACxB,QAAQ,EAAE,IAAI;KACf;CAC4C,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,UAAU,8BAA8B;IAC5C,OAAO;QACL,WAAW,EAAE,IAAI;KAClB,CAAC;AACJ,CAAC;AAkDD,gCAAgC;AAEhC;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,cAIpC;IACC;;;;;;;OAOG;IACH,YAAY,EACV,SAAS,EACT,KAAK,GAAG,EAAE,GAIX;QACC,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,uBAAuB;YACjC,IAAI,EAAE,cAAc;YACpB,KAAK,EAAE;gBACL,GAAG,8BAA8B,EAAE;gBACnC,GAAG,KAAK;aACT;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,iBAAiB;QACrB,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAC3C,8BAA8B,CAC/B,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,WAAW,GAAG,WAAW,CAAC;QAClC,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 type { Messenger } from '@metamask/messenger';\n\nimport type { OnRampServiceGetGeolocationAction } from './OnRampService-method-action-types';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link RampsController}, used to namespace the\n * controller's actions and events and to namespace the controller's state data\n * when composed with other controllers.\n */\nexport const controllerName = 'RampsController';\n\n// === STATE ===\n\n/**\n * Describes the shape of the state object for {@link RampsController}.\n */\nexport type RampsControllerState = {\n /**\n * The user's country code determined by geolocation.\n */\n geolocation: string | null;\n};\n\n/**\n * The metadata for each property in {@link RampsControllerState}.\n */\nconst rampsControllerMetadata = {\n geolocation: {\n persist: true,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n} satisfies StateMetadata<RampsControllerState>;\n\n/**\n * Constructs the default {@link RampsController} 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 RampsController} state.\n */\nexport function getDefaultRampsControllerState(): RampsControllerState {\n return {\n geolocation: null,\n };\n}\n\n// === MESSENGER ===\n\n/**\n * Retrieves the state of the {@link RampsController}.\n */\nexport type RampsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n RampsControllerState\n>;\n\n/**\n * Actions that {@link RampsControllerMessenger} exposes to other consumers.\n */\nexport type RampsControllerActions = RampsControllerGetStateAction;\n\n/**\n * Actions from other messengers that {@link RampsController} calls.\n */\ntype AllowedActions = OnRampServiceGetGeolocationAction;\n\n/**\n * Published when the state of {@link RampsController} changes.\n */\nexport type RampsControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n RampsControllerState\n>;\n\n/**\n * Events that {@link RampsControllerMessenger} exposes to other consumers.\n */\nexport type RampsControllerEvents = RampsControllerStateChangeEvent;\n\n/**\n * Events from other messengers that {@link RampsController} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link RampsController}.\n */\nexport type RampsControllerMessenger = Messenger<\n typeof controllerName,\n RampsControllerActions | AllowedActions,\n RampsControllerEvents | AllowedEvents\n>;\n\n// === CONTROLLER DEFINITION ===\n\n/**\n * Manages cryptocurrency on/off ramps functionality.\n */\nexport class RampsController extends BaseController<\n typeof controllerName,\n RampsControllerState,\n RampsControllerMessenger\n> {\n /**\n * Constructs a new {@link RampsController}.\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: RampsControllerMessenger;\n state?: Partial<RampsControllerState>;\n }) {\n super({\n messenger,\n metadata: rampsControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultRampsControllerState(),\n ...state,\n },\n });\n }\n\n /**\n * Updates the user's geolocation.\n * This method calls the OnRampService to get the geolocation\n * and stores the result in state.\n */\n async updateGeolocation(): Promise<void> {\n const geolocation = await this.messenger.call(\n 'OnRampService:getGeolocation',\n );\n\n this.update((state) => {\n state.geolocation = geolocation;\n });\n }\n}\n"]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OnRampEnvironment = exports.OnRampService = exports.getDefaultRampsControllerState = exports.RampsController = void 0;
|
|
4
|
+
var RampsController_1 = require("./RampsController.cjs");
|
|
5
|
+
Object.defineProperty(exports, "RampsController", { enumerable: true, get: function () { return RampsController_1.RampsController; } });
|
|
6
|
+
Object.defineProperty(exports, "getDefaultRampsControllerState", { enumerable: true, get: function () { return RampsController_1.getDefaultRampsControllerState; } });
|
|
7
|
+
var OnRampService_1 = require("./OnRampService.cjs");
|
|
8
|
+
Object.defineProperty(exports, "OnRampService", { enumerable: true, get: function () { return OnRampService_1.OnRampService; } });
|
|
9
|
+
Object.defineProperty(exports, "OnRampEnvironment", { enumerable: true, get: function () { return OnRampService_1.OnRampEnvironment; } });
|
|
10
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAQA,yDAG2B;AAFzB,kHAAA,eAAe,OAAA;AACf,iIAAA,8BAA8B,OAAA;AAOhC,qDAAmE;AAA1D,8GAAA,aAAa,OAAA;AAAE,kHAAA,iBAAiB,OAAA","sourcesContent":["export type {\n RampsControllerActions,\n RampsControllerEvents,\n RampsControllerGetStateAction,\n RampsControllerMessenger,\n RampsControllerState,\n RampsControllerStateChangeEvent,\n} from './RampsController';\nexport {\n RampsController,\n getDefaultRampsControllerState,\n} from './RampsController';\nexport type {\n OnRampServiceActions,\n OnRampServiceEvents,\n OnRampServiceMessenger,\n} from './OnRampService';\nexport { OnRampService, OnRampEnvironment } from './OnRampService';\nexport type { OnRampServiceGetGeolocationAction } from './OnRampService-method-action-types';\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { RampsControllerActions, RampsControllerEvents, RampsControllerGetStateAction, RampsControllerMessenger, RampsControllerState, RampsControllerStateChangeEvent, } from "./RampsController.cjs";
|
|
2
|
+
export { RampsController, getDefaultRampsControllerState, } from "./RampsController.cjs";
|
|
3
|
+
export type { OnRampServiceActions, OnRampServiceEvents, OnRampServiceMessenger, } from "./OnRampService.cjs";
|
|
4
|
+
export { OnRampService, OnRampEnvironment } from "./OnRampService.cjs";
|
|
5
|
+
export type { OnRampServiceGetGeolocationAction } from "./OnRampService-method-action-types.cjs";
|
|
6
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,sBAAsB,EACtB,qBAAqB,EACrB,6BAA6B,EAC7B,wBAAwB,EACxB,oBAAoB,EACpB,+BAA+B,GAChC,8BAA0B;AAC3B,OAAO,EACL,eAAe,EACf,8BAA8B,GAC/B,8BAA0B;AAC3B,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,GACvB,4BAAwB;AACzB,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,4BAAwB;AACnE,YAAY,EAAE,iCAAiC,EAAE,gDAA4C"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { RampsControllerActions, RampsControllerEvents, RampsControllerGetStateAction, RampsControllerMessenger, RampsControllerState, RampsControllerStateChangeEvent, } from "./RampsController.mjs";
|
|
2
|
+
export { RampsController, getDefaultRampsControllerState, } from "./RampsController.mjs";
|
|
3
|
+
export type { OnRampServiceActions, OnRampServiceEvents, OnRampServiceMessenger, } from "./OnRampService.mjs";
|
|
4
|
+
export { OnRampService, OnRampEnvironment } from "./OnRampService.mjs";
|
|
5
|
+
export type { OnRampServiceGetGeolocationAction } from "./OnRampService-method-action-types.mjs";
|
|
6
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,sBAAsB,EACtB,qBAAqB,EACrB,6BAA6B,EAC7B,wBAAwB,EACxB,oBAAoB,EACpB,+BAA+B,GAChC,8BAA0B;AAC3B,OAAO,EACL,eAAe,EACf,8BAA8B,GAC/B,8BAA0B;AAC3B,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,GACvB,4BAAwB;AACzB,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,4BAAwB;AACnE,YAAY,EAAE,iCAAiC,EAAE,gDAA4C"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,eAAe,EACf,8BAA8B,EAC/B,8BAA0B;AAM3B,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,4BAAwB","sourcesContent":["export type {\n RampsControllerActions,\n RampsControllerEvents,\n RampsControllerGetStateAction,\n RampsControllerMessenger,\n RampsControllerState,\n RampsControllerStateChangeEvent,\n} from './RampsController';\nexport {\n RampsController,\n getDefaultRampsControllerState,\n} from './RampsController';\nexport type {\n OnRampServiceActions,\n OnRampServiceEvents,\n OnRampServiceMessenger,\n} from './OnRampService';\nexport { OnRampService, OnRampEnvironment } from './OnRampService';\nexport type { OnRampServiceGetGeolocationAction } from './OnRampService-method-action-types';\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@metamask/ramps-controller",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A controller for managing cryptocurrency on/off ramps functionality",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"MetaMask",
|
|
7
|
+
"Ethereum"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://github.com/MetaMask/core/tree/main/packages/ramps-controller#readme",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/MetaMask/core/issues"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/MetaMask/core.git"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/index.d.mts",
|
|
23
|
+
"default": "./dist/index.mjs"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/index.d.cts",
|
|
27
|
+
"default": "./dist/index.cjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"main": "./dist/index.cjs",
|
|
33
|
+
"types": "./dist/index.d.cts",
|
|
34
|
+
"files": [
|
|
35
|
+
"dist/"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
|
|
39
|
+
"build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
|
|
40
|
+
"build:docs": "typedoc",
|
|
41
|
+
"changelog:update": "../../scripts/update-changelog.sh @metamask/ramps-controller",
|
|
42
|
+
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/ramps-controller",
|
|
43
|
+
"publish:preview": "yarn npm publish --tag preview",
|
|
44
|
+
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
45
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
46
|
+
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
47
|
+
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
|
|
48
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@metamask/base-controller": "^9.0.0",
|
|
52
|
+
"@metamask/controller-utils": "^11.16.0",
|
|
53
|
+
"@metamask/messenger": "^0.3.0"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@metamask/auto-changelog": "^3.4.4",
|
|
57
|
+
"@ts-bridge/cli": "^0.6.4",
|
|
58
|
+
"@types/jest": "^27.4.1",
|
|
59
|
+
"@types/sinon": "^9.0.10",
|
|
60
|
+
"deepmerge": "^4.2.2",
|
|
61
|
+
"isomorphic-fetch": "^3.0.0",
|
|
62
|
+
"jest": "^27.5.1",
|
|
63
|
+
"nock": "^13.3.1",
|
|
64
|
+
"sinon": "^9.2.4",
|
|
65
|
+
"ts-jest": "^27.1.4",
|
|
66
|
+
"typedoc": "^0.24.8",
|
|
67
|
+
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
68
|
+
"typescript": "~5.3.3"
|
|
69
|
+
},
|
|
70
|
+
"engines": {
|
|
71
|
+
"node": "^18.18 || >=20"
|
|
72
|
+
},
|
|
73
|
+
"publishConfig": {
|
|
74
|
+
"access": "public",
|
|
75
|
+
"registry": "https://registry.npmjs.org/"
|
|
76
|
+
}
|
|
77
|
+
}
|