@metamask-previews/ramps-controller 20.2.0-preview-e0510042f → 20.2.0-preview-fe4b3be11

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 (108) hide show
  1. package/CHANGELOG.md +3 -4
  2. package/dist/NeoBankService-method-action-types.cjs +7 -0
  3. package/dist/NeoBankService-method-action-types.cjs.map +1 -0
  4. package/dist/NeoBankService-method-action-types.d.cts +126 -0
  5. package/dist/NeoBankService-method-action-types.d.cts.map +1 -0
  6. package/dist/NeoBankService-method-action-types.d.mts +126 -0
  7. package/dist/NeoBankService-method-action-types.d.mts.map +1 -0
  8. package/dist/NeoBankService-method-action-types.mjs +6 -0
  9. package/dist/NeoBankService-method-action-types.mjs.map +1 -0
  10. package/dist/NeoBankService.cjs +387 -0
  11. package/dist/NeoBankService.cjs.map +1 -0
  12. package/dist/NeoBankService.d.cts +191 -0
  13. package/dist/NeoBankService.d.cts.map +1 -0
  14. package/dist/NeoBankService.d.mts +191 -0
  15. package/dist/NeoBankService.d.mts.map +1 -0
  16. package/dist/NeoBankService.mjs +379 -0
  17. package/dist/NeoBankService.mjs.map +1 -0
  18. package/dist/RampsController-method-action-types.cjs.map +1 -1
  19. package/dist/RampsController-method-action-types.d.cts +91 -8
  20. package/dist/RampsController-method-action-types.d.cts.map +1 -1
  21. package/dist/RampsController-method-action-types.d.mts +91 -8
  22. package/dist/RampsController-method-action-types.d.mts.map +1 -1
  23. package/dist/RampsController-method-action-types.mjs.map +1 -1
  24. package/dist/RampsController.cjs +375 -20
  25. package/dist/RampsController.cjs.map +1 -1
  26. package/dist/RampsController.d.cts +153 -14
  27. package/dist/RampsController.d.cts.map +1 -1
  28. package/dist/RampsController.d.mts +153 -14
  29. package/dist/RampsController.d.mts.map +1 -1
  30. package/dist/RampsController.mjs +374 -19
  31. package/dist/RampsController.mjs.map +1 -1
  32. package/dist/RampsService-method-action-types.cjs.map +1 -1
  33. package/dist/RampsService-method-action-types.d.cts +0 -1
  34. package/dist/RampsService-method-action-types.d.cts.map +1 -1
  35. package/dist/RampsService-method-action-types.d.mts +0 -1
  36. package/dist/RampsService-method-action-types.d.mts.map +1 -1
  37. package/dist/RampsService-method-action-types.mjs.map +1 -1
  38. package/dist/RampsService.cjs +0 -4
  39. package/dist/RampsService.cjs.map +1 -1
  40. package/dist/RampsService.d.cts +0 -23
  41. package/dist/RampsService.d.cts.map +1 -1
  42. package/dist/RampsService.d.mts +0 -23
  43. package/dist/RampsService.d.mts.map +1 -1
  44. package/dist/RampsService.mjs +0 -4
  45. package/dist/RampsService.mjs.map +1 -1
  46. package/dist/TransakService-method-action-types.cjs.map +1 -1
  47. package/dist/TransakService-method-action-types.d.cts +2 -10
  48. package/dist/TransakService-method-action-types.d.cts.map +1 -1
  49. package/dist/TransakService-method-action-types.d.mts +2 -10
  50. package/dist/TransakService-method-action-types.d.mts.map +1 -1
  51. package/dist/TransakService-method-action-types.mjs.map +1 -1
  52. package/dist/TransakService.cjs +5 -45
  53. package/dist/TransakService.cjs.map +1 -1
  54. package/dist/TransakService.d.cts +3 -15
  55. package/dist/TransakService.d.cts.map +1 -1
  56. package/dist/TransakService.d.mts +3 -15
  57. package/dist/TransakService.d.mts.map +1 -1
  58. package/dist/TransakService.mjs +5 -45
  59. package/dist/TransakService.mjs.map +1 -1
  60. package/dist/autoramp-types.cjs +3 -0
  61. package/dist/autoramp-types.cjs.map +1 -0
  62. package/dist/autoramp-types.d.cts +22 -0
  63. package/dist/autoramp-types.d.cts.map +1 -0
  64. package/dist/autoramp-types.d.mts +22 -0
  65. package/dist/autoramp-types.d.mts.map +1 -0
  66. package/dist/autoramp-types.mjs +2 -0
  67. package/dist/autoramp-types.mjs.map +1 -0
  68. package/dist/autorampAccount.cjs +155 -0
  69. package/dist/autorampAccount.cjs.map +1 -0
  70. package/dist/autorampAccount.d.cts +126 -0
  71. package/dist/autorampAccount.d.cts.map +1 -0
  72. package/dist/autorampAccount.d.mts +126 -0
  73. package/dist/autorampAccount.d.mts.map +1 -0
  74. package/dist/autorampAccount.mjs +147 -0
  75. package/dist/autorampAccount.mjs.map +1 -0
  76. package/dist/index.cjs +20 -1
  77. package/dist/index.cjs.map +1 -1
  78. package/dist/index.d.cts +13 -4
  79. package/dist/index.d.cts.map +1 -1
  80. package/dist/index.d.mts +13 -4
  81. package/dist/index.d.mts.map +1 -1
  82. package/dist/index.mjs +5 -1
  83. package/dist/index.mjs.map +1 -1
  84. package/dist/ownership-message.cjs +26 -0
  85. package/dist/ownership-message.cjs.map +1 -0
  86. package/dist/ownership-message.d.cts +22 -0
  87. package/dist/ownership-message.d.cts.map +1 -0
  88. package/dist/ownership-message.d.mts +22 -0
  89. package/dist/ownership-message.d.mts.map +1 -0
  90. package/dist/ownership-message.mjs +22 -0
  91. package/dist/ownership-message.mjs.map +1 -0
  92. package/dist/wallet-registration-machine.cjs +144 -0
  93. package/dist/wallet-registration-machine.cjs.map +1 -0
  94. package/dist/wallet-registration-machine.d.cts +81 -0
  95. package/dist/wallet-registration-machine.d.cts.map +1 -0
  96. package/dist/wallet-registration-machine.d.mts +81 -0
  97. package/dist/wallet-registration-machine.d.mts.map +1 -0
  98. package/dist/wallet-registration-machine.mjs +139 -0
  99. package/dist/wallet-registration-machine.mjs.map +1 -0
  100. package/dist/wallet-registration-service.cjs +351 -0
  101. package/dist/wallet-registration-service.cjs.map +1 -0
  102. package/dist/wallet-registration-service.d.cts +144 -0
  103. package/dist/wallet-registration-service.d.cts.map +1 -0
  104. package/dist/wallet-registration-service.d.mts +144 -0
  105. package/dist/wallet-registration-service.d.mts.map +1 -0
  106. package/dist/wallet-registration-service.mjs +344 -0
  107. package/dist/wallet-registration-service.mjs.map +1 -0
  108. package/package.json +1 -1
@@ -10,18 +10,22 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
11
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
12
  };
13
- var _RampsController_instances, _RampsController_requestCacheTTL, _RampsController_requestCacheMaxSize, _RampsController_pendingRequests, _RampsController_pendingResourceCount, _RampsController_pendingResourceGeneration, _RampsController_orderPollingMeta, _RampsController_orderPollingTimer, _RampsController_isPolling, _RampsController_initPromise, _RampsController_clearPendingResourceCountForDependentResources, _RampsController_abortDependentRequests, _RampsController_resolveAllProvidersFlag, _RampsController_mutateRequests, _RampsController_removeRequestState, _RampsController_cleanupState, _RampsController_requireRegion, _RampsController_isRegionCurrent, _RampsController_isTokenCurrent, _RampsController_isProviderCurrent, _RampsController_updateResourceField, _RampsController_setResourceLoading, _RampsController_setResourceError, _RampsController_updateRequestState, _RampsController_runInit, _RampsController_syncUserRegionFromCountriesCatalog, _RampsController_pickWidenedQuote, _RampsController_getSupportingProvidersForRegion, _RampsController_filterProviderIdsBySupport, _RampsController_resolveProviderIdsForQuote, _RampsController_resolveProviderIdsForPaymentMethods, _RampsController_getPreferredProviderIdsFromOrders, _RampsController_refreshOrder, _RampsController_pollPendingOrders, _RampsController_syncTransakAuthOnError, _RampsController_getNormalizedTransakError;
13
+ var _RampsController_instances, _RampsController_requestCacheTTL, _RampsController_requestCacheMaxSize, _RampsController_pendingRequests, _RampsController_pendingResourceCount, _RampsController_pendingResourceGeneration, _RampsController_orderPollingMeta, _RampsController_orderPollingTimer, _RampsController_isPolling, _RampsController_initPromise, _RampsController_clearPendingResourceCountForDependentResources, _RampsController_abortDependentRequests, _RampsController_resolveAllProvidersFlag, _RampsController_mutateRequests, _RampsController_removeRequestState, _RampsController_cleanupState, _RampsController_requireRegion, _RampsController_isRegionCurrent, _RampsController_isTokenCurrent, _RampsController_isProviderCurrent, _RampsController_updateResourceField, _RampsController_setResourceLoading, _RampsController_setResourceError, _RampsController_updateRequestState, _RampsController_runInit, _RampsController_syncUserRegionFromCountriesCatalog, _RampsController_pickWidenedQuote, _RampsController_getSupportingProvidersForRegion, _RampsController_filterProviderIdsBySupport, _RampsController_resolveProviderIdsForQuote, _RampsController_resolveProviderIdsForPaymentMethods, _RampsController_getPreferredProviderIdsFromOrders, _RampsController_applyAutorampRemoteSnapshot, _RampsController_refreshOrder, _RampsController_pollPendingOrders, _RampsController_syncTransakAuthOnError, _RampsController_getNormalizedTransakError;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.RampsController = exports.getInternalOrderCode = exports.getDefaultRampsControllerState = exports.RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS = exports.controllerName = void 0;
15
+ exports.RampsController = exports.getInternalOrderCode = exports.getDefaultRampsControllerState = exports.RAMPS_CONTROLLER_REQUIRED_CONTROLLER_ACTIONS = exports.RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS = exports.controllerName = void 0;
16
16
  const base_controller_1 = require("@metamask/base-controller");
17
17
  const controller_utils_1 = require("@metamask/controller-utils");
18
+ const autorampAccount_js_1 = require("./autorampAccount.cjs");
18
19
  const featureFlags_js_1 = require("./featureFlags.cjs");
19
20
  const orderStatus_js_1 = require("./orderStatus.cjs");
21
+ const ownership_message_js_1 = require("./ownership-message.cjs");
20
22
  const paymentMethodMerge_js_1 = require("./paymentMethodMerge.cjs");
21
23
  const providerAvailability_js_1 = require("./providerAvailability.cjs");
22
24
  const rampsErrorCodes_js_1 = require("./rampsErrorCodes.cjs");
23
25
  const RampsService_js_1 = require("./RampsService.cjs");
24
26
  const RequestCache_js_1 = require("./RequestCache.cjs");
27
+ const wallet_registration_machine_js_1 = require("./wallet-registration-machine.cjs");
28
+ const wallet_registration_service_js_1 = require("./wallet-registration-service.cjs");
25
29
  // === GENERAL ===
26
30
  /**
27
31
  * The name of the {@link RampsController}, used to namespace the
@@ -70,7 +74,36 @@ exports.RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS = [
70
74
  'TransakService:cancelOrder',
71
75
  'TransakService:cancelAllActiveOrders',
72
76
  'TransakService:getActiveOrders',
77
+ 'NeoBankService:getAutoramp',
78
+ 'NeoBankService:createAutoramp',
79
+ 'NeoBankService:getCustomerByExternalId',
80
+ 'NeoBankService:getWalletRegistrationStatus',
81
+ 'NeoBankService:registerSelfHostedWallet',
73
82
  ];
83
+ /**
84
+ * Every external controller action RampsController calls via the messenger,
85
+ * which hosts must delegate from the root messenger.
86
+ * `AuthenticationController:getSessionProfile` resolves the vendor customer
87
+ * identity from Profile Sync, and `KeyringController:signPersonalMessage` signs
88
+ * the EIP-191 ownership proof for Money Account self-hosted wallet
89
+ * registration; both are only exercised by the autoramp paths.
90
+ */
91
+ exports.RAMPS_CONTROLLER_REQUIRED_CONTROLLER_ACTIONS = [
92
+ 'AuthenticationController:getSessionProfile',
93
+ 'KeyringController:signPersonalMessage',
94
+ 'RemoteFeatureFlagController:getState',
95
+ ];
96
+ /**
97
+ * Distinguishes an already-materialized {@link AutorampAccount} from the
98
+ * create-fields shape accepted by {@link RampsController.addAutoramp}.
99
+ *
100
+ * @param value - Full account or create fields.
101
+ * @returns Whether the value already carries the derived account fields.
102
+ */
103
+ function isFullAutorampAccount(value) {
104
+ return (typeof value.updatedAt === 'number' &&
105
+ value.lastSeenStatus !== undefined);
106
+ }
74
107
  /**
75
108
  * Default TTL for quotes requests (15 seconds).
76
109
  * Quotes are time-sensitive and should have a shorter cache duration.
@@ -182,6 +215,12 @@ const rampsControllerMetadata = {
182
215
  includeInStateLogs: true,
183
216
  usedInUi: true,
184
217
  },
218
+ autoramps: {
219
+ persist: true,
220
+ includeInDebugSnapshot: true,
221
+ includeInStateLogs: true,
222
+ usedInUi: true,
223
+ },
185
224
  providerAutoSelected: {
186
225
  persist: true,
187
226
  includeInDebugSnapshot: true,
@@ -231,6 +270,7 @@ function getDefaultRampsControllerState() {
231
270
  },
232
271
  },
233
272
  orders: [],
273
+ autoramps: [],
234
274
  providerAutoSelected: false,
235
275
  };
236
276
  }
@@ -378,6 +418,14 @@ const MESSENGER_EXPOSED_METHODS = [
378
418
  'getQuotes',
379
419
  'addOrder',
380
420
  'removeOrder',
421
+ 'addAutoramp',
422
+ 'createAutoramp',
423
+ 'removeAutoramp',
424
+ 'registerMoneyAccountWallet',
425
+ 'markAutorampAsNotified',
426
+ 'applyAutorampStatusFromPush',
427
+ 'refreshAutoramp',
428
+ 'refreshAutoramps',
381
429
  'startOrderPolling',
382
430
  'stopOrderPolling',
383
431
  'getBuyWidgetData',
@@ -1179,12 +1227,6 @@ class RampsController extends base_controller_1.BaseController {
1179
1227
  * @param options.action - The ramp action type. Defaults to 'buy'.
1180
1228
  * @param options.forceRefresh - Whether to bypass cache.
1181
1229
  * @param options.ttl - Custom TTL for this request.
1182
- * @param options.isFeeExcludedFromFiat - When true, requests quotes whose
1183
- * fees are charged on top of `amount` rather than taken out of it, so
1184
- * `amountOut` is what `amount` buys before fees. The ramps API honours it
1185
- * only when the request names exactly one provider, because a fee-on-top
1186
- * `amountOut` cannot be ranked against fee-inclusive ones. Defaults to the
1187
- * existing fee-inclusive behaviour.
1188
1230
  * @returns The quotes response containing success, sorted, error, and customActions.
1189
1231
  */
1190
1232
  async getQuotes(options) {
@@ -1215,12 +1257,7 @@ class RampsController extends base_controller_1.BaseController {
1215
1257
  const { enabled: allProvidersEnabled, allowlist: providerAllowlist } = wantsAutoSelection
1216
1258
  ? __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_resolveAllProvidersFlag).call(this)
1217
1259
  : { enabled: false, allowlist: undefined };
1218
- // Fee-on-top quotes cannot be ranked against fee-inclusive quotes because
1219
- // their amountOut values have different meanings. Keep this request on the
1220
- // single-provider resolver even when all-provider widening is enabled.
1221
- const widenToAllProviders = wantsAutoSelection &&
1222
- allProvidersEnabled &&
1223
- options.isFeeExcludedFromFiat !== true;
1260
+ const widenToAllProviders = wantsAutoSelection && allProvidersEnabled;
1224
1261
  let providersToUse;
1225
1262
  let widenedProviderCatalog = this.state.providers.data;
1226
1263
  if (options.providers) {
@@ -1296,7 +1333,6 @@ class RampsController extends base_controller_1.BaseController {
1296
1333
  (widenToAllProviders
1297
1334
  ? this.messenger.call('RampsService:getDefaultRedirectCallbackUrl')
1298
1335
  : undefined);
1299
- const isFeeExcludedFromFiat = options.isFeeExcludedFromFiat === true;
1300
1336
  const cacheKey = (0, RequestCache_js_1.createCacheKey)('getQuotes', [
1301
1337
  normalizedRegion,
1302
1338
  normalizedFiat,
@@ -1307,7 +1343,6 @@ class RampsController extends base_controller_1.BaseController {
1307
1343
  [...providersToUse].sort().join(','),
1308
1344
  effectiveRedirectUrl,
1309
1345
  action,
1310
- isFeeExcludedFromFiat,
1311
1346
  ]);
1312
1347
  const params = {
1313
1348
  region: normalizedRegion,
@@ -1319,7 +1354,6 @@ class RampsController extends base_controller_1.BaseController {
1319
1354
  providers: providersToUse,
1320
1355
  redirectUrl: effectiveRedirectUrl,
1321
1356
  action,
1322
- isFeeExcludedFromFiat,
1323
1357
  };
1324
1358
  const response = await this.executeRequest(cacheKey, async () => {
1325
1359
  return this.messenger.call('RampsService:getQuotes', params);
@@ -1397,6 +1431,304 @@ class RampsController extends base_controller_1.BaseController {
1397
1431
  });
1398
1432
  __classPrivateFieldGet(this, _RampsController_orderPollingMeta, "f").delete(providerOrderId);
1399
1433
  }
1434
+ /**
1435
+ * Adds or updates a local autoramp last-seen cursor (e.g. after create).
1436
+ *
1437
+ * @param accountOrInput - Full account or create fields.
1438
+ * @returns The upserted {@link AutorampAccount}.
1439
+ */
1440
+ addAutoramp(accountOrInput) {
1441
+ const account = isFullAutorampAccount(accountOrInput)
1442
+ ? accountOrInput
1443
+ : (0, autorampAccount_js_1.createAutorampAccount)(accountOrInput);
1444
+ this.update((state) => {
1445
+ const idx = state.autoramps.findIndex((existing) => existing.id === account.id);
1446
+ if (idx === -1) {
1447
+ state.autoramps.push(account);
1448
+ }
1449
+ else {
1450
+ state.autoramps[idx] = {
1451
+ ...state.autoramps[idx],
1452
+ ...account,
1453
+ };
1454
+ }
1455
+ });
1456
+ return (this.state.autoramps.find((existing) => existing.id === account.id) ??
1457
+ account);
1458
+ }
1459
+ /**
1460
+ * Creates an autoramp via the neo-bank proxy and applies the returned
1461
+ * snapshot as the local last-seen cursor.
1462
+ *
1463
+ * The vendor `customer_id` is resolved via
1464
+ * {@link RampsController.resolveAutorampCustomerId} and injected into the
1465
+ * request (any caller-supplied `customer_id` is overwritten).
1466
+ *
1467
+ * @param request - CreateAutoramp payload.
1468
+ * @param options - Optional idempotency key forwarded to the proxy.
1469
+ * @param options.idempotencyKey - Value sent as `Idempotency-Key`.
1470
+ * @returns The created/updated local {@link AutorampAccount}.
1471
+ */
1472
+ async createAutoramp(request, options = {}) {
1473
+ const customerId = await this.resolveAutorampCustomerId();
1474
+ const body = { ...request, customer_id: customerId };
1475
+ const remote = await this.messenger.call('NeoBankService:createAutoramp', body, options);
1476
+ return __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_applyAutorampRemoteSnapshot).call(this, remote);
1477
+ }
1478
+ /**
1479
+ * Resolves the vendor `customer_id` for autoramp / Money Account operations.
1480
+ *
1481
+ * Maps the wallet's Profile Sync id (the partner `external_id`) to the
1482
+ * vendor customer via `GET /neobank/customers/{external_id}/external`.
1483
+ *
1484
+ * @returns The vendor customer id.
1485
+ */
1486
+ async resolveAutorampCustomerId() {
1487
+ const profile = await this.messenger.call('AuthenticationController:getSessionProfile');
1488
+ const canonical = profile?.canonicalProfileId;
1489
+ const externalId = typeof canonical === 'string' && canonical.length > 0
1490
+ ? canonical
1491
+ : profile?.profileId;
1492
+ if (typeof externalId !== 'string' || externalId.length === 0) {
1493
+ throw new Error('Cannot resolve MoonPay customer id: wallet is not signed in to Profile Sync.');
1494
+ }
1495
+ const customer = await this.messenger.call('NeoBankService:getCustomerByExternalId', externalId);
1496
+ const customerId = customer &&
1497
+ typeof customer === 'object' &&
1498
+ typeof customer.id === 'string'
1499
+ ? customer.id
1500
+ : null;
1501
+ if (!customerId) {
1502
+ throw new Error(`Cannot resolve MoonPay customer id: no MoonPay customer is mapped to external id "${externalId}".`);
1503
+ }
1504
+ return customerId;
1505
+ }
1506
+ /**
1507
+ * Registers a Money Account wallet with MoonPay Iron via neobank-proxy.
1508
+ *
1509
+ * @param params - Money Account wallet registration parameters.
1510
+ * @param params.address - Monad Money Account address.
1511
+ * @returns The registration state, or `{ type: 'lookupUnavailable' }` when
1512
+ * the address-list lookup fails (never treated as unregistered).
1513
+ */
1514
+ async registerMoneyAccountWallet({ address, }) {
1515
+ let machine = (0, wallet_registration_machine_js_1.transition)((0, wallet_registration_machine_js_1.createInitialState)(), { type: 'START' });
1516
+ const toExistingResult = (status) => {
1517
+ if (status.type === 'active') {
1518
+ return { type: 'alreadyRegistered', registration: status.registration };
1519
+ }
1520
+ if (status.type === 'disabled') {
1521
+ return {
1522
+ type: 'registeredDisabled',
1523
+ registration: status.registration,
1524
+ };
1525
+ }
1526
+ return undefined;
1527
+ };
1528
+ const customerId = await this.resolveAutorampCustomerId();
1529
+ const toLookupUnavailableResult = (error) => {
1530
+ machine = (0, wallet_registration_machine_js_1.transition)(machine, {
1531
+ type: 'LOOKUP_FAILED',
1532
+ });
1533
+ return {
1534
+ type: 'lookupUnavailable',
1535
+ error: error instanceof wallet_registration_service_js_1.WalletRegistrationError
1536
+ ? error
1537
+ : new wallet_registration_service_js_1.WalletRegistrationError('lookupUnavailable', {
1538
+ message: 'self-hosted address lookup failed',
1539
+ body: error instanceof Error ? error.message : undefined,
1540
+ }),
1541
+ };
1542
+ };
1543
+ const lookup = async () => {
1544
+ try {
1545
+ return await this.messenger.call('NeoBankService:getWalletRegistrationStatus', { customerId, address });
1546
+ }
1547
+ catch (error) {
1548
+ return toLookupUnavailableResult(error);
1549
+ }
1550
+ };
1551
+ const applyLookup = (status) => {
1552
+ let eventType = 'LOOKUP_ABSENT';
1553
+ if (status.type === 'active') {
1554
+ eventType = 'LOOKUP_ACTIVE';
1555
+ }
1556
+ else if (status.type === 'disabled') {
1557
+ eventType = 'LOOKUP_DISABLED';
1558
+ }
1559
+ machine = (0, wallet_registration_machine_js_1.transition)(machine, {
1560
+ type: eventType,
1561
+ });
1562
+ return toExistingResult(status);
1563
+ };
1564
+ const resolveLookup = async () => {
1565
+ const status = await lookup();
1566
+ if (status.type === 'lookupUnavailable') {
1567
+ return status;
1568
+ }
1569
+ return applyLookup(status);
1570
+ };
1571
+ const existingResult = await resolveLookup();
1572
+ if (existingResult) {
1573
+ return existingResult;
1574
+ }
1575
+ let idempotencyKey = (0, wallet_registration_service_js_1.createIdempotencyKey)();
1576
+ let lastMessage;
1577
+ while (true) {
1578
+ const message = (0, ownership_message_js_1.buildOwnershipMessage)({
1579
+ address,
1580
+ customerId,
1581
+ now: new Date(),
1582
+ });
1583
+ if (lastMessage !== undefined && message !== lastMessage) {
1584
+ idempotencyKey = (0, wallet_registration_service_js_1.createIdempotencyKey)();
1585
+ }
1586
+ lastMessage = message;
1587
+ let signature;
1588
+ try {
1589
+ signature = await this.messenger.call('KeyringController:signPersonalMessage', { data: message, from: address });
1590
+ machine = (0, wallet_registration_machine_js_1.transition)(machine, { type: 'SIGN_OK' });
1591
+ }
1592
+ catch (error) {
1593
+ machine = (0, wallet_registration_machine_js_1.transition)(machine, {
1594
+ type: 'SIGN_FAILED',
1595
+ retryable: false,
1596
+ });
1597
+ throw error;
1598
+ }
1599
+ try {
1600
+ const result = await this.messenger.call('NeoBankService:registerSelfHostedWallet', {
1601
+ address,
1602
+ customerId,
1603
+ message,
1604
+ signature,
1605
+ idempotencyKey,
1606
+ });
1607
+ machine = (0, wallet_registration_machine_js_1.transition)(machine, { type: 'SUBMIT_OK' });
1608
+ return result;
1609
+ }
1610
+ catch (error) {
1611
+ if (!(error instanceof wallet_registration_service_js_1.WalletRegistrationError)) {
1612
+ machine = (0, wallet_registration_machine_js_1.transition)(machine, {
1613
+ type: 'SUBMIT_TERMINAL',
1614
+ });
1615
+ throw error;
1616
+ }
1617
+ if (error.kind === 'conflict') {
1618
+ machine = (0, wallet_registration_machine_js_1.transition)(machine, {
1619
+ type: 'SUBMIT_CONFLICT',
1620
+ });
1621
+ }
1622
+ else if (error.kind === 'transient') {
1623
+ machine = (0, wallet_registration_machine_js_1.transition)(machine, {
1624
+ type: 'SUBMIT_TRANSIENT',
1625
+ });
1626
+ }
1627
+ else if (error.kind === 'validation') {
1628
+ machine = (0, wallet_registration_machine_js_1.transition)(machine, {
1629
+ type: 'SUBMIT_VALIDATION',
1630
+ utcRollover: (0, ownership_message_js_1.buildOwnershipMessage)({
1631
+ address,
1632
+ customerId,
1633
+ now: new Date(),
1634
+ }) !== message,
1635
+ });
1636
+ }
1637
+ else if (error.kind === 'rateLimited') {
1638
+ machine = (0, wallet_registration_machine_js_1.transition)(machine, {
1639
+ type: 'SUBMIT_RATE_LIMITED',
1640
+ });
1641
+ }
1642
+ else {
1643
+ machine = (0, wallet_registration_machine_js_1.transition)(machine, {
1644
+ type: 'SUBMIT_TERMINAL',
1645
+ });
1646
+ }
1647
+ if (machine.status === 'disambiguate409' ||
1648
+ machine.status === 'checkThenRetry') {
1649
+ const reconciledResult = await resolveLookup();
1650
+ if (reconciledResult) {
1651
+ return reconciledResult;
1652
+ }
1653
+ }
1654
+ if (machine.status !== 'signing') {
1655
+ throw error;
1656
+ }
1657
+ }
1658
+ }
1659
+ }
1660
+ /**
1661
+ * Removes a local autoramp last-seen cursor by id.
1662
+ *
1663
+ * @param autorampId - MoonPay autoramp id.
1664
+ */
1665
+ removeAutoramp(autorampId) {
1666
+ this.update((state) => {
1667
+ state.autoramps = state.autoramps.filter((autoramp) => autoramp.id !== autorampId);
1668
+ });
1669
+ }
1670
+ /**
1671
+ * Marks that the UI has already notified for the autoramp's current status.
1672
+ *
1673
+ * @param autorampId - MoonPay autoramp id.
1674
+ */
1675
+ markAutorampAsNotified(autorampId) {
1676
+ const existing = this.state.autoramps.find((autoramp) => autoramp.id === autorampId);
1677
+ if (!existing) {
1678
+ return;
1679
+ }
1680
+ const notified = (0, autorampAccount_js_1.markAutorampNotified)(existing);
1681
+ this.update((state) => {
1682
+ const idx = state.autoramps.findIndex((autoramp) => autoramp.id === autorampId);
1683
+ if (idx !== -1) {
1684
+ state.autoramps[idx] = notified;
1685
+ }
1686
+ });
1687
+ }
1688
+ /**
1689
+ * Applies a remote autoramp snapshot from a websocket / webhook push.
1690
+ *
1691
+ * @param remote - Remote autoramp snapshot.
1692
+ * @returns The updated local account.
1693
+ */
1694
+ applyAutorampStatusFromPush(remote) {
1695
+ return __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_applyAutorampRemoteSnapshot).call(this, remote);
1696
+ }
1697
+ /**
1698
+ * Fetches one autoramp from the neo-bank proxy and applies it to the
1699
+ * last-seen cursor. Does not recreate a cursor that was removed while the
1700
+ * request was in flight.
1701
+ *
1702
+ * @param autorampId - MoonPay autoramp id.
1703
+ * @returns The updated local account, or an unpersisted snapshot if the
1704
+ * cursor was removed during the fetch.
1705
+ */
1706
+ async refreshAutoramp(autorampId) {
1707
+ const remote = await this.messenger.call('NeoBankService:getAutoramp', autorampId);
1708
+ return __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_applyAutorampRemoteSnapshot).call(this, remote, { allowInsert: false });
1709
+ }
1710
+ /**
1711
+ * Refreshes all known local autoramps from MoonPay.
1712
+ * Intended for app resume / unlock catch-up when webhooks were missed.
1713
+ *
1714
+ * @returns Updated autoramp accounts (failed fetches are skipped).
1715
+ */
1716
+ async refreshAutoramps() {
1717
+ const ids = this.state.autoramps.map((autoramp) => autoramp.id);
1718
+ const updated = [];
1719
+ for (const id of ids) {
1720
+ try {
1721
+ const account = await this.refreshAutoramp(id);
1722
+ if (this.state.autoramps.some((autoramp) => autoramp.id === account.id)) {
1723
+ updated.push(account);
1724
+ }
1725
+ }
1726
+ catch {
1727
+ // Keep local cursor for this id; continue remaining refreshes.
1728
+ }
1729
+ }
1730
+ return updated;
1731
+ }
1400
1732
  /**
1401
1733
  * Starts polling all pending V2 orders at a fixed interval.
1402
1734
  * Each poll cycle iterates orders with non-terminal statuses,
@@ -1686,17 +2018,16 @@ class RampsController extends base_controller_1.BaseController {
1686
2018
  * @param network - The blockchain network identifier.
1687
2019
  * @param paymentMethod - The payment method identifier.
1688
2020
  * @param fiatAmount - The fiat amount as a string.
1689
- * @param isFeeExcludedFromFiat - Whether Transak charges fees on top.
1690
2021
  * @returns The buy quote with pricing and fee details.
1691
2022
  */
1692
- async transakGetBuyQuote(fiatCurrency, cryptoCurrency, network, paymentMethod, fiatAmount, isFeeExcludedFromFiat = false) {
2023
+ async transakGetBuyQuote(fiatCurrency, cryptoCurrency, network, paymentMethod, fiatAmount) {
1693
2024
  this.update((state) => {
1694
2025
  state.nativeProviders.transak.buyQuote.isLoading = true;
1695
2026
  state.nativeProviders.transak.buyQuote.error = null;
1696
2027
  delete state.nativeProviders.transak.buyQuote.errorKey;
1697
2028
  });
1698
2029
  try {
1699
- const quote = await this.messenger.call('TransakService:getBuyQuote', fiatCurrency, cryptoCurrency, network, paymentMethod, fiatAmount, isFeeExcludedFromFiat);
2030
+ const quote = await this.messenger.call('TransakService:getBuyQuote', fiatCurrency, cryptoCurrency, network, paymentMethod, fiatAmount);
1700
2031
  this.update((state) => {
1701
2032
  state.nativeProviders.transak.buyQuote.data = quote;
1702
2033
  state.nativeProviders.transak.buyQuote.isLoading = false;
@@ -2357,6 +2688,30 @@ async function _RampsController_resolveProviderIdsForPaymentMethods({ assetId, r
2357
2688
  }
2358
2689
  }
2359
2690
  return orderedIds;
2691
+ }, _RampsController_applyAutorampRemoteSnapshot = function _RampsController_applyAutorampRemoteSnapshot(remote, { allowInsert = true } = {}) {
2692
+ const local = this.state.autoramps.find((autoramp) => autoramp.id === remote.id) ??
2693
+ null;
2694
+ if (local === null && !allowInsert) {
2695
+ return (0, autorampAccount_js_1.applyAutorampRemoteStatus)(null, remote).account;
2696
+ }
2697
+ const result = (0, autorampAccount_js_1.applyAutorampRemoteStatus)(local, remote);
2698
+ this.update((state) => {
2699
+ const idx = state.autoramps.findIndex((autoramp) => autoramp.id === result.account.id);
2700
+ if (idx === -1) {
2701
+ state.autoramps.push(result.account);
2702
+ }
2703
+ else {
2704
+ state.autoramps[idx] = result.account;
2705
+ }
2706
+ });
2707
+ if (result.statusChanged) {
2708
+ this.messenger.publish('RampsController:autorampStatusChanged', {
2709
+ autoramp: result.account,
2710
+ previousStatus: result.previousStatus,
2711
+ shouldNotify: result.shouldNotify,
2712
+ });
2713
+ }
2714
+ return (this.state.autoramps.find((autoramp) => autoramp.id === result.account.id) ?? result.account);
2360
2715
  }, _RampsController_refreshOrder =
2361
2716
  /**
2362
2717
  * Refreshes a single order via the V2 API and updates it in state.