@metamask/ramps-controller 13.2.0 → 13.3.1
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 -1
- package/dist/RampsController.cjs +166 -58
- package/dist/RampsController.cjs.map +1 -1
- package/dist/RampsController.d.cts +5 -0
- package/dist/RampsController.d.cts.map +1 -1
- package/dist/RampsController.d.mts +5 -0
- package/dist/RampsController.d.mts.map +1 -1
- package/dist/RampsController.mjs +166 -58
- package/dist/RampsController.mjs.map +1 -1
- package/dist/RampsService.cjs +8 -3
- package/dist/RampsService.cjs.map +1 -1
- package/dist/RampsService.d.cts.map +1 -1
- package/dist/RampsService.d.mts.map +1 -1
- package/dist/RampsService.mjs +8 -3
- package/dist/RampsService.mjs.map +1 -1
- package/dist/RequestCache.cjs +7 -2
- package/dist/RequestCache.cjs.map +1 -1
- package/dist/RequestCache.d.cts +5 -1
- package/dist/RequestCache.d.cts.map +1 -1
- package/dist/RequestCache.d.mts +5 -1
- package/dist/RequestCache.d.mts.map +1 -1
- package/dist/RequestCache.mjs +7 -2
- package/dist/RequestCache.mjs.map +1 -1
- package/dist/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/rampsErrorCodes.cjs +11 -0
- package/dist/rampsErrorCodes.cjs.map +1 -0
- package/dist/rampsErrorCodes.d.cts +9 -0
- package/dist/rampsErrorCodes.d.cts.map +1 -0
- package/dist/rampsErrorCodes.d.mts +9 -0
- package/dist/rampsErrorCodes.d.mts.map +1 -0
- package/dist/rampsErrorCodes.mjs +8 -0
- package/dist/rampsErrorCodes.mjs.map +1 -0
- package/dist/selectors.cjs +5 -1
- package/dist/selectors.cjs.map +1 -1
- package/dist/selectors.d.cts +3 -0
- package/dist/selectors.d.cts.map +1 -1
- package/dist/selectors.d.mts +3 -0
- package/dist/selectors.d.mts.map +1 -1
- package/dist/selectors.mjs +5 -1
- package/dist/selectors.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA+DA,OAAO,EACL,eAAe,EACf,8BAA8B,EAC9B,qBAAqB,EACrB,yCAAyC,EAC1C,8BAA0B;AAqC3B,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EAClB,2BAAuB;
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA+DA,OAAO,EACL,eAAe,EACf,8BAA8B,EAC9B,qBAAqB,EACrB,yCAAyC,EAC1C,8BAA0B;AAqC3B,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EAClB,2BAAuB;AAkBxB,OAAO,EACL,aAAa,EACb,yBAAyB,EACzB,8BAA8B,EAC9B,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EACjB,2BAAuB;AACxB,OAAO,EAAE,iBAAiB,EAAE,8BAA0B;AAEtD,OAAO,EAAE,qBAAqB,EAAE,wBAAoB;AA2BpD,OAAO,EACL,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,yBAAyB,EAC1B,6BAAyB","sourcesContent":["export type {\n RampsControllerActions,\n RampsControllerEvents,\n RampsControllerGetStateAction,\n RampsControllerMessenger,\n RampsControllerState,\n RampsControllerStateChangeEvent,\n RampsControllerOrderStatusChangedEvent,\n RampsControllerOptions,\n UserRegion,\n ResourceState,\n TransakState,\n NativeProvidersState,\n} from './RampsController';\nexport type {\n RampsControllerExecuteRequestAction,\n RampsControllerAbortRequestAction,\n RampsControllerGetRequestStateAction,\n RampsControllerSetUserRegionAction,\n RampsControllerSetSelectedProviderAction,\n RampsControllerInitAction,\n RampsControllerGetCountriesAction,\n RampsControllerGetTokensAction,\n RampsControllerSetSelectedTokenAction,\n RampsControllerGetProvidersAction,\n RampsControllerGetPaymentMethodsAction,\n RampsControllerSetSelectedPaymentMethodAction,\n RampsControllerGetQuotesAction,\n RampsControllerAddOrderAction,\n RampsControllerRemoveOrderAction,\n RampsControllerStartOrderPollingAction,\n RampsControllerStopOrderPollingAction,\n RampsControllerGetBuyWidgetDataAction,\n RampsControllerAddPrecreatedOrderAction,\n RampsControllerGetOrderAction,\n RampsControllerGetOrderFromCallbackAction,\n RampsControllerTransakSetApiKeyAction,\n RampsControllerTransakSetAccessTokenAction,\n RampsControllerTransakClearAccessTokenAction,\n RampsControllerTransakSetAuthenticatedAction,\n RampsControllerTransakResetStateAction,\n RampsControllerTransakSendUserOtpAction,\n RampsControllerTransakVerifyUserOtpAction,\n RampsControllerTransakLogoutAction,\n RampsControllerTransakGetUserDetailsAction,\n RampsControllerTransakGetBuyQuoteAction,\n RampsControllerTransakGetKycRequirementAction,\n RampsControllerTransakGetAdditionalRequirementsAction,\n RampsControllerTransakCreateOrderAction,\n RampsControllerTransakGetOrderAction,\n RampsControllerTransakGetUserLimitsAction,\n RampsControllerTransakRequestOttAction,\n RampsControllerTransakGeneratePaymentWidgetUrlAction,\n RampsControllerTransakSubmitPurposeOfUsageFormAction,\n RampsControllerTransakPatchUserAction,\n RampsControllerTransakSubmitSsnDetailsAction,\n RampsControllerTransakConfirmPaymentAction,\n RampsControllerTransakGetTranslationAction,\n RampsControllerTransakGetIdProofStatusAction,\n RampsControllerTransakCancelOrderAction,\n RampsControllerTransakCancelAllActiveOrdersAction,\n RampsControllerTransakGetActiveOrdersAction,\n} from './RampsController-method-action-types';\nexport {\n RampsController,\n getDefaultRampsControllerState,\n normalizeProviderCode,\n RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS,\n} from './RampsController';\nexport type {\n RampsServiceActions,\n RampsServiceEvents,\n RampsServiceMessenger,\n Country,\n State,\n SupportedActions,\n CountryPhone,\n Provider,\n ProviderLink,\n ProviderLogos,\n ProviderBrowserType,\n ProviderLimit,\n ProviderFiatLimits,\n ProviderLimits,\n RampAction,\n PaymentMethod,\n PaymentMethodsResponse,\n Quote,\n QuoteError,\n QuoteSortBy,\n QuoteSortOrder,\n QuoteCryptoTranslation,\n QuoteCustomAction,\n QuotesResponse,\n GetQuotesParams,\n RampsToken,\n TokensResponse,\n BuyWidget,\n RampsOrder,\n RampsOrderNetwork,\n RampsOrderCryptoCurrency,\n RampsOrderFiatCurrency,\n RampsOrderPaymentMethod,\n OrderPaymentDetail,\n} from './RampsService';\nexport {\n RampsService,\n RampsEnvironment,\n RampsApiService,\n RampsOrderStatus,\n RAMPS_SDK_VERSION,\n} from './RampsService';\nexport type {\n RampsServiceGetGeolocationAction,\n RampsServiceGetCountriesAction,\n RampsServiceGetPaymentMethodsAction,\n RampsServiceGetQuotesAction,\n RampsServiceGetBuyWidgetUrlAction,\n RampsServiceGetOrderAction,\n RampsServiceGetOrderFromCallbackAction,\n} from './RampsService-method-action-types';\nexport type {\n RequestCache,\n RequestState,\n ExecuteRequestOptions,\n PendingRequest,\n ResourceType,\n} from './RequestCache';\nexport type { RampsErrorCode } from './rampsErrorCodes';\nexport {\n RequestStatus,\n DEFAULT_REQUEST_CACHE_TTL,\n DEFAULT_REQUEST_CACHE_MAX_SIZE,\n createCacheKey,\n isCacheExpired,\n createLoadingState,\n createSuccessState,\n createErrorState,\n} from './RequestCache';\nexport { RAMPS_ERROR_CODES } from './rampsErrorCodes';\nexport type { RequestSelectorResult } from './selectors';\nexport { createRequestSelector } from './selectors';\nexport type {\n TransakServiceActions,\n TransakServiceEvents,\n TransakServiceMessenger,\n TransakAccessToken,\n TransakUserDetails,\n TransakUserDetailsAddress,\n TransakUserDetailsKycDetails,\n TransakBuyQuote,\n TransakKycRequirement,\n TransakAdditionalRequirement,\n TransakAdditionalRequirementsResponse,\n TransakOttResponse,\n TransakOrderPaymentMethod,\n TransakDepositOrder,\n TransakDepositNetwork,\n TransakDepositCryptoCurrency,\n TransakDepositPaymentMethod,\n TransakDepositRegion,\n TransakOrder,\n TransakQuoteTranslation,\n TransakTranslationRequest,\n TransakUserLimits,\n TransakIdProofStatus,\n PatchUserRequestBody as TransakPatchUserRequestBody,\n} from './TransakService';\nexport {\n TransakApiError,\n TransakService,\n TransakEnvironment,\n TransakOrderIdTransformer,\n} from './TransakService';\nexport type {\n TransakServiceMethodActions,\n TransakServiceSendUserOtpAction,\n TransakServiceVerifyUserOtpAction,\n TransakServiceGetUserDetailsAction,\n TransakServiceGetBuyQuoteAction,\n TransakServiceGetKycRequirementAction,\n TransakServiceCreateOrderAction,\n TransakServiceGetOrderAction,\n TransakServiceRequestOttAction,\n TransakServiceGeneratePaymentWidgetUrlAction,\n} from './TransakService-method-action-types';\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RAMPS_ERROR_CODES = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Error codes for RampsController.
|
|
6
|
+
* These codes are returned to the UI layer for translation.
|
|
7
|
+
*/
|
|
8
|
+
exports.RAMPS_ERROR_CODES = {
|
|
9
|
+
CIRCUIT_BREAKER_OPEN: 'CIRCUIT_BREAKER_OPEN',
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=rampsErrorCodes.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rampsErrorCodes.cjs","sourceRoot":"","sources":["../src/rampsErrorCodes.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACU,QAAA,iBAAiB,GAAG;IAC/B,oBAAoB,EAAE,sBAAsB;CACpC,CAAC","sourcesContent":["/**\n * Error codes for RampsController.\n * These codes are returned to the UI layer for translation.\n */\nexport const RAMPS_ERROR_CODES = {\n CIRCUIT_BREAKER_OPEN: 'CIRCUIT_BREAKER_OPEN',\n} as const;\n\nexport type RampsErrorCode =\n (typeof RAMPS_ERROR_CODES)[keyof typeof RAMPS_ERROR_CODES];\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error codes for RampsController.
|
|
3
|
+
* These codes are returned to the UI layer for translation.
|
|
4
|
+
*/
|
|
5
|
+
export declare const RAMPS_ERROR_CODES: {
|
|
6
|
+
readonly CIRCUIT_BREAKER_OPEN: "CIRCUIT_BREAKER_OPEN";
|
|
7
|
+
};
|
|
8
|
+
export type RampsErrorCode = (typeof RAMPS_ERROR_CODES)[keyof typeof RAMPS_ERROR_CODES];
|
|
9
|
+
//# sourceMappingURL=rampsErrorCodes.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rampsErrorCodes.d.cts","sourceRoot":"","sources":["../src/rampsErrorCodes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,iBAAiB;;CAEpB,CAAC;AAEX,MAAM,MAAM,cAAc,GACxB,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error codes for RampsController.
|
|
3
|
+
* These codes are returned to the UI layer for translation.
|
|
4
|
+
*/
|
|
5
|
+
export declare const RAMPS_ERROR_CODES: {
|
|
6
|
+
readonly CIRCUIT_BREAKER_OPEN: "CIRCUIT_BREAKER_OPEN";
|
|
7
|
+
};
|
|
8
|
+
export type RampsErrorCode = (typeof RAMPS_ERROR_CODES)[keyof typeof RAMPS_ERROR_CODES];
|
|
9
|
+
//# sourceMappingURL=rampsErrorCodes.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rampsErrorCodes.d.mts","sourceRoot":"","sources":["../src/rampsErrorCodes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,iBAAiB;;CAEpB,CAAC;AAEX,MAAM,MAAM,cAAc,GACxB,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rampsErrorCodes.mjs","sourceRoot":"","sources":["../src/rampsErrorCodes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,oBAAoB,EAAE,sBAAsB;CACpC,CAAC","sourcesContent":["/**\n * Error codes for RampsController.\n * These codes are returned to the UI layer for translation.\n */\nexport const RAMPS_ERROR_CODES = {\n CIRCUIT_BREAKER_OPEN: 'CIRCUIT_BREAKER_OPEN',\n} as const;\n\nexport type RampsErrorCode =\n (typeof RAMPS_ERROR_CODES)[keyof typeof RAMPS_ERROR_CODES];\n"]}
|
package/dist/selectors.cjs
CHANGED
|
@@ -69,11 +69,15 @@ function createRequestSelector(getState, method, params) {
|
|
|
69
69
|
return lastResult;
|
|
70
70
|
}
|
|
71
71
|
lastRequest = request;
|
|
72
|
-
|
|
72
|
+
const nextResult = {
|
|
73
73
|
data: request?.data ?? null,
|
|
74
74
|
isFetching: request?.status === RequestCache_1.RequestStatus.LOADING,
|
|
75
75
|
error: request?.error ?? null,
|
|
76
76
|
};
|
|
77
|
+
if (request?.errorKey) {
|
|
78
|
+
nextResult.errorKey = request.errorKey;
|
|
79
|
+
}
|
|
80
|
+
lastResult = nextResult;
|
|
77
81
|
return lastResult;
|
|
78
82
|
};
|
|
79
83
|
}
|
package/dist/selectors.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.cjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"selectors.cjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":";;;AAGA,qDAA+D;AAoB/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,SAAgB,qBAAqB,CACnC,QAAqE,EACrE,MAAc,EACd,MAAiB;IAEjB,MAAM,QAAQ,GAAG,IAAA,6BAAc,EAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEhD,IAAI,WAAqC,CAAC;IAC1C,IAAI,UAAU,GAAwC,IAAI,CAAC;IAE3D,OAAO,CAAC,KAAiB,EAAgC,EAAE;QACzD,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC;QAEtD,IAAI,OAAO,KAAK,WAAW,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;YACnD,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,WAAW,GAAG,OAAO,CAAC;QACtB,MAAM,UAAU,GAAiC;YAC/C,IAAI,EAAG,OAAO,EAAE,IAAc,IAAI,IAAI;YACtC,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,4BAAa,CAAC,OAAO;YACrD,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,IAAI;SAC9B,CAAC;QAEF,IAAI,OAAO,EAAE,QAAQ,EAAE,CAAC;YACtB,UAAU,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACzC,CAAC;QAED,UAAU,GAAG,UAAU,CAAC;QAExB,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC;AAhCD,sDAgCC","sourcesContent":["import type { RampsControllerState } from './RampsController';\nimport type { RampsErrorCode } from './rampsErrorCodes';\nimport type { RequestState } from './RequestCache';\nimport { RequestStatus, createCacheKey } from './RequestCache';\n\n/**\n * Result shape returned by request selectors.\n *\n * This object is memoized - the same reference is returned when the underlying\n * request state hasn't changed, making it safe to use with React Redux's\n * `useSelector` without `shallowEqual`.\n */\nexport type RequestSelectorResult<TData> = {\n /** The data returned by the request, or null if not yet loaded or on error. */\n data: TData | null;\n /** Whether the request is currently in progress. */\n isFetching: boolean;\n /** Error message if the request failed, or null if successful or not yet attempted. */\n error: string | null;\n /** Stable error key for client-side localization, if available. */\n errorKey?: RampsErrorCode | null;\n};\n\n/**\n * Creates a memoized selector for a controller method's request state.\n *\n * This selector tracks the loading, error, and data state for a specific\n * controller method call. It's optimized for use with React Redux's `useSelector`\n * hook - the selector returns the same object reference when the underlying\n * request state hasn't changed, so no `shallowEqual` is needed.\n *\n * The selector uses reference equality on the request object itself, so it\n * works correctly with arrays and objects without expensive deep equality checks.\n *\n * @param getState - Function that extracts RampsControllerState from the root state.\n * Typically a reselect selector like `selectRampsControllerState`.\n * @param method - The controller method name (e.g., 'updateUserRegion').\n * @param params - The parameters passed to the method, used to generate the cache key.\n * Must match the params used when calling the controller method.\n * @returns A selector function that returns `{ data, isFetching, error }`.\n *\n * @example\n * ```ts\n * // In selectors file - create once at module level\n * import { createRequestSelector } from '@metamask/ramps-controller';\n * import { createSelector } from 'reselect';\n *\n * const selectRampsControllerState = createSelector(\n * (state: RootState) => state.engine.backgroundState.RampsController,\n * (rampsControllerState) => rampsControllerState,\n * );\n *\n * export const selectUserRegionRequest = createRequestSelector<\n * RootState,\n * string\n * >(selectRampsControllerState, 'updateUserRegion', []);\n *\n * // In hook - use directly with useSelector, no shallowEqual needed\n * export function useRampsUserRegion() {\n * const { isFetching, error } = useSelector(selectUserRegionRequest);\n * // ... rest of hook\n * }\n * ```\n *\n * @example\n * ```ts\n * // For methods with parameters\n * export const selectCryptoCurrenciesRequest = (region: string) =>\n * createRequestSelector<RootState, CryptoCurrency[]>(\n * selectRampsControllerState,\n * 'getCryptoCurrencies',\n * [region],\n * );\n *\n * // In component\n * const { data, isFetching, error } = useSelector(\n * selectCryptoCurrenciesRequest('US')\n * );\n * ```\n */\nexport function createRequestSelector<TRootState, TData>(\n getState: (rootState: TRootState) => RampsControllerState | undefined,\n method: string,\n params: unknown[],\n): (state: TRootState) => RequestSelectorResult<TData> {\n const cacheKey = createCacheKey(method, params);\n\n let lastRequest: RequestState | undefined;\n let lastResult: RequestSelectorResult<TData> | null = null;\n\n return (state: TRootState): RequestSelectorResult<TData> => {\n const request = getState(state)?.requests?.[cacheKey];\n\n if (request === lastRequest && lastResult !== null) {\n return lastResult;\n }\n\n lastRequest = request;\n const nextResult: RequestSelectorResult<TData> = {\n data: (request?.data as TData) ?? null,\n isFetching: request?.status === RequestStatus.LOADING,\n error: request?.error ?? null,\n };\n\n if (request?.errorKey) {\n nextResult.errorKey = request.errorKey;\n }\n\n lastResult = nextResult;\n\n return lastResult;\n };\n}\n"]}
|
package/dist/selectors.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { RampsControllerState } from "./RampsController.cjs";
|
|
2
|
+
import type { RampsErrorCode } from "./rampsErrorCodes.cjs";
|
|
2
3
|
/**
|
|
3
4
|
* Result shape returned by request selectors.
|
|
4
5
|
*
|
|
@@ -13,6 +14,8 @@ export type RequestSelectorResult<TData> = {
|
|
|
13
14
|
isFetching: boolean;
|
|
14
15
|
/** Error message if the request failed, or null if successful or not yet attempted. */
|
|
15
16
|
error: string | null;
|
|
17
|
+
/** Stable error key for client-side localization, if available. */
|
|
18
|
+
errorKey?: RampsErrorCode | null;
|
|
16
19
|
};
|
|
17
20
|
/**
|
|
18
21
|
* Creates a memoized selector for a controller method's request state.
|
package/dist/selectors.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.d.cts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,8BAA0B;
|
|
1
|
+
{"version":3,"file":"selectors.d.cts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,8BAA0B;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA0B;AAIxD;;;;;;GAMG;AACH,MAAM,MAAM,qBAAqB,CAAC,KAAK,IAAI;IACzC,+EAA+E;IAC/E,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;IACnB,oDAAoD;IACpD,UAAU,EAAE,OAAO,CAAC;IACpB,uFAAuF;IACvF,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,mEAAmE;IACnE,QAAQ,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;CAClC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,KAAK,EACrD,QAAQ,EAAE,CAAC,SAAS,EAAE,UAAU,KAAK,oBAAoB,GAAG,SAAS,EACrE,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,OAAO,EAAE,GAChB,CAAC,KAAK,EAAE,UAAU,KAAK,qBAAqB,CAAC,KAAK,CAAC,CA4BrD"}
|
package/dist/selectors.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { RampsControllerState } from "./RampsController.mjs";
|
|
2
|
+
import type { RampsErrorCode } from "./rampsErrorCodes.mjs";
|
|
2
3
|
/**
|
|
3
4
|
* Result shape returned by request selectors.
|
|
4
5
|
*
|
|
@@ -13,6 +14,8 @@ export type RequestSelectorResult<TData> = {
|
|
|
13
14
|
isFetching: boolean;
|
|
14
15
|
/** Error message if the request failed, or null if successful or not yet attempted. */
|
|
15
16
|
error: string | null;
|
|
17
|
+
/** Stable error key for client-side localization, if available. */
|
|
18
|
+
errorKey?: RampsErrorCode | null;
|
|
16
19
|
};
|
|
17
20
|
/**
|
|
18
21
|
* Creates a memoized selector for a controller method's request state.
|
package/dist/selectors.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.d.mts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,8BAA0B;
|
|
1
|
+
{"version":3,"file":"selectors.d.mts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,8BAA0B;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA0B;AAIxD;;;;;;GAMG;AACH,MAAM,MAAM,qBAAqB,CAAC,KAAK,IAAI;IACzC,+EAA+E;IAC/E,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;IACnB,oDAAoD;IACpD,UAAU,EAAE,OAAO,CAAC;IACpB,uFAAuF;IACvF,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,mEAAmE;IACnE,QAAQ,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;CAClC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,KAAK,EACrD,QAAQ,EAAE,CAAC,SAAS,EAAE,UAAU,KAAK,oBAAoB,GAAG,SAAS,EACrE,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,OAAO,EAAE,GAChB,CAAC,KAAK,EAAE,UAAU,KAAK,qBAAqB,CAAC,KAAK,CAAC,CA4BrD"}
|
package/dist/selectors.mjs
CHANGED
|
@@ -66,11 +66,15 @@ export function createRequestSelector(getState, method, params) {
|
|
|
66
66
|
return lastResult;
|
|
67
67
|
}
|
|
68
68
|
lastRequest = request;
|
|
69
|
-
|
|
69
|
+
const nextResult = {
|
|
70
70
|
data: request?.data ?? null,
|
|
71
71
|
isFetching: request?.status === RequestStatus.LOADING,
|
|
72
72
|
error: request?.error ?? null,
|
|
73
73
|
};
|
|
74
|
+
if (request?.errorKey) {
|
|
75
|
+
nextResult.errorKey = request.errorKey;
|
|
76
|
+
}
|
|
77
|
+
lastResult = nextResult;
|
|
74
78
|
return lastResult;
|
|
75
79
|
};
|
|
76
80
|
}
|
package/dist/selectors.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.mjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"selectors.mjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,2BAAuB;AAoB/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAAqE,EACrE,MAAc,EACd,MAAiB;IAEjB,MAAM,QAAQ,GAAG,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEhD,IAAI,WAAqC,CAAC;IAC1C,IAAI,UAAU,GAAwC,IAAI,CAAC;IAE3D,OAAO,CAAC,KAAiB,EAAgC,EAAE;QACzD,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC;QAEtD,IAAI,OAAO,KAAK,WAAW,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;YACnD,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,WAAW,GAAG,OAAO,CAAC;QACtB,MAAM,UAAU,GAAiC;YAC/C,IAAI,EAAG,OAAO,EAAE,IAAc,IAAI,IAAI;YACtC,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,aAAa,CAAC,OAAO;YACrD,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,IAAI;SAC9B,CAAC;QAEF,IAAI,OAAO,EAAE,QAAQ,EAAE,CAAC;YACtB,UAAU,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACzC,CAAC;QAED,UAAU,GAAG,UAAU,CAAC;QAExB,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { RampsControllerState } from './RampsController';\nimport type { RampsErrorCode } from './rampsErrorCodes';\nimport type { RequestState } from './RequestCache';\nimport { RequestStatus, createCacheKey } from './RequestCache';\n\n/**\n * Result shape returned by request selectors.\n *\n * This object is memoized - the same reference is returned when the underlying\n * request state hasn't changed, making it safe to use with React Redux's\n * `useSelector` without `shallowEqual`.\n */\nexport type RequestSelectorResult<TData> = {\n /** The data returned by the request, or null if not yet loaded or on error. */\n data: TData | null;\n /** Whether the request is currently in progress. */\n isFetching: boolean;\n /** Error message if the request failed, or null if successful or not yet attempted. */\n error: string | null;\n /** Stable error key for client-side localization, if available. */\n errorKey?: RampsErrorCode | null;\n};\n\n/**\n * Creates a memoized selector for a controller method's request state.\n *\n * This selector tracks the loading, error, and data state for a specific\n * controller method call. It's optimized for use with React Redux's `useSelector`\n * hook - the selector returns the same object reference when the underlying\n * request state hasn't changed, so no `shallowEqual` is needed.\n *\n * The selector uses reference equality on the request object itself, so it\n * works correctly with arrays and objects without expensive deep equality checks.\n *\n * @param getState - Function that extracts RampsControllerState from the root state.\n * Typically a reselect selector like `selectRampsControllerState`.\n * @param method - The controller method name (e.g., 'updateUserRegion').\n * @param params - The parameters passed to the method, used to generate the cache key.\n * Must match the params used when calling the controller method.\n * @returns A selector function that returns `{ data, isFetching, error }`.\n *\n * @example\n * ```ts\n * // In selectors file - create once at module level\n * import { createRequestSelector } from '@metamask/ramps-controller';\n * import { createSelector } from 'reselect';\n *\n * const selectRampsControllerState = createSelector(\n * (state: RootState) => state.engine.backgroundState.RampsController,\n * (rampsControllerState) => rampsControllerState,\n * );\n *\n * export const selectUserRegionRequest = createRequestSelector<\n * RootState,\n * string\n * >(selectRampsControllerState, 'updateUserRegion', []);\n *\n * // In hook - use directly with useSelector, no shallowEqual needed\n * export function useRampsUserRegion() {\n * const { isFetching, error } = useSelector(selectUserRegionRequest);\n * // ... rest of hook\n * }\n * ```\n *\n * @example\n * ```ts\n * // For methods with parameters\n * export const selectCryptoCurrenciesRequest = (region: string) =>\n * createRequestSelector<RootState, CryptoCurrency[]>(\n * selectRampsControllerState,\n * 'getCryptoCurrencies',\n * [region],\n * );\n *\n * // In component\n * const { data, isFetching, error } = useSelector(\n * selectCryptoCurrenciesRequest('US')\n * );\n * ```\n */\nexport function createRequestSelector<TRootState, TData>(\n getState: (rootState: TRootState) => RampsControllerState | undefined,\n method: string,\n params: unknown[],\n): (state: TRootState) => RequestSelectorResult<TData> {\n const cacheKey = createCacheKey(method, params);\n\n let lastRequest: RequestState | undefined;\n let lastResult: RequestSelectorResult<TData> | null = null;\n\n return (state: TRootState): RequestSelectorResult<TData> => {\n const request = getState(state)?.requests?.[cacheKey];\n\n if (request === lastRequest && lastResult !== null) {\n return lastResult;\n }\n\n lastRequest = request;\n const nextResult: RequestSelectorResult<TData> = {\n data: (request?.data as TData) ?? null,\n isFetching: request?.status === RequestStatus.LOADING,\n error: request?.error ?? null,\n };\n\n if (request?.errorKey) {\n nextResult.errorKey = request.errorKey;\n }\n\n lastResult = nextResult;\n\n return lastResult;\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/ramps-controller",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.3.1",
|
|
4
4
|
"description": "A controller for managing cryptocurrency on/off ramps functionality",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/ramps-controller",
|
|
46
46
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/ramps-controller",
|
|
47
47
|
"dev": "node dev-watch.js",
|
|
48
|
-
"messenger-action-types:check": "tsx ../../packages/messenger-cli/src/cli.ts --check",
|
|
49
|
-
"messenger-action-types:generate": "tsx ../../packages/messenger-cli/src/cli.ts --generate",
|
|
48
|
+
"messenger-action-types:check": "tsx ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --check",
|
|
49
|
+
"messenger-action-types:generate": "tsx ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --generate",
|
|
50
50
|
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
51
51
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
52
52
|
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@metamask/base-controller": "^9.1.0",
|
|
58
|
-
"@metamask/controller-utils": "^
|
|
59
|
-
"@metamask/messenger": "^1.
|
|
58
|
+
"@metamask/controller-utils": "^12.0.0",
|
|
59
|
+
"@metamask/messenger": "^1.2.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@metamask/auto-changelog": "^6.1.0",
|