@metamask/ramps-controller 2.1.0 → 4.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +41 -1
  2. package/dist/RampsController.cjs +294 -39
  3. package/dist/RampsController.cjs.map +1 -1
  4. package/dist/RampsController.d.cts +96 -17
  5. package/dist/RampsController.d.cts.map +1 -1
  6. package/dist/RampsController.d.mts +96 -17
  7. package/dist/RampsController.d.mts.map +1 -1
  8. package/dist/RampsController.mjs +294 -39
  9. package/dist/RampsController.mjs.map +1 -1
  10. package/dist/RampsService-method-action-types.cjs.map +1 -1
  11. package/dist/RampsService-method-action-types.d.cts +24 -7
  12. package/dist/RampsService-method-action-types.d.cts.map +1 -1
  13. package/dist/RampsService-method-action-types.d.mts +24 -7
  14. package/dist/RampsService-method-action-types.d.mts.map +1 -1
  15. package/dist/RampsService-method-action-types.mjs.map +1 -1
  16. package/dist/RampsService.cjs +83 -8
  17. package/dist/RampsService.cjs.map +1 -1
  18. package/dist/RampsService.d.cts +104 -19
  19. package/dist/RampsService.d.cts.map +1 -1
  20. package/dist/RampsService.d.mts +104 -19
  21. package/dist/RampsService.d.mts.map +1 -1
  22. package/dist/RampsService.mjs +83 -8
  23. package/dist/RampsService.mjs.map +1 -1
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +3 -3
  26. package/dist/index.d.cts.map +1 -1
  27. package/dist/index.d.mts +3 -3
  28. package/dist/index.d.mts.map +1 -1
  29. package/dist/index.mjs.map +1 -1
  30. package/dist/selectors.cjs +5 -5
  31. package/dist/selectors.cjs.map +1 -1
  32. package/dist/selectors.d.cts +5 -5
  33. package/dist/selectors.d.mts +5 -5
  34. package/dist/selectors.mjs +5 -5
  35. package/dist/selectors.mjs.map +1 -1
  36. package/package.json +2 -2
@@ -1,8 +1,8 @@
1
1
  import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
2
  import { BaseController } from "@metamask/base-controller";
3
3
  import type { Messenger } from "@metamask/messenger";
4
- import type { Country, Eligibility } from "./RampsService.cjs";
5
- import type { RampsServiceGetGeolocationAction, RampsServiceGetCountriesAction, RampsServiceGetEligibilityAction } from "./RampsService-method-action-types.cjs";
4
+ import type { Country, TokensResponse, Provider, State } from "./RampsService.cjs";
5
+ import type { RampsServiceGetGeolocationAction, RampsServiceGetCountriesAction, RampsServiceGetTokensAction, RampsServiceGetProvidersAction } from "./RampsService-method-action-types.cjs";
6
6
  import type { RequestCache as RequestCacheType, RequestState, ExecuteRequestOptions } from "./RequestCache.cjs";
7
7
  /**
8
8
  * The name of the {@link RampsController}, used to namespace the
@@ -10,18 +10,48 @@ import type { RequestCache as RequestCacheType, RequestState, ExecuteRequestOpti
10
10
  * when composed with other controllers.
11
11
  */
12
12
  export declare const controllerName = "RampsController";
13
+ /**
14
+ * Represents the user's selected region with full country and state objects.
15
+ */
16
+ export type UserRegion = {
17
+ /**
18
+ * The country object for the selected region.
19
+ */
20
+ country: Country;
21
+ /**
22
+ * The state object if a state was selected, null if only country was selected.
23
+ */
24
+ state: State | null;
25
+ /**
26
+ * The region code string (e.g., "us-ut" or "fr") used for API calls.
27
+ */
28
+ regionCode: string;
29
+ };
13
30
  /**
14
31
  * Describes the shape of the state object for {@link RampsController}.
15
32
  */
16
33
  export type RampsControllerState = {
17
34
  /**
18
- * The user's country code determined by geolocation.
35
+ * The user's selected region with full country and state objects.
36
+ * Initially set via geolocation fetch, but can be manually changed by the user.
37
+ * Once set (either via geolocation or manual selection), it will not be overwritten
38
+ * by subsequent geolocation fetches.
39
+ */
40
+ userRegion: UserRegion | null;
41
+ /**
42
+ * The user's preferred provider.
43
+ * Can be manually set by the user.
19
44
  */
20
- geolocation: string | null;
45
+ preferredProvider: Provider | null;
21
46
  /**
22
- * Eligibility information for the user's current region.
47
+ * List of providers available for the current region.
23
48
  */
24
- eligibility: Eligibility | null;
49
+ providers: Provider[];
50
+ /**
51
+ * Tokens fetched for the current region and action.
52
+ * Contains topTokens and allTokens arrays.
53
+ */
54
+ tokens: TokensResponse | null;
25
55
  /**
26
56
  * Cache of request states, keyed by cache key.
27
57
  * This stores loading, success, and error states for API requests.
@@ -48,7 +78,7 @@ export type RampsControllerActions = RampsControllerGetStateAction;
48
78
  /**
49
79
  * Actions from other messengers that {@link RampsController} calls.
50
80
  */
51
- type AllowedActions = RampsServiceGetGeolocationAction | RampsServiceGetCountriesAction | RampsServiceGetEligibilityAction;
81
+ type AllowedActions = RampsServiceGetGeolocationAction | RampsServiceGetCountriesAction | RampsServiceGetTokensAction | RampsServiceGetProvidersAction;
52
82
  /**
53
83
  * Published when the state of {@link RampsController} changes.
54
84
  */
@@ -123,30 +153,79 @@ export declare class RampsController extends BaseController<typeof controllerNam
123
153
  */
124
154
  getRequestState(cacheKey: string): RequestState | undefined;
125
155
  /**
126
- * Updates the user's geolocation and eligibility.
127
- * This method calls the RampsService to get the geolocation,
128
- * then automatically fetches eligibility for that region.
156
+ * Updates the user's region by fetching geolocation.
157
+ * This method calls the RampsService to get the geolocation.
129
158
  *
130
159
  * @param options - Options for cache behavior.
131
- * @returns The geolocation string.
160
+ * @returns The user region object.
132
161
  */
133
- updateGeolocation(options?: ExecuteRequestOptions): Promise<string>;
162
+ updateUserRegion(options?: ExecuteRequestOptions): Promise<UserRegion | null>;
134
163
  /**
135
- * Updates the eligibility information for a given region.
164
+ * Sets the user's region manually (without fetching geolocation).
165
+ * This allows users to override the detected region.
136
166
  *
137
- * @param isoCode - The ISO code for the region (e.g., "us", "fr", "us-ny").
167
+ * @param region - The region code to set (e.g., "US-CA").
138
168
  * @param options - Options for cache behavior.
139
- * @returns The eligibility information.
169
+ * @returns The user region object.
140
170
  */
141
- updateEligibility(isoCode: string, options?: ExecuteRequestOptions): Promise<Eligibility>;
171
+ setUserRegion(region: string, options?: ExecuteRequestOptions): Promise<UserRegion>;
172
+ /**
173
+ * Sets the user's preferred provider.
174
+ * This allows users to set their preferred ramp provider.
175
+ *
176
+ * @param provider - The provider object to set.
177
+ */
178
+ setPreferredProvider(provider: Provider | null): void;
179
+ /**
180
+ * Initializes the controller by fetching the user's region from geolocation.
181
+ * This should be called once at app startup to set up the initial region.
182
+ * After the region is set, tokens are fetched and saved to state.
183
+ *
184
+ * If a userRegion already exists (from persistence or manual selection),
185
+ * this method will skip geolocation fetch and only fetch tokens if needed.
186
+ *
187
+ * @param options - Options for cache behavior.
188
+ * @returns Promise that resolves when initialization is complete.
189
+ */
190
+ init(options?: ExecuteRequestOptions): Promise<void>;
142
191
  /**
143
192
  * Fetches the list of supported countries for a given ramp action.
144
193
  *
145
194
  * @param action - The ramp action type ('buy' or 'sell').
146
195
  * @param options - Options for cache behavior.
147
- * @returns An array of countries with their eligibility information.
196
+ * @returns An array of countries.
148
197
  */
149
198
  getCountries(action?: 'buy' | 'sell', options?: ExecuteRequestOptions): Promise<Country[]>;
199
+ /**
200
+ * Fetches the list of available tokens for a given region and action.
201
+ * The tokens are saved in the controller state once fetched.
202
+ *
203
+ * @param region - The region code (e.g., "us", "fr", "us-ny"). If not provided, uses the user's region from controller state.
204
+ * @param action - The ramp action type ('buy' or 'sell').
205
+ * @param options - Options for cache behavior.
206
+ * @returns The tokens response containing topTokens and allTokens.
207
+ */
208
+ getTokens(region?: string, action?: 'buy' | 'sell', options?: ExecuteRequestOptions): Promise<TokensResponse>;
209
+ /**
210
+ * Fetches the list of providers for a given region.
211
+ * The providers are saved in the controller state once fetched.
212
+ *
213
+ * @param region - The region code (e.g., "us", "fr", "us-ny"). If not provided, uses the user's region from controller state.
214
+ * @param options - Options for cache behavior and query filters.
215
+ * @param options.provider - Provider ID(s) to filter by.
216
+ * @param options.crypto - Crypto currency ID(s) to filter by.
217
+ * @param options.fiat - Fiat currency ID(s) to filter by.
218
+ * @param options.payments - Payment method ID(s) to filter by.
219
+ * @returns The providers response containing providers array.
220
+ */
221
+ getProviders(region?: string, options?: ExecuteRequestOptions & {
222
+ provider?: string | string[];
223
+ crypto?: string | string[];
224
+ fiat?: string | string[];
225
+ payments?: string | string[];
226
+ }): Promise<{
227
+ providers: Provider[];
228
+ }>;
150
229
  }
151
230
  export {};
152
231
  //# sourceMappingURL=RampsController.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RampsController.d.cts","sourceRoot":"","sources":["../src/RampsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAGrD,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,2BAAuB;AAC3D,OAAO,KAAK,EACV,gCAAgC,EAChC,8BAA8B,EAC9B,gCAAgC,EACjC,+CAA2C;AAC5C,OAAO,KAAK,EACV,YAAY,IAAI,gBAAgB,EAChC,YAAY,EACZ,qBAAqB,EAEtB,2BAAuB;AAaxB;;;;GAIG;AACH,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAIhD;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B;;OAEG;IACH,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IAChC;;;OAGG;IACH,QAAQ,EAAE,gBAAgB,CAAC;CAC5B,CAAC;AA0BF;;;;;;;GAOG;AACH,wBAAgB,8BAA8B,IAAI,oBAAoB,CAMrE;AAID;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,wBAAwB,CAClE,OAAO,cAAc,EACrB,oBAAoB,CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,6BAA6B,CAAC;AAEnE;;GAEG;AACH,KAAK,cAAc,GACf,gCAAgC,GAChC,8BAA8B,GAC9B,gCAAgC,CAAC;AAErC;;GAEG;AACH,MAAM,MAAM,+BAA+B,GAAG,0BAA0B,CACtE,OAAO,cAAc,EACrB,o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M,EAAE,CAAC;QAC3B,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QACzB,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;KAC9B,GACA,OAAO,CAAC;QAAE,SAAS,EAAE,QAAQ,EAAE,CAAA;KAAE,CAAC;CA6CtC"}
@@ -1,8 +1,8 @@
1
1
  import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
2
  import { BaseController } from "@metamask/base-controller";
3
3
  import type { Messenger } from "@metamask/messenger";
4
- import type { Country, Eligibility } from "./RampsService.mjs";
5
- import type { RampsServiceGetGeolocationAction, RampsServiceGetCountriesAction, RampsServiceGetEligibilityAction } from "./RampsService-method-action-types.mjs";
4
+ import type { Country, TokensResponse, Provider, State } from "./RampsService.mjs";
5
+ import type { RampsServiceGetGeolocationAction, RampsServiceGetCountriesAction, RampsServiceGetTokensAction, RampsServiceGetProvidersAction } from "./RampsService-method-action-types.mjs";
6
6
  import type { RequestCache as RequestCacheType, RequestState, ExecuteRequestOptions } from "./RequestCache.mjs";
7
7
  /**
8
8
  * The name of the {@link RampsController}, used to namespace the
@@ -10,18 +10,48 @@ import type { RequestCache as RequestCacheType, RequestState, ExecuteRequestOpti
10
10
  * when composed with other controllers.
11
11
  */
12
12
  export declare const controllerName = "RampsController";
13
+ /**
14
+ * Represents the user's selected region with full country and state objects.
15
+ */
16
+ export type UserRegion = {
17
+ /**
18
+ * The country object for the selected region.
19
+ */
20
+ country: Country;
21
+ /**
22
+ * The state object if a state was selected, null if only country was selected.
23
+ */
24
+ state: State | null;
25
+ /**
26
+ * The region code string (e.g., "us-ut" or "fr") used for API calls.
27
+ */
28
+ regionCode: string;
29
+ };
13
30
  /**
14
31
  * Describes the shape of the state object for {@link RampsController}.
15
32
  */
16
33
  export type RampsControllerState = {
17
34
  /**
18
- * The user's country code determined by geolocation.
35
+ * The user's selected region with full country and state objects.
36
+ * Initially set via geolocation fetch, but can be manually changed by the user.
37
+ * Once set (either via geolocation or manual selection), it will not be overwritten
38
+ * by subsequent geolocation fetches.
39
+ */
40
+ userRegion: UserRegion | null;
41
+ /**
42
+ * The user's preferred provider.
43
+ * Can be manually set by the user.
19
44
  */
20
- geolocation: string | null;
45
+ preferredProvider: Provider | null;
21
46
  /**
22
- * Eligibility information for the user's current region.
47
+ * List of providers available for the current region.
23
48
  */
24
- eligibility: Eligibility | null;
49
+ providers: Provider[];
50
+ /**
51
+ * Tokens fetched for the current region and action.
52
+ * Contains topTokens and allTokens arrays.
53
+ */
54
+ tokens: TokensResponse | null;
25
55
  /**
26
56
  * Cache of request states, keyed by cache key.
27
57
  * This stores loading, success, and error states for API requests.
@@ -48,7 +78,7 @@ export type RampsControllerActions = RampsControllerGetStateAction;
48
78
  /**
49
79
  * Actions from other messengers that {@link RampsController} calls.
50
80
  */
51
- type AllowedActions = RampsServiceGetGeolocationAction | RampsServiceGetCountriesAction | RampsServiceGetEligibilityAction;
81
+ type AllowedActions = RampsServiceGetGeolocationAction | RampsServiceGetCountriesAction | RampsServiceGetTokensAction | RampsServiceGetProvidersAction;
52
82
  /**
53
83
  * Published when the state of {@link RampsController} changes.
54
84
  */
@@ -123,30 +153,79 @@ export declare class RampsController extends BaseController<typeof controllerNam
123
153
  */
124
154
  getRequestState(cacheKey: string): RequestState | undefined;
125
155
  /**
126
- * Updates the user's geolocation and eligibility.
127
- * This method calls the RampsService to get the geolocation,
128
- * then automatically fetches eligibility for that region.
156
+ * Updates the user's region by fetching geolocation.
157
+ * This method calls the RampsService to get the geolocation.
129
158
  *
130
159
  * @param options - Options for cache behavior.
131
- * @returns The geolocation string.
160
+ * @returns The user region object.
132
161
  */
133
- updateGeolocation(options?: ExecuteRequestOptions): Promise<string>;
162
+ updateUserRegion(options?: ExecuteRequestOptions): Promise<UserRegion | null>;
134
163
  /**
135
- * Updates the eligibility information for a given region.
164
+ * Sets the user's region manually (without fetching geolocation).
165
+ * This allows users to override the detected region.
136
166
  *
137
- * @param isoCode - The ISO code for the region (e.g., "us", "fr", "us-ny").
167
+ * @param region - The region code to set (e.g., "US-CA").
138
168
  * @param options - Options for cache behavior.
139
- * @returns The eligibility information.
169
+ * @returns The user region object.
140
170
  */
141
- updateEligibility(isoCode: string, options?: ExecuteRequestOptions): Promise<Eligibility>;
171
+ setUserRegion(region: string, options?: ExecuteRequestOptions): Promise<UserRegion>;
172
+ /**
173
+ * Sets the user's preferred provider.
174
+ * This allows users to set their preferred ramp provider.
175
+ *
176
+ * @param provider - The provider object to set.
177
+ */
178
+ setPreferredProvider(provider: Provider | null): void;
179
+ /**
180
+ * Initializes the controller by fetching the user's region from geolocation.
181
+ * This should be called once at app startup to set up the initial region.
182
+ * After the region is set, tokens are fetched and saved to state.
183
+ *
184
+ * If a userRegion already exists (from persistence or manual selection),
185
+ * this method will skip geolocation fetch and only fetch tokens if needed.
186
+ *
187
+ * @param options - Options for cache behavior.
188
+ * @returns Promise that resolves when initialization is complete.
189
+ */
190
+ init(options?: ExecuteRequestOptions): Promise<void>;
142
191
  /**
143
192
  * Fetches the list of supported countries for a given ramp action.
144
193
  *
145
194
  * @param action - The ramp action type ('buy' or 'sell').
146
195
  * @param options - Options for cache behavior.
147
- * @returns An array of countries with their eligibility information.
196
+ * @returns An array of countries.
148
197
  */
149
198
  getCountries(action?: 'buy' | 'sell', options?: ExecuteRequestOptions): Promise<Country[]>;
199
+ /**
200
+ * Fetches the list of available tokens for a given region and action.
201
+ * The tokens are saved in the controller state once fetched.
202
+ *
203
+ * @param region - The region code (e.g., "us", "fr", "us-ny"). If not provided, uses the user's region from controller state.
204
+ * @param action - The ramp action type ('buy' or 'sell').
205
+ * @param options - Options for cache behavior.
206
+ * @returns The tokens response containing topTokens and allTokens.
207
+ */
208
+ getTokens(region?: string, action?: 'buy' | 'sell', options?: ExecuteRequestOptions): Promise<TokensResponse>;
209
+ /**
210
+ * Fetches the list of providers for a given region.
211
+ * The providers are saved in the controller state once fetched.
212
+ *
213
+ * @param region - The region code (e.g., "us", "fr", "us-ny"). If not provided, uses the user's region from controller state.
214
+ * @param options - Options for cache behavior and query filters.
215
+ * @param options.provider - Provider ID(s) to filter by.
216
+ * @param options.crypto - Crypto currency ID(s) to filter by.
217
+ * @param options.fiat - Fiat currency ID(s) to filter by.
218
+ * @param options.payments - Payment method ID(s) to filter by.
219
+ * @returns The providers response containing providers array.
220
+ */
221
+ getProviders(region?: string, options?: ExecuteRequestOptions & {
222
+ provider?: string | string[];
223
+ crypto?: string | string[];
224
+ fiat?: string | string[];
225
+ payments?: string | string[];
226
+ }): Promise<{
227
+ providers: Provider[];
228
+ }>;
150
229
  }
151
230
  export {};
152
231
  //# sourceMappingURL=RampsController.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RampsController.d.mts","sourceRoot":"","sources":["../src/RampsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAGrD,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,2BAAuB;AAC3D,OAAO,KAAK,EACV,gCAAgC,EAChC,8BAA8B,EAC9B,gCAAgC,EACjC,+CAA2C;AAC5C,OAAO,KAAK,EACV,YAAY,IAAI,gBAAgB,EAChC,YAAY,EACZ,qBAAqB,EAEtB,2BAAuB;AAaxB;;;;GAIG;AACH,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAIhD;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B;;OAEG;IACH,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IAChC;;;OAGG;IACH,QAAQ,EAAE,gBAAgB,CAAC;CAC5B,CAAC;AA0BF;;;;;;;GAOG;AACH,wBAAgB,8BAA8B,IAAI,oBAAoB,CAMrE;AAID;;GAEG;AACH,MAA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