@metamask-previews/ramps-controller 10.2.0-preview-d8831108d → 10.2.0-preview-fe5e4090d
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 +0 -4
- package/dist/RampsController.cjs +12 -72
- package/dist/RampsController.cjs.map +1 -1
- package/dist/RampsController.d.cts +7 -25
- package/dist/RampsController.d.cts.map +1 -1
- package/dist/RampsController.d.mts +7 -25
- package/dist/RampsController.d.mts.map +1 -1
- package/dist/RampsController.mjs +11 -70
- package/dist/RampsController.mjs.map +1 -1
- package/dist/index.cjs +1 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -22,10 +22,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
22
22
|
- Added `RampsController:orderStatusChanged` event, published when a polled order's status transitions ([#8045](https://github.com/MetaMask/core/pull/8045))
|
|
23
23
|
- 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))
|
|
24
24
|
|
|
25
|
-
### Changed
|
|
26
|
-
|
|
27
|
-
- **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))
|
|
28
|
-
|
|
29
25
|
## [10.0.0]
|
|
30
26
|
|
|
31
27
|
### Changed
|
package/dist/RampsController.cjs
CHANGED
|
@@ -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.
|
|
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,
|
|
@@ -949,74 +945,25 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
949
945
|
super.destroy();
|
|
950
946
|
}
|
|
951
947
|
/**
|
|
952
|
-
* Fetches the widget
|
|
948
|
+
* Fetches the widget URL from a quote for redirect providers.
|
|
953
949
|
* Makes a request to the buyURL endpoint via the RampsService to get the
|
|
954
|
-
* actual provider widget URL
|
|
950
|
+
* actual provider widget URL.
|
|
955
951
|
*
|
|
956
952
|
* @param quote - The quote to fetch the widget URL from.
|
|
957
|
-
* @returns Promise resolving to the
|
|
958
|
-
* @throws Rethrows errors from the RampsService (e.g. HttpError, network failures) so clients can react to fetch failures.
|
|
953
|
+
* @returns Promise resolving to the widget URL string, or null if not available.
|
|
959
954
|
*/
|
|
960
|
-
async
|
|
955
|
+
async getWidgetUrl(quote) {
|
|
961
956
|
const buyUrl = quote.quote?.buyURL;
|
|
962
957
|
if (!buyUrl) {
|
|
963
958
|
return null;
|
|
964
959
|
}
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
return null;
|
|
960
|
+
try {
|
|
961
|
+
const buyWidget = await this.messenger.call('RampsService:getBuyWidgetUrl', buyUrl);
|
|
962
|
+
return buyWidget.url ?? null;
|
|
968
963
|
}
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
/**
|
|
972
|
-
* Registers an order ID for polling until the order is created or resolved.
|
|
973
|
-
* Adds a minimal stub order to controller state; the existing order polling
|
|
974
|
-
* will fetch the full order when the provider has created it.
|
|
975
|
-
*
|
|
976
|
-
* @param params - Object containing order identifiers and wallet info.
|
|
977
|
-
* @param params.orderId - Full order ID (e.g. "/providers/paypal/orders/abc123") or order code.
|
|
978
|
-
* @param params.providerCode - Provider code (e.g. "paypal", "transak"), with or without /providers/ prefix.
|
|
979
|
-
* @param params.walletAddress - Wallet address for the order.
|
|
980
|
-
* @param params.chainId - Optional chain ID for the order.
|
|
981
|
-
*/
|
|
982
|
-
addPrecreatedOrder(params) {
|
|
983
|
-
const { orderId, providerCode, walletAddress, chainId } = params;
|
|
984
|
-
const orderCode = orderId.includes('/orders/')
|
|
985
|
-
? orderId.split('/orders/')[1]
|
|
986
|
-
: orderId;
|
|
987
|
-
if (!orderCode?.trim()) {
|
|
988
|
-
return;
|
|
964
|
+
catch {
|
|
965
|
+
return null;
|
|
989
966
|
}
|
|
990
|
-
const normalizedProviderCode = normalizeProviderCode(providerCode);
|
|
991
|
-
const stubOrder = {
|
|
992
|
-
providerOrderId: orderCode,
|
|
993
|
-
provider: {
|
|
994
|
-
id: `/providers/${normalizedProviderCode}`,
|
|
995
|
-
name: '',
|
|
996
|
-
environmentType: '',
|
|
997
|
-
description: '',
|
|
998
|
-
hqAddress: '',
|
|
999
|
-
links: [],
|
|
1000
|
-
logos: { light: '', dark: '', height: 0, width: 0 },
|
|
1001
|
-
},
|
|
1002
|
-
walletAddress,
|
|
1003
|
-
status: RampsService_1.RampsOrderStatus.Precreated,
|
|
1004
|
-
orderType: 'buy',
|
|
1005
|
-
createdAt: Date.now(),
|
|
1006
|
-
isOnlyLink: false,
|
|
1007
|
-
success: false,
|
|
1008
|
-
cryptoAmount: 0,
|
|
1009
|
-
fiatAmount: 0,
|
|
1010
|
-
providerOrderLink: '',
|
|
1011
|
-
totalFeesFiat: 0,
|
|
1012
|
-
txHash: '',
|
|
1013
|
-
network: chainId ? { chainId, name: '' } : { chainId: '', name: '' },
|
|
1014
|
-
canBeUpdated: true,
|
|
1015
|
-
idHasExpired: false,
|
|
1016
|
-
excludeFromPurchases: false,
|
|
1017
|
-
timeDescriptionPending: '',
|
|
1018
|
-
};
|
|
1019
|
-
this.addOrder(stubOrder);
|
|
1020
967
|
}
|
|
1021
968
|
/**
|
|
1022
969
|
* Fetches an order from the unified V2 API endpoint.
|
|
@@ -1031,17 +978,10 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
1031
978
|
const order = await this.messenger.call('RampsService:getOrder', providerCode, orderCode, wallet);
|
|
1032
979
|
this.update((state) => {
|
|
1033
980
|
const idx = state.orders.findIndex((existing) => existing.providerOrderId === orderCode);
|
|
1034
|
-
if (idx
|
|
1035
|
-
state.orders.push({
|
|
1036
|
-
...order,
|
|
1037
|
-
providerOrderId: orderCode,
|
|
1038
|
-
});
|
|
1039
|
-
}
|
|
1040
|
-
else {
|
|
981
|
+
if (idx !== -1) {
|
|
1041
982
|
state.orders[idx] = {
|
|
1042
983
|
...state.orders[idx],
|
|
1043
984
|
...order,
|
|
1044
|
-
providerOrderId: orderCode,
|
|
1045
985
|
};
|
|
1046
986
|
}
|
|
1047
987
|
});
|
|
@@ -1556,7 +1496,7 @@ async function _RampsController_refreshOrder(order) {
|
|
|
1556
1496
|
if (!providerCode || !order.providerOrderId || !order.walletAddress) {
|
|
1557
1497
|
return;
|
|
1558
1498
|
}
|
|
1559
|
-
const providerCodeSegment =
|
|
1499
|
+
const providerCodeSegment = providerCode.replace('/providers/', '');
|
|
1560
1500
|
const previousStatus = order.status;
|
|
1561
1501
|
try {
|
|
1562
1502
|
const updatedOrder = await this.getOrder(providerCodeSegment, order.providerOrderId, order.walletAddress);
|