@metamask/ramps-controller 20.2.0 → 21.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 (223) hide show
  1. package/CHANGELOG.md +30 -1
  2. package/dist/NeoBankService-method-action-types.d.ts +126 -0
  3. package/dist/NeoBankService-method-action-types.d.ts.map +1 -0
  4. package/dist/{TransakService-method-action-types.mjs → NeoBankService-method-action-types.js} +1 -1
  5. package/dist/NeoBankService-method-action-types.js.map +1 -0
  6. package/dist/NeoBankService.d.ts +191 -0
  7. package/dist/NeoBankService.d.ts.map +1 -0
  8. package/dist/NeoBankService.js +380 -0
  9. package/dist/NeoBankService.js.map +1 -0
  10. package/dist/{RampsController-method-action-types.d.mts → RampsController-method-action-types.d.ts} +93 -3
  11. package/dist/RampsController-method-action-types.d.ts.map +1 -0
  12. package/dist/{RampsController-method-action-types.mjs → RampsController-method-action-types.js} +1 -1
  13. package/dist/RampsController-method-action-types.js.map +1 -0
  14. package/dist/{RampsController.d.cts → RampsController.d.ts} +164 -17
  15. package/dist/RampsController.d.ts.map +1 -0
  16. package/dist/{RampsController.mjs → RampsController.js} +1064 -582
  17. package/dist/RampsController.js.map +1 -0
  18. package/dist/{RampsService-method-action-types.d.cts → RampsService-method-action-types.d.ts} +2 -2
  19. package/dist/RampsService-method-action-types.d.ts.map +1 -0
  20. package/dist/{RampsService-method-action-types.mjs → RampsService-method-action-types.js} +1 -1
  21. package/dist/RampsService-method-action-types.js.map +1 -0
  22. package/dist/{RampsService.d.mts → RampsService.d.ts} +5 -5
  23. package/dist/RampsService.d.ts.map +1 -0
  24. package/dist/{RampsService.mjs → RampsService.js} +159 -147
  25. package/dist/RampsService.js.map +1 -0
  26. package/dist/{RequestCache.d.cts → RequestCache.d.ts} +3 -3
  27. package/dist/RequestCache.d.ts.map +1 -0
  28. package/dist/{RequestCache.mjs → RequestCache.js} +1 -1
  29. package/dist/RequestCache.js.map +1 -0
  30. package/dist/{TransakService-method-action-types.d.cts → TransakService-method-action-types.d.ts} +2 -2
  31. package/dist/TransakService-method-action-types.d.ts.map +1 -0
  32. package/dist/TransakService-method-action-types.js +6 -0
  33. package/dist/TransakService-method-action-types.js.map +1 -0
  34. package/dist/{TransakService.d.mts → TransakService.d.ts} +6 -6
  35. package/dist/TransakService.d.ts.map +1 -0
  36. package/dist/TransakService.js +746 -0
  37. package/dist/TransakService.js.map +1 -0
  38. package/dist/autoramp-types.d.ts +22 -0
  39. package/dist/autoramp-types.d.ts.map +1 -0
  40. package/dist/autoramp-types.js +2 -0
  41. package/dist/autoramp-types.js.map +1 -0
  42. package/dist/autorampAccount.d.ts +126 -0
  43. package/dist/autorampAccount.d.ts.map +1 -0
  44. package/dist/autorampAccount.js +147 -0
  45. package/dist/autorampAccount.js.map +1 -0
  46. package/dist/{client-identity.d.cts → client-identity.d.ts} +1 -1
  47. package/dist/client-identity.d.ts.map +1 -0
  48. package/dist/{client-identity.mjs → client-identity.js} +1 -1
  49. package/dist/client-identity.js.map +1 -0
  50. package/dist/{errorNormalization.d.mts → errorNormalization.d.ts} +1 -1
  51. package/dist/errorNormalization.d.ts.map +1 -0
  52. package/dist/{errorNormalization.mjs → errorNormalization.js} +1 -1
  53. package/dist/errorNormalization.js.map +1 -0
  54. package/dist/{featureFlags.d.mts → featureFlags.d.ts} +2 -2
  55. package/dist/featureFlags.d.ts.map +1 -0
  56. package/dist/{featureFlags.mjs → featureFlags.js} +1 -1
  57. package/dist/featureFlags.js.map +1 -0
  58. package/dist/index.d.ts +35 -0
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/index.js +18 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/{orderStatus.d.mts → orderStatus.d.ts} +2 -2
  63. package/dist/orderStatus.d.ts.map +1 -0
  64. package/dist/{orderStatus.mjs → orderStatus.js} +2 -2
  65. package/dist/orderStatus.js.map +1 -0
  66. package/dist/ownership-message.d.ts +22 -0
  67. package/dist/ownership-message.d.ts.map +1 -0
  68. package/dist/ownership-message.js +22 -0
  69. package/dist/ownership-message.js.map +1 -0
  70. package/dist/{paymentMethodMerge.d.cts → paymentMethodMerge.d.ts} +2 -2
  71. package/dist/paymentMethodMerge.d.ts.map +1 -0
  72. package/dist/{paymentMethodMerge.mjs → paymentMethodMerge.js} +1 -1
  73. package/dist/paymentMethodMerge.js.map +1 -0
  74. package/dist/{providerAvailability.d.mts → providerAvailability.d.ts} +2 -2
  75. package/dist/providerAvailability.d.ts.map +1 -0
  76. package/dist/{providerAvailability.mjs → providerAvailability.js} +1 -1
  77. package/dist/providerAvailability.js.map +1 -0
  78. package/dist/{quoteClassification.d.cts → quoteClassification.d.ts} +2 -2
  79. package/dist/quoteClassification.d.ts.map +1 -0
  80. package/dist/{quoteClassification.mjs → quoteClassification.js} +1 -1
  81. package/dist/quoteClassification.js.map +1 -0
  82. package/dist/{rampsErrorCodes.d.cts → rampsErrorCodes.d.ts} +2 -2
  83. package/dist/rampsErrorCodes.d.ts.map +1 -0
  84. package/dist/{rampsErrorCodes.mjs → rampsErrorCodes.js} +1 -1
  85. package/dist/rampsErrorCodes.js.map +1 -0
  86. package/dist/{selectors.d.mts → selectors.d.ts} +3 -3
  87. package/dist/selectors.d.ts.map +1 -0
  88. package/dist/{selectors.mjs → selectors.js} +2 -2
  89. package/dist/selectors.js.map +1 -0
  90. package/dist/{transakApiErrorUtils.d.cts → transakApiErrorUtils.d.ts} +1 -1
  91. package/dist/transakApiErrorUtils.d.ts.map +1 -0
  92. package/dist/{transakApiErrorUtils.mjs → transakApiErrorUtils.js} +3 -3
  93. package/dist/transakApiErrorUtils.js.map +1 -0
  94. package/dist/{transakErrorCodes.d.cts → transakErrorCodes.d.ts} +3 -3
  95. package/dist/transakErrorCodes.d.ts.map +1 -0
  96. package/dist/{transakErrorCodes.mjs → transakErrorCodes.js} +1 -1
  97. package/dist/transakErrorCodes.js.map +1 -0
  98. package/dist/wallet-registration-machine.d.ts +81 -0
  99. package/dist/wallet-registration-machine.d.ts.map +1 -0
  100. package/dist/wallet-registration-machine.js +139 -0
  101. package/dist/wallet-registration-machine.js.map +1 -0
  102. package/dist/wallet-registration-service.d.ts +144 -0
  103. package/dist/wallet-registration-service.d.ts.map +1 -0
  104. package/dist/wallet-registration-service.js +335 -0
  105. package/dist/wallet-registration-service.js.map +1 -0
  106. package/package.json +17 -21
  107. package/dist/RampsController-method-action-types.cjs +0 -7
  108. package/dist/RampsController-method-action-types.cjs.map +0 -1
  109. package/dist/RampsController-method-action-types.d.cts +0 -668
  110. package/dist/RampsController-method-action-types.d.cts.map +0 -1
  111. package/dist/RampsController-method-action-types.d.mts.map +0 -1
  112. package/dist/RampsController-method-action-types.mjs.map +0 -1
  113. package/dist/RampsController.cjs +0 -2429
  114. package/dist/RampsController.cjs.map +0 -1
  115. package/dist/RampsController.d.cts.map +0 -1
  116. package/dist/RampsController.d.mts +0 -821
  117. package/dist/RampsController.d.mts.map +0 -1
  118. package/dist/RampsController.mjs.map +0 -1
  119. package/dist/RampsService-method-action-types.cjs +0 -7
  120. package/dist/RampsService-method-action-types.cjs.map +0 -1
  121. package/dist/RampsService-method-action-types.d.cts.map +0 -1
  122. package/dist/RampsService-method-action-types.d.mts +0 -171
  123. package/dist/RampsService-method-action-types.d.mts.map +0 -1
  124. package/dist/RampsService-method-action-types.mjs.map +0 -1
  125. package/dist/RampsService.cjs +0 -708
  126. package/dist/RampsService.cjs.map +0 -1
  127. package/dist/RampsService.d.cts +0 -944
  128. package/dist/RampsService.d.cts.map +0 -1
  129. package/dist/RampsService.d.mts.map +0 -1
  130. package/dist/RampsService.mjs.map +0 -1
  131. package/dist/RequestCache.cjs +0 -103
  132. package/dist/RequestCache.cjs.map +0 -1
  133. package/dist/RequestCache.d.cts.map +0 -1
  134. package/dist/RequestCache.d.mts +0 -110
  135. package/dist/RequestCache.d.mts.map +0 -1
  136. package/dist/RequestCache.mjs.map +0 -1
  137. package/dist/TransakService-method-action-types.cjs +0 -7
  138. package/dist/TransakService-method-action-types.cjs.map +0 -1
  139. package/dist/TransakService-method-action-types.d.cts.map +0 -1
  140. package/dist/TransakService-method-action-types.d.mts +0 -140
  141. package/dist/TransakService-method-action-types.d.mts.map +0 -1
  142. package/dist/TransakService-method-action-types.mjs.map +0 -1
  143. package/dist/TransakService.cjs +0 -743
  144. package/dist/TransakService.cjs.map +0 -1
  145. package/dist/TransakService.d.cts +0 -370
  146. package/dist/TransakService.d.cts.map +0 -1
  147. package/dist/TransakService.d.mts.map +0 -1
  148. package/dist/TransakService.mjs +0 -734
  149. package/dist/TransakService.mjs.map +0 -1
  150. package/dist/client-identity.cjs +0 -28
  151. package/dist/client-identity.cjs.map +0 -1
  152. package/dist/client-identity.d.cts.map +0 -1
  153. package/dist/client-identity.d.mts +0 -24
  154. package/dist/client-identity.d.mts.map +0 -1
  155. package/dist/client-identity.mjs.map +0 -1
  156. package/dist/errorNormalization.cjs +0 -84
  157. package/dist/errorNormalization.cjs.map +0 -1
  158. package/dist/errorNormalization.d.cts +0 -56
  159. package/dist/errorNormalization.d.cts.map +0 -1
  160. package/dist/errorNormalization.d.mts.map +0 -1
  161. package/dist/errorNormalization.mjs.map +0 -1
  162. package/dist/featureFlags.cjs +0 -144
  163. package/dist/featureFlags.cjs.map +0 -1
  164. package/dist/featureFlags.d.cts +0 -82
  165. package/dist/featureFlags.d.cts.map +0 -1
  166. package/dist/featureFlags.d.mts.map +0 -1
  167. package/dist/featureFlags.mjs.map +0 -1
  168. package/dist/index.cjs +0 -63
  169. package/dist/index.cjs.map +0 -1
  170. package/dist/index.d.cts +0 -26
  171. package/dist/index.d.cts.map +0 -1
  172. package/dist/index.d.mts +0 -26
  173. package/dist/index.d.mts.map +0 -1
  174. package/dist/index.mjs +0 -14
  175. package/dist/index.mjs.map +0 -1
  176. package/dist/orderStatus.cjs +0 -34
  177. package/dist/orderStatus.cjs.map +0 -1
  178. package/dist/orderStatus.d.cts +0 -18
  179. package/dist/orderStatus.d.cts.map +0 -1
  180. package/dist/orderStatus.d.mts.map +0 -1
  181. package/dist/orderStatus.mjs.map +0 -1
  182. package/dist/paymentMethodMerge.cjs +0 -51
  183. package/dist/paymentMethodMerge.cjs.map +0 -1
  184. package/dist/paymentMethodMerge.d.cts.map +0 -1
  185. package/dist/paymentMethodMerge.d.mts +0 -26
  186. package/dist/paymentMethodMerge.d.mts.map +0 -1
  187. package/dist/paymentMethodMerge.mjs.map +0 -1
  188. package/dist/providerAvailability.cjs +0 -134
  189. package/dist/providerAvailability.cjs.map +0 -1
  190. package/dist/providerAvailability.d.cts +0 -101
  191. package/dist/providerAvailability.d.cts.map +0 -1
  192. package/dist/providerAvailability.d.mts.map +0 -1
  193. package/dist/providerAvailability.mjs.map +0 -1
  194. package/dist/quoteClassification.cjs +0 -44
  195. package/dist/quoteClassification.cjs.map +0 -1
  196. package/dist/quoteClassification.d.cts.map +0 -1
  197. package/dist/quoteClassification.d.mts +0 -33
  198. package/dist/quoteClassification.d.mts.map +0 -1
  199. package/dist/quoteClassification.mjs.map +0 -1
  200. package/dist/rampsErrorCodes.cjs +0 -11
  201. package/dist/rampsErrorCodes.cjs.map +0 -1
  202. package/dist/rampsErrorCodes.d.cts.map +0 -1
  203. package/dist/rampsErrorCodes.d.mts +0 -9
  204. package/dist/rampsErrorCodes.d.mts.map +0 -1
  205. package/dist/rampsErrorCodes.mjs.map +0 -1
  206. package/dist/selectors.cjs +0 -85
  207. package/dist/selectors.cjs.map +0 -1
  208. package/dist/selectors.d.cts +0 -78
  209. package/dist/selectors.d.cts.map +0 -1
  210. package/dist/selectors.d.mts.map +0 -1
  211. package/dist/selectors.mjs.map +0 -1
  212. package/dist/transakApiErrorUtils.cjs +0 -15
  213. package/dist/transakApiErrorUtils.cjs.map +0 -1
  214. package/dist/transakApiErrorUtils.d.cts.map +0 -1
  215. package/dist/transakApiErrorUtils.d.mts +0 -3
  216. package/dist/transakApiErrorUtils.d.mts.map +0 -1
  217. package/dist/transakApiErrorUtils.mjs.map +0 -1
  218. package/dist/transakErrorCodes.cjs +0 -14
  219. package/dist/transakErrorCodes.cjs.map +0 -1
  220. package/dist/transakErrorCodes.d.cts.map +0 -1
  221. package/dist/transakErrorCodes.d.mts +0 -12
  222. package/dist/transakErrorCodes.d.mts.map +0 -1
  223. package/dist/transakErrorCodes.mjs.map +0 -1
@@ -1,134 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isFiatDepositAvailable = exports.regionHasProviderForAsset = exports.getProvidersServingAsset = exports.providerServesAsset = exports.normalizeRampsAssetId = void 0;
4
- /**
5
- * Canonicalizes a CAIP-19 asset id for comparison against Ramps API values.
6
- *
7
- * CAIP-19 does not constrain the case of the asset reference, and the Ramps API
8
- * is not consistent about it. Every `eip155` key in `regions/{region}/providers`
9
- * `supportedCryptoCurrencies` is lowercase, while `regions/{region}/topTokens`
10
- * returns four mainnet `assetId` values EIP-55 checksummed (USDT, USDC, WBTC,
11
- * LINK) in both its `topTokens` and `allTokens` lists, with no lowercase
12
- * duplicate. Callers also supply checksummed ids of their own from other
13
- * controllers, so the two sides of a comparison can disagree on case for the
14
- * same asset.
15
- *
16
- * Non-EVM references are case-sensitive (Solana base58, Tron base58, bitcoin
17
- * bech32), so lowercasing is restricted to `eip155` rather than applied to the
18
- * whole string. This is a tightening: for EVM ids a plain `toLowerCase()` on
19
- * both sides already matched. Current API data carries non-EVM ids in identical
20
- * case on both endpoints, so the passthrough guards against future drift rather
21
- * than fixing an observed mismatch.
22
- *
23
- * The namespace itself is matched case-insensitively, so an `EIP155:` prefix
24
- * is treated as EVM even though CAIP-19 defines namespaces as lowercase.
25
- *
26
- * @param assetId - CAIP-19 asset id, in either case form.
27
- * @returns The asset id in the form the Ramps API uses.
28
- */
29
- function normalizeRampsAssetId(assetId) {
30
- const trimmedAssetId = assetId.trim();
31
- return /^eip155:/iu.test(trimmedAssetId)
32
- ? trimmedAssetId.toLowerCase()
33
- : trimmedAssetId;
34
- }
35
- exports.normalizeRampsAssetId = normalizeRampsAssetId;
36
- /**
37
- * Whether a provider serves the given deposit asset.
38
- *
39
- * Mirrors the region-provider matching the controller performs internally: a
40
- * provider serves the asset when its `supportedCryptoCurrencies` map (keyed by
41
- * CAIP-19 asset id) contains the asset id. Both sides are canonicalized with
42
- * {@link normalizeRampsAssetId}, so EVM ids match regardless of checksum
43
- * casing while non-EVM references stay case-sensitive. A provider without a
44
- * `supportedCryptoCurrencies` map is treated as not serving the asset.
45
- *
46
- * @param provider - The provider to test.
47
- * @param assetId - CAIP-19 asset id of the deposit asset.
48
- * @returns Whether the provider serves the asset.
49
- */
50
- function providerServesAsset(provider, assetId) {
51
- const map = provider?.supportedCryptoCurrencies;
52
- if (!map) {
53
- return false;
54
- }
55
- const target = normalizeRampsAssetId(assetId);
56
- return Object.keys(map).some((key) => normalizeRampsAssetId(key) === target && map[key]);
57
- }
58
- exports.providerServesAsset = providerServesAsset;
59
- /**
60
- * Filters a provider list down to those serving the given deposit asset.
61
- *
62
- * @param providers - The providers to filter.
63
- * @param assetId - CAIP-19 asset id of the deposit asset.
64
- * @returns The subset of providers serving the asset.
65
- */
66
- function getProvidersServingAsset(providers, assetId) {
67
- return providers.filter((provider) => providerServesAsset(provider, assetId));
68
- }
69
- exports.getProvidersServingAsset = getProvidersServingAsset;
70
- /**
71
- * Whether a region offers a usable on-ramp provider that serves the given
72
- * deposit asset, under the all-providers feature flag. This is the pure,
73
- * asset-aware region gate shared between the controller and headless-buy
74
- * consumers so the two never disagree about eligibility.
75
- *
76
- * With `allProvidersEnabled` false the gate is native-only: the region must
77
- * offer a native provider (e.g. Transak Native) that serves the asset. With
78
- * `allProvidersEnabled` true the region is supported when any provider
79
- * (native or aggregator) serves the asset; the controller's flag-aware
80
- * `getQuotes` performs the precise provider selection at quote time. Fails
81
- * closed: an empty or missing `assetId` returns `false`.
82
- *
83
- * @param options - The options.
84
- * @param options.providers - The region's providers (native and aggregator).
85
- * @param options.assetId - CAIP-19 asset id of the deposit asset.
86
- * @param options.allProvidersEnabled - Whether the all-providers feature flag
87
- * is enabled (see `isHeadlessAllProvidersEnabled`).
88
- * @returns Whether the region has a provider serving the asset.
89
- */
90
- function regionHasProviderForAsset({ providers, assetId, allProvidersEnabled, }) {
91
- if (!assetId) {
92
- return false;
93
- }
94
- const serving = getProvidersServingAsset(providers, assetId);
95
- if (serving.some((provider) => provider.type === 'native')) {
96
- return true;
97
- }
98
- if (!allProvidersEnabled) {
99
- return false;
100
- }
101
- return serving.length > 0;
102
- }
103
- exports.regionHasProviderForAsset = regionHasProviderForAsset;
104
- /**
105
- * Whether headless fiat deposit is available for the current region, under
106
- * the all-providers feature flag. Flag-aware and independent of which single
107
- * provider is currently selected once widened, so the availability gate
108
- * cannot disagree with the controller's own flag-aware provider pick.
109
- *
110
- * With `allProvidersEnabled` false the check keeps the native-only behaviour:
111
- * a native provider must be the currently selected (preferred) one, since the
112
- * controller resolves the selected provider first and an aggregator preferred
113
- * provider would otherwise run a non-native deposit. With
114
- * `allProvidersEnabled` true the flow is available whenever the region has
115
- * any provider.
116
- *
117
- * @param options - The options.
118
- * @param options.providers - The region's providers.
119
- * @param options.selectedProvider - The currently selected provider, if any.
120
- * @param options.allProvidersEnabled - Whether the all-providers feature flag
121
- * is enabled (see `isHeadlessAllProvidersEnabled`).
122
- * @returns Whether headless fiat deposit is available.
123
- */
124
- function isFiatDepositAvailable({ providers, selectedProvider, allProvidersEnabled, }) {
125
- if (selectedProvider?.type === 'native') {
126
- return true;
127
- }
128
- if (!allProvidersEnabled) {
129
- return false;
130
- }
131
- return providers.length > 0;
132
- }
133
- exports.isFiatDepositAvailable = isFiatDepositAvailable;
134
- //# sourceMappingURL=providerAvailability.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"providerAvailability.cjs","sourceRoot":"","sources":["../src/providerAvailability.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,SAAgB,qBAAqB,CAAC,OAAe;IACnD,MAAM,cAAc,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IACtC,OAAO,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC;QACtC,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE;QAC9B,CAAC,CAAC,cAAc,CAAC;AACrB,CAAC;AALD,sDAKC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,mBAAmB,CACjC,QAAkB,EAClB,OAAe;IAEf,MAAM,GAAG,GAAG,QAAQ,EAAE,yBAAyB,CAAC;IAChD,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,MAAM,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAC9C,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAC1B,CAAC,GAAG,EAAE,EAAE,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,CAC3D,CAAC;AACJ,CAAC;AAZD,kDAYC;AAED;;;;;;GAMG;AACH,SAAgB,wBAAwB,CACtC,SAAqB,EACrB,OAAe;IAEf,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,mBAAmB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;AAChF,CAAC;AALD,4DAKC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,yBAAyB,CAAC,EACxC,SAAS,EACT,OAAO,EACP,mBAAmB,GAKpB;IACC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,OAAO,GAAG,wBAAwB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAC7D,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,QAAQ,CAAC,EAAE,CAAC;QAC3D,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;AAC5B,CAAC;AApBD,8DAoBC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,sBAAsB,CAAC,EACrC,SAAS,EACT,gBAAgB,EAChB,mBAAmB,GAKpB;IACC,IAAI,gBAAgB,EAAE,IAAI,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;AAC9B,CAAC;AAhBD,wDAgBC","sourcesContent":["import type { Provider } from './RampsService.js';\n\n/**\n * Canonicalizes a CAIP-19 asset id for comparison against Ramps API values.\n *\n * CAIP-19 does not constrain the case of the asset reference, and the Ramps API\n * is not consistent about it. Every `eip155` key in `regions/{region}/providers`\n * `supportedCryptoCurrencies` is lowercase, while `regions/{region}/topTokens`\n * returns four mainnet `assetId` values EIP-55 checksummed (USDT, USDC, WBTC,\n * LINK) in both its `topTokens` and `allTokens` lists, with no lowercase\n * duplicate. Callers also supply checksummed ids of their own from other\n * controllers, so the two sides of a comparison can disagree on case for the\n * same asset.\n *\n * Non-EVM references are case-sensitive (Solana base58, Tron base58, bitcoin\n * bech32), so lowercasing is restricted to `eip155` rather than applied to the\n * whole string. This is a tightening: for EVM ids a plain `toLowerCase()` on\n * both sides already matched. Current API data carries non-EVM ids in identical\n * case on both endpoints, so the passthrough guards against future drift rather\n * than fixing an observed mismatch.\n *\n * The namespace itself is matched case-insensitively, so an `EIP155:` prefix\n * is treated as EVM even though CAIP-19 defines namespaces as lowercase.\n *\n * @param assetId - CAIP-19 asset id, in either case form.\n * @returns The asset id in the form the Ramps API uses.\n */\nexport function normalizeRampsAssetId(assetId: string): string {\n const trimmedAssetId = assetId.trim();\n return /^eip155:/iu.test(trimmedAssetId)\n ? trimmedAssetId.toLowerCase()\n : trimmedAssetId;\n}\n\n/**\n * Whether a provider serves the given deposit asset.\n *\n * Mirrors the region-provider matching the controller performs internally: a\n * provider serves the asset when its `supportedCryptoCurrencies` map (keyed by\n * CAIP-19 asset id) contains the asset id. Both sides are canonicalized with\n * {@link normalizeRampsAssetId}, so EVM ids match regardless of checksum\n * casing while non-EVM references stay case-sensitive. A provider without a\n * `supportedCryptoCurrencies` map is treated as not serving the asset.\n *\n * @param provider - The provider to test.\n * @param assetId - CAIP-19 asset id of the deposit asset.\n * @returns Whether the provider serves the asset.\n */\nexport function providerServesAsset(\n provider: Provider,\n assetId: string,\n): boolean {\n const map = provider?.supportedCryptoCurrencies;\n if (!map) {\n return false;\n }\n const target = normalizeRampsAssetId(assetId);\n return Object.keys(map).some(\n (key) => normalizeRampsAssetId(key) === target && map[key],\n );\n}\n\n/**\n * Filters a provider list down to those serving the given deposit asset.\n *\n * @param providers - The providers to filter.\n * @param assetId - CAIP-19 asset id of the deposit asset.\n * @returns The subset of providers serving the asset.\n */\nexport function getProvidersServingAsset(\n providers: Provider[],\n assetId: string,\n): Provider[] {\n return providers.filter((provider) => providerServesAsset(provider, assetId));\n}\n\n/**\n * Whether a region offers a usable on-ramp provider that serves the given\n * deposit asset, under the all-providers feature flag. This is the pure,\n * asset-aware region gate shared between the controller and headless-buy\n * consumers so the two never disagree about eligibility.\n *\n * With `allProvidersEnabled` false the gate is native-only: the region must\n * offer a native provider (e.g. Transak Native) that serves the asset. With\n * `allProvidersEnabled` true the region is supported when any provider\n * (native or aggregator) serves the asset; the controller's flag-aware\n * `getQuotes` performs the precise provider selection at quote time. Fails\n * closed: an empty or missing `assetId` returns `false`.\n *\n * @param options - The options.\n * @param options.providers - The region's providers (native and aggregator).\n * @param options.assetId - CAIP-19 asset id of the deposit asset.\n * @param options.allProvidersEnabled - Whether the all-providers feature flag\n * is enabled (see `isHeadlessAllProvidersEnabled`).\n * @returns Whether the region has a provider serving the asset.\n */\nexport function regionHasProviderForAsset({\n providers,\n assetId,\n allProvidersEnabled,\n}: {\n providers: Provider[];\n assetId: string;\n allProvidersEnabled: boolean;\n}): boolean {\n if (!assetId) {\n return false;\n }\n const serving = getProvidersServingAsset(providers, assetId);\n if (serving.some((provider) => provider.type === 'native')) {\n return true;\n }\n if (!allProvidersEnabled) {\n return false;\n }\n return serving.length > 0;\n}\n\n/**\n * Whether headless fiat deposit is available for the current region, under\n * the all-providers feature flag. Flag-aware and independent of which single\n * provider is currently selected once widened, so the availability gate\n * cannot disagree with the controller's own flag-aware provider pick.\n *\n * With `allProvidersEnabled` false the check keeps the native-only behaviour:\n * a native provider must be the currently selected (preferred) one, since the\n * controller resolves the selected provider first and an aggregator preferred\n * provider would otherwise run a non-native deposit. With\n * `allProvidersEnabled` true the flow is available whenever the region has\n * any provider.\n *\n * @param options - The options.\n * @param options.providers - The region's providers.\n * @param options.selectedProvider - The currently selected provider, if any.\n * @param options.allProvidersEnabled - Whether the all-providers feature flag\n * is enabled (see `isHeadlessAllProvidersEnabled`).\n * @returns Whether headless fiat deposit is available.\n */\nexport function isFiatDepositAvailable({\n providers,\n selectedProvider,\n allProvidersEnabled,\n}: {\n providers: Provider[];\n selectedProvider?: Provider | null;\n allProvidersEnabled: boolean;\n}): boolean {\n if (selectedProvider?.type === 'native') {\n return true;\n }\n if (!allProvidersEnabled) {\n return false;\n }\n return providers.length > 0;\n}\n"]}
@@ -1,101 +0,0 @@
1
- import type { Provider } from "./RampsService.cjs";
2
- /**
3
- * Canonicalizes a CAIP-19 asset id for comparison against Ramps API values.
4
- *
5
- * CAIP-19 does not constrain the case of the asset reference, and the Ramps API
6
- * is not consistent about it. Every `eip155` key in `regions/{region}/providers`
7
- * `supportedCryptoCurrencies` is lowercase, while `regions/{region}/topTokens`
8
- * returns four mainnet `assetId` values EIP-55 checksummed (USDT, USDC, WBTC,
9
- * LINK) in both its `topTokens` and `allTokens` lists, with no lowercase
10
- * duplicate. Callers also supply checksummed ids of their own from other
11
- * controllers, so the two sides of a comparison can disagree on case for the
12
- * same asset.
13
- *
14
- * Non-EVM references are case-sensitive (Solana base58, Tron base58, bitcoin
15
- * bech32), so lowercasing is restricted to `eip155` rather than applied to the
16
- * whole string. This is a tightening: for EVM ids a plain `toLowerCase()` on
17
- * both sides already matched. Current API data carries non-EVM ids in identical
18
- * case on both endpoints, so the passthrough guards against future drift rather
19
- * than fixing an observed mismatch.
20
- *
21
- * The namespace itself is matched case-insensitively, so an `EIP155:` prefix
22
- * is treated as EVM even though CAIP-19 defines namespaces as lowercase.
23
- *
24
- * @param assetId - CAIP-19 asset id, in either case form.
25
- * @returns The asset id in the form the Ramps API uses.
26
- */
27
- export declare function normalizeRampsAssetId(assetId: string): string;
28
- /**
29
- * Whether a provider serves the given deposit asset.
30
- *
31
- * Mirrors the region-provider matching the controller performs internally: a
32
- * provider serves the asset when its `supportedCryptoCurrencies` map (keyed by
33
- * CAIP-19 asset id) contains the asset id. Both sides are canonicalized with
34
- * {@link normalizeRampsAssetId}, so EVM ids match regardless of checksum
35
- * casing while non-EVM references stay case-sensitive. A provider without a
36
- * `supportedCryptoCurrencies` map is treated as not serving the asset.
37
- *
38
- * @param provider - The provider to test.
39
- * @param assetId - CAIP-19 asset id of the deposit asset.
40
- * @returns Whether the provider serves the asset.
41
- */
42
- export declare function providerServesAsset(provider: Provider, assetId: string): boolean;
43
- /**
44
- * Filters a provider list down to those serving the given deposit asset.
45
- *
46
- * @param providers - The providers to filter.
47
- * @param assetId - CAIP-19 asset id of the deposit asset.
48
- * @returns The subset of providers serving the asset.
49
- */
50
- export declare function getProvidersServingAsset(providers: Provider[], assetId: string): Provider[];
51
- /**
52
- * Whether a region offers a usable on-ramp provider that serves the given
53
- * deposit asset, under the all-providers feature flag. This is the pure,
54
- * asset-aware region gate shared between the controller and headless-buy
55
- * consumers so the two never disagree about eligibility.
56
- *
57
- * With `allProvidersEnabled` false the gate is native-only: the region must
58
- * offer a native provider (e.g. Transak Native) that serves the asset. With
59
- * `allProvidersEnabled` true the region is supported when any provider
60
- * (native or aggregator) serves the asset; the controller's flag-aware
61
- * `getQuotes` performs the precise provider selection at quote time. Fails
62
- * closed: an empty or missing `assetId` returns `false`.
63
- *
64
- * @param options - The options.
65
- * @param options.providers - The region's providers (native and aggregator).
66
- * @param options.assetId - CAIP-19 asset id of the deposit asset.
67
- * @param options.allProvidersEnabled - Whether the all-providers feature flag
68
- * is enabled (see `isHeadlessAllProvidersEnabled`).
69
- * @returns Whether the region has a provider serving the asset.
70
- */
71
- export declare function regionHasProviderForAsset({ providers, assetId, allProvidersEnabled, }: {
72
- providers: Provider[];
73
- assetId: string;
74
- allProvidersEnabled: boolean;
75
- }): boolean;
76
- /**
77
- * Whether headless fiat deposit is available for the current region, under
78
- * the all-providers feature flag. Flag-aware and independent of which single
79
- * provider is currently selected once widened, so the availability gate
80
- * cannot disagree with the controller's own flag-aware provider pick.
81
- *
82
- * With `allProvidersEnabled` false the check keeps the native-only behaviour:
83
- * a native provider must be the currently selected (preferred) one, since the
84
- * controller resolves the selected provider first and an aggregator preferred
85
- * provider would otherwise run a non-native deposit. With
86
- * `allProvidersEnabled` true the flow is available whenever the region has
87
- * any provider.
88
- *
89
- * @param options - The options.
90
- * @param options.providers - The region's providers.
91
- * @param options.selectedProvider - The currently selected provider, if any.
92
- * @param options.allProvidersEnabled - Whether the all-providers feature flag
93
- * is enabled (see `isHeadlessAllProvidersEnabled`).
94
- * @returns Whether headless fiat deposit is available.
95
- */
96
- export declare function isFiatDepositAvailable({ providers, selectedProvider, allProvidersEnabled, }: {
97
- providers: Provider[];
98
- selectedProvider?: Provider | null;
99
- allProvidersEnabled: boolean;
100
- }): boolean;
101
- //# sourceMappingURL=providerAvailability.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"providerAvailability.d.cts","sourceRoot":"","sources":["../src/providerAvailability.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,2BAA0B;AAElD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAK7D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,MAAM,GACd,OAAO,CAST;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,QAAQ,EAAE,EACrB,OAAO,EAAE,MAAM,GACd,QAAQ,EAAE,CAEZ;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,yBAAyB,CAAC,EACxC,SAAS,EACT,OAAO,EACP,mBAAmB,GACpB,EAAE;IACD,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB,EAAE,OAAO,CAAC;CAC9B,GAAG,OAAO,CAYV;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,SAAS,EACT,gBAAgB,EAChB,mBAAmB,GACpB,EAAE;IACD,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,gBAAgB,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IACnC,mBAAmB,EAAE,OAAO,CAAC;CAC9B,GAAG,OAAO,CAQV"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"providerAvailability.d.mts","sourceRoot":"","sources":["../src/providerAvailability.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,2BAA0B;AAElD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAK7D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,MAAM,GACd,OAAO,CAST;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,QAAQ,EAAE,EACrB,OAAO,EAAE,MAAM,GACd,QAAQ,EAAE,CAEZ;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,yBAAyB,CAAC,EACxC,SAAS,EACT,OAAO,EACP,mBAAmB,GACpB,EAAE;IACD,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB,EAAE,OAAO,CAAC;CAC9B,GAAG,OAAO,CAYV;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,SAAS,EACT,gBAAgB,EAChB,mBAAmB,GACpB,EAAE;IACD,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,gBAAgB,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IACnC,mBAAmB,EAAE,OAAO,CAAC;CAC9B,GAAG,OAAO,CAQV"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"providerAvailability.mjs","sourceRoot":"","sources":["../src/providerAvailability.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAe;IACnD,MAAM,cAAc,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IACtC,OAAO,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC;QACtC,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE;QAC9B,CAAC,CAAC,cAAc,CAAC;AACrB,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,mBAAmB,CACjC,QAAkB,EAClB,OAAe;IAEf,MAAM,GAAG,GAAG,QAAQ,EAAE,yBAAyB,CAAC;IAChD,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,MAAM,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAC9C,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAC1B,CAAC,GAAG,EAAE,EAAE,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,CAC3D,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACtC,SAAqB,EACrB,OAAe;IAEf,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,mBAAmB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;AAChF,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,yBAAyB,CAAC,EACxC,SAAS,EACT,OAAO,EACP,mBAAmB,GAKpB;IACC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,OAAO,GAAG,wBAAwB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAC7D,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,QAAQ,CAAC,EAAE,CAAC;QAC3D,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,sBAAsB,CAAC,EACrC,SAAS,EACT,gBAAgB,EAChB,mBAAmB,GAKpB;IACC,IAAI,gBAAgB,EAAE,IAAI,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import type { Provider } from './RampsService.js';\n\n/**\n * Canonicalizes a CAIP-19 asset id for comparison against Ramps API values.\n *\n * CAIP-19 does not constrain the case of the asset reference, and the Ramps API\n * is not consistent about it. Every `eip155` key in `regions/{region}/providers`\n * `supportedCryptoCurrencies` is lowercase, while `regions/{region}/topTokens`\n * returns four mainnet `assetId` values EIP-55 checksummed (USDT, USDC, WBTC,\n * LINK) in both its `topTokens` and `allTokens` lists, with no lowercase\n * duplicate. Callers also supply checksummed ids of their own from other\n * controllers, so the two sides of a comparison can disagree on case for the\n * same asset.\n *\n * Non-EVM references are case-sensitive (Solana base58, Tron base58, bitcoin\n * bech32), so lowercasing is restricted to `eip155` rather than applied to the\n * whole string. This is a tightening: for EVM ids a plain `toLowerCase()` on\n * both sides already matched. Current API data carries non-EVM ids in identical\n * case on both endpoints, so the passthrough guards against future drift rather\n * than fixing an observed mismatch.\n *\n * The namespace itself is matched case-insensitively, so an `EIP155:` prefix\n * is treated as EVM even though CAIP-19 defines namespaces as lowercase.\n *\n * @param assetId - CAIP-19 asset id, in either case form.\n * @returns The asset id in the form the Ramps API uses.\n */\nexport function normalizeRampsAssetId(assetId: string): string {\n const trimmedAssetId = assetId.trim();\n return /^eip155:/iu.test(trimmedAssetId)\n ? trimmedAssetId.toLowerCase()\n : trimmedAssetId;\n}\n\n/**\n * Whether a provider serves the given deposit asset.\n *\n * Mirrors the region-provider matching the controller performs internally: a\n * provider serves the asset when its `supportedCryptoCurrencies` map (keyed by\n * CAIP-19 asset id) contains the asset id. Both sides are canonicalized with\n * {@link normalizeRampsAssetId}, so EVM ids match regardless of checksum\n * casing while non-EVM references stay case-sensitive. A provider without a\n * `supportedCryptoCurrencies` map is treated as not serving the asset.\n *\n * @param provider - The provider to test.\n * @param assetId - CAIP-19 asset id of the deposit asset.\n * @returns Whether the provider serves the asset.\n */\nexport function providerServesAsset(\n provider: Provider,\n assetId: string,\n): boolean {\n const map = provider?.supportedCryptoCurrencies;\n if (!map) {\n return false;\n }\n const target = normalizeRampsAssetId(assetId);\n return Object.keys(map).some(\n (key) => normalizeRampsAssetId(key) === target && map[key],\n );\n}\n\n/**\n * Filters a provider list down to those serving the given deposit asset.\n *\n * @param providers - The providers to filter.\n * @param assetId - CAIP-19 asset id of the deposit asset.\n * @returns The subset of providers serving the asset.\n */\nexport function getProvidersServingAsset(\n providers: Provider[],\n assetId: string,\n): Provider[] {\n return providers.filter((provider) => providerServesAsset(provider, assetId));\n}\n\n/**\n * Whether a region offers a usable on-ramp provider that serves the given\n * deposit asset, under the all-providers feature flag. This is the pure,\n * asset-aware region gate shared between the controller and headless-buy\n * consumers so the two never disagree about eligibility.\n *\n * With `allProvidersEnabled` false the gate is native-only: the region must\n * offer a native provider (e.g. Transak Native) that serves the asset. With\n * `allProvidersEnabled` true the region is supported when any provider\n * (native or aggregator) serves the asset; the controller's flag-aware\n * `getQuotes` performs the precise provider selection at quote time. Fails\n * closed: an empty or missing `assetId` returns `false`.\n *\n * @param options - The options.\n * @param options.providers - The region's providers (native and aggregator).\n * @param options.assetId - CAIP-19 asset id of the deposit asset.\n * @param options.allProvidersEnabled - Whether the all-providers feature flag\n * is enabled (see `isHeadlessAllProvidersEnabled`).\n * @returns Whether the region has a provider serving the asset.\n */\nexport function regionHasProviderForAsset({\n providers,\n assetId,\n allProvidersEnabled,\n}: {\n providers: Provider[];\n assetId: string;\n allProvidersEnabled: boolean;\n}): boolean {\n if (!assetId) {\n return false;\n }\n const serving = getProvidersServingAsset(providers, assetId);\n if (serving.some((provider) => provider.type === 'native')) {\n return true;\n }\n if (!allProvidersEnabled) {\n return false;\n }\n return serving.length > 0;\n}\n\n/**\n * Whether headless fiat deposit is available for the current region, under\n * the all-providers feature flag. Flag-aware and independent of which single\n * provider is currently selected once widened, so the availability gate\n * cannot disagree with the controller's own flag-aware provider pick.\n *\n * With `allProvidersEnabled` false the check keeps the native-only behaviour:\n * a native provider must be the currently selected (preferred) one, since the\n * controller resolves the selected provider first and an aggregator preferred\n * provider would otherwise run a non-native deposit. With\n * `allProvidersEnabled` true the flow is available whenever the region has\n * any provider.\n *\n * @param options - The options.\n * @param options.providers - The region's providers.\n * @param options.selectedProvider - The currently selected provider, if any.\n * @param options.allProvidersEnabled - Whether the all-providers feature flag\n * is enabled (see `isHeadlessAllProvidersEnabled`).\n * @returns Whether headless fiat deposit is available.\n */\nexport function isFiatDepositAvailable({\n providers,\n selectedProvider,\n allProvidersEnabled,\n}: {\n providers: Provider[];\n selectedProvider?: Provider | null;\n allProvidersEnabled: boolean;\n}): boolean {\n if (selectedProvider?.type === 'native') {\n return true;\n }\n if (!allProvidersEnabled) {\n return false;\n }\n return providers.length > 0;\n}\n"]}
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isInAppOnlyQuote = exports.isCustomActionQuote = exports.isExternalBrowserQuote = void 0;
4
- /**
5
- * Whether a quote's checkout runs in an external / system browser rather than
6
- * an in-app WebView. Decided by the per-quote `buyWidget.browser` hint from the
7
- * quotes API. When the hint is absent the quote is treated as in-app (the
8
- * caller is responsible for the in-app WebView fail-safe).
9
- *
10
- * This is the pure classification only: it deliberately knows nothing about
11
- * host redirect URLs or deeplink schemes, which stay in the consuming client.
12
- *
13
- * @param quote - The quote to classify.
14
- * @returns Whether the quote uses an external browser.
15
- */
16
- function isExternalBrowserQuote(quote) {
17
- return quote.quote?.buyWidget?.browser === 'IN_APP_OS_BROWSER';
18
- }
19
- exports.isExternalBrowserQuote = isExternalBrowserQuote;
20
- /**
21
- * Whether a quote is a custom-action ("checkout outside of MetaMask") quote,
22
- * e.g. PayPal or Robinhood. Reads the inline `isCustomAction` flag, which the
23
- * wire may carry even though it is absent from the published `Quote` type.
24
- *
25
- * @param quote - The quote to classify.
26
- * @returns Whether the quote is a custom-action quote.
27
- */
28
- function isCustomActionQuote(quote) {
29
- return quote.quote?.isCustomAction === true;
30
- }
31
- exports.isCustomActionQuote = isCustomActionQuote;
32
- /**
33
- * Whether a quote continues inside an in-app WebView, i.e. it is neither a
34
- * custom-action quote nor an external-browser quote. This is the Phase 1
35
- * in-app-only inclusion test.
36
- *
37
- * @param quote - The quote to classify.
38
- * @returns Whether the quote is an in-app WebView quote.
39
- */
40
- function isInAppOnlyQuote(quote) {
41
- return !isCustomActionQuote(quote) && !isExternalBrowserQuote(quote);
42
- }
43
- exports.isInAppOnlyQuote = isInAppOnlyQuote;
44
- //# sourceMappingURL=quoteClassification.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"quoteClassification.cjs","sourceRoot":"","sources":["../src/quoteClassification.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;GAWG;AACH,SAAgB,sBAAsB,CAAC,KAAY;IACjD,OAAO,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,KAAK,mBAAmB,CAAC;AACjE,CAAC;AAFD,wDAEC;AAED;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CAAC,KAAY;IAC9C,OAAQ,KAAK,CAAC,KAAsC,EAAE,cAAc,KAAK,IAAI,CAAC;AAChF,CAAC;AAFD,kDAEC;AAED;;;;;;;GAOG;AACH,SAAgB,gBAAgB,CAAC,KAAY;IAC3C,OAAO,CAAC,mBAAmB,CAAC,KAAK,CAAC,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC;AACvE,CAAC;AAFD,4CAEC","sourcesContent":["import type { Quote } from './RampsService.js';\n\n/**\n * Whether a quote's checkout runs in an external / system browser rather than\n * an in-app WebView. Decided by the per-quote `buyWidget.browser` hint from the\n * quotes API. When the hint is absent the quote is treated as in-app (the\n * caller is responsible for the in-app WebView fail-safe).\n *\n * This is the pure classification only: it deliberately knows nothing about\n * host redirect URLs or deeplink schemes, which stay in the consuming client.\n *\n * @param quote - The quote to classify.\n * @returns Whether the quote uses an external browser.\n */\nexport function isExternalBrowserQuote(quote: Quote): boolean {\n return quote.quote?.buyWidget?.browser === 'IN_APP_OS_BROWSER';\n}\n\n/**\n * Whether a quote is a custom-action (\"checkout outside of MetaMask\") quote,\n * e.g. PayPal or Robinhood. Reads the inline `isCustomAction` flag, which the\n * wire may carry even though it is absent from the published `Quote` type.\n *\n * @param quote - The quote to classify.\n * @returns Whether the quote is a custom-action quote.\n */\nexport function isCustomActionQuote(quote: Quote): boolean {\n return (quote.quote as { isCustomAction?: boolean })?.isCustomAction === true;\n}\n\n/**\n * Whether a quote continues inside an in-app WebView, i.e. it is neither a\n * custom-action quote nor an external-browser quote. This is the Phase 1\n * in-app-only inclusion test.\n *\n * @param quote - The quote to classify.\n * @returns Whether the quote is an in-app WebView quote.\n */\nexport function isInAppOnlyQuote(quote: Quote): boolean {\n return !isCustomActionQuote(quote) && !isExternalBrowserQuote(quote);\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"quoteClassification.d.cts","sourceRoot":"","sources":["../src/quoteClassification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,2BAA0B;AAE/C;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAE5D;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAEzD;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAEtD"}
@@ -1,33 +0,0 @@
1
- import type { Quote } from "./RampsService.mjs";
2
- /**
3
- * Whether a quote's checkout runs in an external / system browser rather than
4
- * an in-app WebView. Decided by the per-quote `buyWidget.browser` hint from the
5
- * quotes API. When the hint is absent the quote is treated as in-app (the
6
- * caller is responsible for the in-app WebView fail-safe).
7
- *
8
- * This is the pure classification only: it deliberately knows nothing about
9
- * host redirect URLs or deeplink schemes, which stay in the consuming client.
10
- *
11
- * @param quote - The quote to classify.
12
- * @returns Whether the quote uses an external browser.
13
- */
14
- export declare function isExternalBrowserQuote(quote: Quote): boolean;
15
- /**
16
- * Whether a quote is a custom-action ("checkout outside of MetaMask") quote,
17
- * e.g. PayPal or Robinhood. Reads the inline `isCustomAction` flag, which the
18
- * wire may carry even though it is absent from the published `Quote` type.
19
- *
20
- * @param quote - The quote to classify.
21
- * @returns Whether the quote is a custom-action quote.
22
- */
23
- export declare function isCustomActionQuote(quote: Quote): boolean;
24
- /**
25
- * Whether a quote continues inside an in-app WebView, i.e. it is neither a
26
- * custom-action quote nor an external-browser quote. This is the Phase 1
27
- * in-app-only inclusion test.
28
- *
29
- * @param quote - The quote to classify.
30
- * @returns Whether the quote is an in-app WebView quote.
31
- */
32
- export declare function isInAppOnlyQuote(quote: Quote): boolean;
33
- //# sourceMappingURL=quoteClassification.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"quoteClassification.d.mts","sourceRoot":"","sources":["../src/quoteClassification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,2BAA0B;AAE/C;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAE5D;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAEzD;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAEtD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"quoteClassification.mjs","sourceRoot":"","sources":["../src/quoteClassification.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAY;IACjD,OAAO,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,KAAK,mBAAmB,CAAC;AACjE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAY;IAC9C,OAAQ,KAAK,CAAC,KAAsC,EAAE,cAAc,KAAK,IAAI,CAAC;AAChF,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAY;IAC3C,OAAO,CAAC,mBAAmB,CAAC,KAAK,CAAC,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC;AACvE,CAAC","sourcesContent":["import type { Quote } from './RampsService.js';\n\n/**\n * Whether a quote's checkout runs in an external / system browser rather than\n * an in-app WebView. Decided by the per-quote `buyWidget.browser` hint from the\n * quotes API. When the hint is absent the quote is treated as in-app (the\n * caller is responsible for the in-app WebView fail-safe).\n *\n * This is the pure classification only: it deliberately knows nothing about\n * host redirect URLs or deeplink schemes, which stay in the consuming client.\n *\n * @param quote - The quote to classify.\n * @returns Whether the quote uses an external browser.\n */\nexport function isExternalBrowserQuote(quote: Quote): boolean {\n return quote.quote?.buyWidget?.browser === 'IN_APP_OS_BROWSER';\n}\n\n/**\n * Whether a quote is a custom-action (\"checkout outside of MetaMask\") quote,\n * e.g. PayPal or Robinhood. Reads the inline `isCustomAction` flag, which the\n * wire may carry even though it is absent from the published `Quote` type.\n *\n * @param quote - The quote to classify.\n * @returns Whether the quote is a custom-action quote.\n */\nexport function isCustomActionQuote(quote: Quote): boolean {\n return (quote.quote as { isCustomAction?: boolean })?.isCustomAction === true;\n}\n\n/**\n * Whether a quote continues inside an in-app WebView, i.e. it is neither a\n * custom-action quote nor an external-browser quote. This is the Phase 1\n * in-app-only inclusion test.\n *\n * @param quote - The quote to classify.\n * @returns Whether the quote is an in-app WebView quote.\n */\nexport function isInAppOnlyQuote(quote: Quote): boolean {\n return !isCustomActionQuote(quote) && !isExternalBrowserQuote(quote);\n}\n"]}
@@ -1,11 +0,0 @@
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
@@ -1 +0,0 @@
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"]}
@@ -1 +0,0 @@
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"}
@@ -1,9 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1 +0,0 @@
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"]}
@@ -1,85 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createRequestSelector = void 0;
4
- const RequestCache_js_1 = require("./RequestCache.cjs");
5
- /**
6
- * Creates a memoized selector for a controller method's request state.
7
- *
8
- * This selector tracks the loading, error, and data state for a specific
9
- * controller method call. It's optimized for use with React Redux's `useSelector`
10
- * hook - the selector returns the same object reference when the underlying
11
- * request state hasn't changed, so no `shallowEqual` is needed.
12
- *
13
- * The selector uses reference equality on the request object itself, so it
14
- * works correctly with arrays and objects without expensive deep equality checks.
15
- *
16
- * @param getState - Function that extracts RampsControllerState from the root state.
17
- * Typically a reselect selector like `selectRampsControllerState`.
18
- * @param method - The controller method name (e.g., 'updateUserRegion').
19
- * @param params - The parameters passed to the method, used to generate the cache key.
20
- * Must match the params used when calling the controller method.
21
- * @returns A selector function that returns `{ data, isFetching, error }`.
22
- *
23
- * @example
24
- * ```ts
25
- * // In selectors file - create once at module level
26
- * import { createRequestSelector } from '@metamask/ramps-controller';
27
- * import { createSelector } from 'reselect';
28
- *
29
- * const selectRampsControllerState = createSelector(
30
- * (state: RootState) => state.engine.backgroundState.RampsController,
31
- * (rampsControllerState) => rampsControllerState,
32
- * );
33
- *
34
- * export const selectUserRegionRequest = createRequestSelector<
35
- * RootState,
36
- * string
37
- * >(selectRampsControllerState, 'updateUserRegion', []);
38
- *
39
- * // In hook - use directly with useSelector, no shallowEqual needed
40
- * export function useRampsUserRegion() {
41
- * const { isFetching, error } = useSelector(selectUserRegionRequest);
42
- * // ... rest of hook
43
- * }
44
- * ```
45
- *
46
- * @example
47
- * ```ts
48
- * // For methods with parameters
49
- * export const selectCryptoCurrenciesRequest = (region: string) =>
50
- * createRequestSelector<RootState, CryptoCurrency[]>(
51
- * selectRampsControllerState,
52
- * 'getCryptoCurrencies',
53
- * [region],
54
- * );
55
- *
56
- * // In component
57
- * const { data, isFetching, error } = useSelector(
58
- * selectCryptoCurrenciesRequest('US')
59
- * );
60
- * ```
61
- */
62
- function createRequestSelector(getState, method, params) {
63
- const cacheKey = (0, RequestCache_js_1.createCacheKey)(method, params);
64
- let lastRequest;
65
- let lastResult = null;
66
- return (state) => {
67
- const request = getState(state)?.requests?.[cacheKey];
68
- if (request === lastRequest && lastResult !== null) {
69
- return lastResult;
70
- }
71
- lastRequest = request;
72
- const nextResult = {
73
- data: request?.data ?? null,
74
- isFetching: request?.status === RequestCache_js_1.RequestStatus.LOADING,
75
- error: request?.error ?? null,
76
- };
77
- if (request?.errorKey) {
78
- nextResult.errorKey = request.errorKey;
79
- }
80
- lastResult = nextResult;
81
- return lastResult;
82
- };
83
- }
84
- exports.createRequestSelector = createRequestSelector;
85
- //# sourceMappingURL=selectors.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"selectors.cjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":";;;AAGA,wDAAkE;AAoBlE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,SAAgB,qBAAqB,CACnC,QAAqE,EACrE,MAAc,EACd,MAAiB;IAEjB,MAAM,QAAQ,GAAG,IAAA,gCAAc,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,+BAAa,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.js';\nimport type { RampsErrorCode } from './rampsErrorCodes.js';\nimport type { RequestState } from './RequestCache.js';\nimport { RequestStatus, createCacheKey } from './RequestCache.js';\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"]}
@@ -1,78 +0,0 @@
1
- import type { RampsControllerState } from "./RampsController.cjs";
2
- import type { RampsErrorCode } from "./rampsErrorCodes.cjs";
3
- /**
4
- * Result shape returned by request selectors.
5
- *
6
- * This object is memoized - the same reference is returned when the underlying
7
- * request state hasn't changed, making it safe to use with React Redux's
8
- * `useSelector` without `shallowEqual`.
9
- */
10
- export type RequestSelectorResult<TData> = {
11
- /** The data returned by the request, or null if not yet loaded or on error. */
12
- data: TData | null;
13
- /** Whether the request is currently in progress. */
14
- isFetching: boolean;
15
- /** Error message if the request failed, or null if successful or not yet attempted. */
16
- error: string | null;
17
- /** Stable error key for client-side localization, if available. */
18
- errorKey?: RampsErrorCode | null;
19
- };
20
- /**
21
- * Creates a memoized selector for a controller method's request state.
22
- *
23
- * This selector tracks the loading, error, and data state for a specific
24
- * controller method call. It's optimized for use with React Redux's `useSelector`
25
- * hook - the selector returns the same object reference when the underlying
26
- * request state hasn't changed, so no `shallowEqual` is needed.
27
- *
28
- * The selector uses reference equality on the request object itself, so it
29
- * works correctly with arrays and objects without expensive deep equality checks.
30
- *
31
- * @param getState - Function that extracts RampsControllerState from the root state.
32
- * Typically a reselect selector like `selectRampsControllerState`.
33
- * @param method - The controller method name (e.g., 'updateUserRegion').
34
- * @param params - The parameters passed to the method, used to generate the cache key.
35
- * Must match the params used when calling the controller method.
36
- * @returns A selector function that returns `{ data, isFetching, error }`.
37
- *
38
- * @example
39
- * ```ts
40
- * // In selectors file - create once at module level
41
- * import { createRequestSelector } from '@metamask/ramps-controller';
42
- * import { createSelector } from 'reselect';
43
- *
44
- * const selectRampsControllerState = createSelector(
45
- * (state: RootState) => state.engine.backgroundState.RampsController,
46
- * (rampsControllerState) => rampsControllerState,
47
- * );
48
- *
49
- * export const selectUserRegionRequest = createRequestSelector<
50
- * RootState,
51
- * string
52
- * >(selectRampsControllerState, 'updateUserRegion', []);
53
- *
54
- * // In hook - use directly with useSelector, no shallowEqual needed
55
- * export function useRampsUserRegion() {
56
- * const { isFetching, error } = useSelector(selectUserRegionRequest);
57
- * // ... rest of hook
58
- * }
59
- * ```
60
- *
61
- * @example
62
- * ```ts
63
- * // For methods with parameters
64
- * export const selectCryptoCurrenciesRequest = (region: string) =>
65
- * createRequestSelector<RootState, CryptoCurrency[]>(
66
- * selectRampsControllerState,
67
- * 'getCryptoCurrencies',
68
- * [region],
69
- * );
70
- *
71
- * // In component
72
- * const { data, isFetching, error } = useSelector(
73
- * selectCryptoCurrenciesRequest('US')
74
- * );
75
- * ```
76
- */
77
- export declare function createRequestSelector<TRootState, TData>(getState: (rootState: TRootState) => RampsControllerState | undefined, method: string, params: unknown[]): (state: TRootState) => RequestSelectorResult<TData>;
78
- //# sourceMappingURL=selectors.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"selectors.d.cts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,8BAA6B;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA6B;AAI3D;;;;;;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"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"selectors.d.mts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,8BAA6B;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA6B;AAI3D;;;;;;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"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"selectors.mjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,2BAA0B;AAoBlE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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.js';\nimport type { RampsErrorCode } from './rampsErrorCodes.js';\nimport type { RequestState } from './RequestCache.js';\nimport { RequestStatus, createCacheKey } from './RequestCache.js';\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"]}