@metamask-previews/ramps-controller 10.0.0-preview-685dbf46b → 10.1.0-preview-968b2b4f4

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 CHANGED
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [10.1.0]
11
+
10
12
  ### Added
11
13
 
12
14
  - Added `orders: RampsOrder[]` to controller state with persistence, along with crud methods([#8045](https://github.com/MetaMask/core/pull/8045))
@@ -14,10 +16,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
14
16
  - Added `RampsController:orderStatusChanged` event, published when a polled order's status transitions ([#8045](https://github.com/MetaMask/core/pull/8045))
15
17
  - Add messenger actions for `RampsController:setSelectedToken`, `RampsController:getQuotes`, and `RampsController:getOrder`, register their handlers in `RampsController`, and export the action types from the package index ([#8081](https://github.com/MetaMask/core/pull/8081))
16
18
 
17
- ### Changed
18
-
19
- - **BREAKING:** Replace `getWidgetUrl` with `getBuyWidgetData` (returns `BuyWidget | null`); add `addPrecreatedOrder` for custom-action ramp flows (e.g., PayPal) ([#8100](https://github.com/MetaMask/core/pull/8100))
20
-
21
19
  ## [10.0.0]
22
20
 
23
21
  ### Changed
@@ -194,7 +192,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
194
192
  - Add `OnRampService` for interacting with the OnRamp API
195
193
  - Add geolocation detection via IP address lookup
196
194
 
197
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/ramps-controller@10.0.0...HEAD
195
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/ramps-controller@10.1.0...HEAD
196
+ [10.1.0]: https://github.com/MetaMask/core/compare/@metamask/ramps-controller@10.0.0...@metamask/ramps-controller@10.1.0
198
197
  [10.0.0]: https://github.com/MetaMask/core/compare/@metamask/ramps-controller@9.0.0...@metamask/ramps-controller@10.0.0
199
198
  [9.0.0]: https://github.com/MetaMask/core/compare/@metamask/ramps-controller@8.1.0...@metamask/ramps-controller@9.0.0
200
199
  [8.1.0]: https://github.com/MetaMask/core/compare/@metamask/ramps-controller@8.0.0...@metamask/ramps-controller@8.1.0
@@ -12,7 +12,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
12
12
  };
13
13
  var _RampsController_instances, _RampsController_requestCacheTTL, _RampsController_requestCacheMaxSize, _RampsController_pendingRequests, _RampsController_pendingResourceCount, _RampsController_orderPollingMeta, _RampsController_orderPollingTimer, _RampsController_isPolling, _RampsController_clearPendingResourceCountForDependentResources, _RampsController_abortDependentRequests, _RampsController_registerActionHandlers, _RampsController_mutateRequests, _RampsController_removeRequestState, _RampsController_cleanupState, _RampsController_fireAndForget, _RampsController_requireRegion, _RampsController_isRegionCurrent, _RampsController_isTokenCurrent, _RampsController_isProviderCurrent, _RampsController_updateResourceField, _RampsController_setResourceLoading, _RampsController_setResourceError, _RampsController_updateRequestState, _RampsController_refreshOrder, _RampsController_pollPendingOrders, _RampsController_syncTransakAuthOnError;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.RampsController = exports.normalizeProviderCode = exports.getDefaultRampsControllerState = exports.RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS = exports.controllerName = void 0;
15
+ exports.RampsController = exports.getDefaultRampsControllerState = exports.RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS = exports.controllerName = void 0;
16
16
  const base_controller_1 = require("@metamask/base-controller");
17
17
  const RampsService_1 = require("./RampsService.cjs");
18
18
  const RequestCache_1 = require("./RequestCache.cjs");
@@ -250,10 +250,6 @@ function findRegionFromCode(regionCode, countries) {
250
250
  regionCode: normalizedCode,
251
251
  };
252
252
  }
253
- function normalizeProviderCode(providerCode) {
254
- return providerCode.replace(/^\/providers\//u, '');
255
- }
256
- exports.normalizeProviderCode = normalizeProviderCode;
257
253
  // === ORDER POLLING CONSTANTS ===
258
254
  const TERMINAL_ORDER_STATUSES = new Set([
259
255
  RampsService_1.RampsOrderStatus.Completed,
@@ -939,74 +935,25 @@ class RampsController extends base_controller_1.BaseController {
939
935
  super.destroy();
940
936
  }
941
937
  /**
942
- * Fetches the widget data from a quote for redirect providers.
938
+ * Fetches the widget URL from a quote for redirect providers.
943
939
  * Makes a request to the buyURL endpoint via the RampsService to get the
944
- * actual provider widget URL and optional order ID for polling.
940
+ * actual provider widget URL.
945
941
  *
946
942
  * @param quote - The quote to fetch the widget URL from.
947
- * @returns Promise resolving to the full BuyWidget (url, browser, orderId), or null if not available (missing buyURL or empty url in response).
948
- * @throws Rethrows errors from the RampsService (e.g. HttpError, network failures) so clients can react to fetch failures.
943
+ * @returns Promise resolving to the widget URL string, or null if not available.
949
944
  */
950
- async getBuyWidgetData(quote) {
945
+ async getWidgetUrl(quote) {
951
946
  const buyUrl = quote.quote?.buyURL;
952
947
  if (!buyUrl) {
953
948
  return null;
954
949
  }
955
- const buyWidget = await this.messenger.call('RampsService:getBuyWidgetUrl', buyUrl);
956
- if (!buyWidget?.url) {
957
- return null;
950
+ try {
951
+ const buyWidget = await this.messenger.call('RampsService:getBuyWidgetUrl', buyUrl);
952
+ return buyWidget.url ?? null;
958
953
  }
959
- return buyWidget;
960
- }
961
- /**
962
- * Registers an order ID for polling until the order is created or resolved.
963
- * Adds a minimal stub order to controller state; the existing order polling
964
- * will fetch the full order when the provider has created it.
965
- *
966
- * @param params - Object containing order identifiers and wallet info.
967
- * @param params.orderId - Full order ID (e.g. "/providers/paypal/orders/abc123") or order code.
968
- * @param params.providerCode - Provider code (e.g. "paypal", "transak"), with or without /providers/ prefix.
969
- * @param params.walletAddress - Wallet address for the order.
970
- * @param params.chainId - Optional chain ID for the order.
971
- */
972
- addPrecreatedOrder(params) {
973
- const { orderId, providerCode, walletAddress, chainId } = params;
974
- const orderCode = orderId.includes('/orders/')
975
- ? orderId.split('/orders/')[1]
976
- : orderId;
977
- if (!orderCode?.trim()) {
978
- return;
954
+ catch {
955
+ return null;
979
956
  }
980
- const normalizedProviderCode = normalizeProviderCode(providerCode);
981
- const stubOrder = {
982
- providerOrderId: orderCode,
983
- provider: {
984
- id: `/providers/${normalizedProviderCode}`,
985
- name: '',
986
- environmentType: '',
987
- description: '',
988
- hqAddress: '',
989
- links: [],
990
- logos: { light: '', dark: '', height: 0, width: 0 },
991
- },
992
- walletAddress,
993
- status: RampsService_1.RampsOrderStatus.Precreated,
994
- orderType: 'buy',
995
- createdAt: Date.now(),
996
- isOnlyLink: false,
997
- success: false,
998
- cryptoAmount: 0,
999
- fiatAmount: 0,
1000
- providerOrderLink: '',
1001
- totalFeesFiat: 0,
1002
- txHash: '',
1003
- network: chainId ? { chainId, name: '' } : { chainId: '', name: '' },
1004
- canBeUpdated: true,
1005
- idHasExpired: false,
1006
- excludeFromPurchases: false,
1007
- timeDescriptionPending: '',
1008
- };
1009
- this.addOrder(stubOrder);
1010
957
  }
1011
958
  /**
1012
959
  * Fetches an order from the unified V2 API endpoint.
@@ -1539,7 +1486,7 @@ async function _RampsController_refreshOrder(order) {
1539
1486
  if (!providerCode || !order.providerOrderId || !order.walletAddress) {
1540
1487
  return;
1541
1488
  }
1542
- const providerCodeSegment = normalizeProviderCode(providerCode);
1489
+ const providerCodeSegment = providerCode.replace('/providers/', '');
1543
1490
  const previousStatus = order.status;
1544
1491
  try {
1545
1492
  const updatedOrder = await this.getOrder(providerCodeSegment, order.providerOrderId, order.walletAddress);