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

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 +4 -3
  2. package/dist/RampsController-method-action-types.cjs.map +1 -1
  3. package/dist/RampsController-method-action-types.d.cts +8 -91
  4. package/dist/RampsController-method-action-types.d.cts.map +1 -1
  5. package/dist/RampsController-method-action-types.d.mts +8 -91
  6. package/dist/RampsController-method-action-types.d.mts.map +1 -1
  7. package/dist/RampsController-method-action-types.mjs.map +1 -1
  8. package/dist/RampsController.cjs +20 -375
  9. package/dist/RampsController.cjs.map +1 -1
  10. package/dist/RampsController.d.cts +14 -153
  11. package/dist/RampsController.d.cts.map +1 -1
  12. package/dist/RampsController.d.mts +14 -153
  13. package/dist/RampsController.d.mts.map +1 -1
  14. package/dist/RampsController.mjs +19 -374
  15. package/dist/RampsController.mjs.map +1 -1
  16. package/dist/RampsService-method-action-types.cjs.map +1 -1
  17. package/dist/RampsService-method-action-types.d.cts +1 -0
  18. package/dist/RampsService-method-action-types.d.cts.map +1 -1
  19. package/dist/RampsService-method-action-types.d.mts +1 -0
  20. package/dist/RampsService-method-action-types.d.mts.map +1 -1
  21. package/dist/RampsService-method-action-types.mjs.map +1 -1
  22. package/dist/RampsService.cjs +4 -0
  23. package/dist/RampsService.cjs.map +1 -1
  24. package/dist/RampsService.d.cts +23 -0
  25. package/dist/RampsService.d.cts.map +1 -1
  26. package/dist/RampsService.d.mts +23 -0
  27. package/dist/RampsService.d.mts.map +1 -1
  28. package/dist/RampsService.mjs +4 -0
  29. package/dist/RampsService.mjs.map +1 -1
  30. package/dist/TransakService-method-action-types.cjs.map +1 -1
  31. package/dist/TransakService-method-action-types.d.cts +10 -2
  32. package/dist/TransakService-method-action-types.d.cts.map +1 -1
  33. package/dist/TransakService-method-action-types.d.mts +10 -2
  34. package/dist/TransakService-method-action-types.d.mts.map +1 -1
  35. package/dist/TransakService-method-action-types.mjs.map +1 -1
  36. package/dist/TransakService.cjs +45 -5
  37. package/dist/TransakService.cjs.map +1 -1
  38. package/dist/TransakService.d.cts +15 -3
  39. package/dist/TransakService.d.cts.map +1 -1
  40. package/dist/TransakService.d.mts +15 -3
  41. package/dist/TransakService.d.mts.map +1 -1
  42. package/dist/TransakService.mjs +45 -5
  43. package/dist/TransakService.mjs.map +1 -1
  44. package/dist/index.cjs +1 -20
  45. package/dist/index.cjs.map +1 -1
  46. package/dist/index.d.cts +4 -13
  47. package/dist/index.d.cts.map +1 -1
  48. package/dist/index.d.mts +4 -13
  49. package/dist/index.d.mts.map +1 -1
  50. package/dist/index.mjs +1 -5
  51. package/dist/index.mjs.map +1 -1
  52. package/package.json +1 -1
  53. package/dist/NeoBankService-method-action-types.cjs +0 -7
  54. package/dist/NeoBankService-method-action-types.cjs.map +0 -1
  55. package/dist/NeoBankService-method-action-types.d.cts +0 -126
  56. package/dist/NeoBankService-method-action-types.d.cts.map +0 -1
  57. package/dist/NeoBankService-method-action-types.d.mts +0 -126
  58. package/dist/NeoBankService-method-action-types.d.mts.map +0 -1
  59. package/dist/NeoBankService-method-action-types.mjs +0 -6
  60. package/dist/NeoBankService-method-action-types.mjs.map +0 -1
  61. package/dist/NeoBankService.cjs +0 -387
  62. package/dist/NeoBankService.cjs.map +0 -1
  63. package/dist/NeoBankService.d.cts +0 -191
  64. package/dist/NeoBankService.d.cts.map +0 -1
  65. package/dist/NeoBankService.d.mts +0 -191
  66. package/dist/NeoBankService.d.mts.map +0 -1
  67. package/dist/NeoBankService.mjs +0 -379
  68. package/dist/NeoBankService.mjs.map +0 -1
  69. package/dist/autoramp-types.cjs +0 -3
  70. package/dist/autoramp-types.cjs.map +0 -1
  71. package/dist/autoramp-types.d.cts +0 -22
  72. package/dist/autoramp-types.d.cts.map +0 -1
  73. package/dist/autoramp-types.d.mts +0 -22
  74. package/dist/autoramp-types.d.mts.map +0 -1
  75. package/dist/autoramp-types.mjs +0 -2
  76. package/dist/autoramp-types.mjs.map +0 -1
  77. package/dist/autorampAccount.cjs +0 -155
  78. package/dist/autorampAccount.cjs.map +0 -1
  79. package/dist/autorampAccount.d.cts +0 -126
  80. package/dist/autorampAccount.d.cts.map +0 -1
  81. package/dist/autorampAccount.d.mts +0 -126
  82. package/dist/autorampAccount.d.mts.map +0 -1
  83. package/dist/autorampAccount.mjs +0 -147
  84. package/dist/autorampAccount.mjs.map +0 -1
  85. package/dist/ownership-message.cjs +0 -26
  86. package/dist/ownership-message.cjs.map +0 -1
  87. package/dist/ownership-message.d.cts +0 -22
  88. package/dist/ownership-message.d.cts.map +0 -1
  89. package/dist/ownership-message.d.mts +0 -22
  90. package/dist/ownership-message.d.mts.map +0 -1
  91. package/dist/ownership-message.mjs +0 -22
  92. package/dist/ownership-message.mjs.map +0 -1
  93. package/dist/wallet-registration-machine.cjs +0 -144
  94. package/dist/wallet-registration-machine.cjs.map +0 -1
  95. package/dist/wallet-registration-machine.d.cts +0 -81
  96. package/dist/wallet-registration-machine.d.cts.map +0 -1
  97. package/dist/wallet-registration-machine.d.mts +0 -81
  98. package/dist/wallet-registration-machine.d.mts.map +0 -1
  99. package/dist/wallet-registration-machine.mjs +0 -139
  100. package/dist/wallet-registration-machine.mjs.map +0 -1
  101. package/dist/wallet-registration-service.cjs +0 -351
  102. package/dist/wallet-registration-service.cjs.map +0 -1
  103. package/dist/wallet-registration-service.d.cts +0 -144
  104. package/dist/wallet-registration-service.d.cts.map +0 -1
  105. package/dist/wallet-registration-service.d.mts +0 -144
  106. package/dist/wallet-registration-service.d.mts.map +0 -1
  107. package/dist/wallet-registration-service.mjs +0 -344
  108. package/dist/wallet-registration-service.mjs.map +0 -1
@@ -9,20 +9,16 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
9
9
  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");
10
10
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
11
  };
12
- 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;
12
+ 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
13
  import { BaseController } from "@metamask/base-controller";
14
14
  import { BrokenCircuitError } from "@metamask/controller-utils";
15
- import { applyAutorampRemoteStatus, createAutorampAccount, markAutorampNotified } from "./autorampAccount.mjs";
16
15
  import { getHeadlessProviderAllowlist, isHeadlessAllProvidersEnabled, normalizeHeadlessProviderId } from "./featureFlags.mjs";
17
16
  import { PENDING_ORDER_STATUSES, TERMINAL_ORDER_STATUSES } from "./orderStatus.mjs";
18
- import { buildOwnershipMessage } from "./ownership-message.mjs";
19
17
  import { mergePaymentMethodsById, pickPaymentMethod } from "./paymentMethodMerge.mjs";
20
18
  import { getProvidersServingAsset, normalizeRampsAssetId, providerServesAsset } from "./providerAvailability.mjs";
21
19
  import { RAMPS_ERROR_CODES } from "./rampsErrorCodes.mjs";
22
20
  import { RampsOrderStatus } from "./RampsService.mjs";
23
21
  import { DEFAULT_REQUEST_CACHE_TTL, DEFAULT_REQUEST_CACHE_MAX_SIZE, createCacheKey, isCacheExpired, createLoadingState, createSuccessState, createErrorState, RequestStatus } from "./RequestCache.mjs";
24
- import { createInitialState as createInitialWalletRegistrationState, transition as transitionWalletRegistration } from "./wallet-registration-machine.mjs";
25
- import { createIdempotencyKey, WalletRegistrationError } from "./wallet-registration-service.mjs";
26
22
  // === GENERAL ===
27
23
  /**
28
24
  * The name of the {@link RampsController}, used to namespace the
@@ -71,36 +67,7 @@ export const RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS = [
71
67
  'TransakService:cancelOrder',
72
68
  'TransakService:cancelAllActiveOrders',
73
69
  'TransakService:getActiveOrders',
74
- 'NeoBankService:getAutoramp',
75
- 'NeoBankService:createAutoramp',
76
- 'NeoBankService:getCustomerByExternalId',
77
- 'NeoBankService:getWalletRegistrationStatus',
78
- 'NeoBankService:registerSelfHostedWallet',
79
70
  ];
80
- /**
81
- * Every external controller action RampsController calls via the messenger,
82
- * which hosts must delegate from the root messenger.
83
- * `AuthenticationController:getSessionProfile` resolves the vendor customer
84
- * identity from Profile Sync, and `KeyringController:signPersonalMessage` signs
85
- * the EIP-191 ownership proof for Money Account self-hosted wallet
86
- * registration; both are only exercised by the autoramp paths.
87
- */
88
- export const RAMPS_CONTROLLER_REQUIRED_CONTROLLER_ACTIONS = [
89
- 'AuthenticationController:getSessionProfile',
90
- 'KeyringController:signPersonalMessage',
91
- 'RemoteFeatureFlagController:getState',
92
- ];
93
- /**
94
- * Distinguishes an already-materialized {@link AutorampAccount} from the
95
- * create-fields shape accepted by {@link RampsController.addAutoramp}.
96
- *
97
- * @param value - Full account or create fields.
98
- * @returns Whether the value already carries the derived account fields.
99
- */
100
- function isFullAutorampAccount(value) {
101
- return (typeof value.updatedAt === 'number' &&
102
- value.lastSeenStatus !== undefined);
103
- }
104
71
  /**
105
72
  * Default TTL for quotes requests (15 seconds).
106
73
  * Quotes are time-sensitive and should have a shorter cache duration.
@@ -212,12 +179,6 @@ const rampsControllerMetadata = {
212
179
  includeInStateLogs: true,
213
180
  usedInUi: true,
214
181
  },
215
- autoramps: {
216
- persist: true,
217
- includeInDebugSnapshot: true,
218
- includeInStateLogs: true,
219
- usedInUi: true,
220
- },
221
182
  providerAutoSelected: {
222
183
  persist: true,
223
184
  includeInDebugSnapshot: true,
@@ -267,7 +228,6 @@ export function getDefaultRampsControllerState() {
267
228
  },
268
229
  },
269
230
  orders: [],
270
- autoramps: [],
271
231
  providerAutoSelected: false,
272
232
  };
273
233
  }
@@ -413,14 +373,6 @@ const MESSENGER_EXPOSED_METHODS = [
413
373
  'getQuotes',
414
374
  'addOrder',
415
375
  'removeOrder',
416
- 'addAutoramp',
417
- 'createAutoramp',
418
- 'removeAutoramp',
419
- 'registerMoneyAccountWallet',
420
- 'markAutorampAsNotified',
421
- 'applyAutorampStatusFromPush',
422
- 'refreshAutoramp',
423
- 'refreshAutoramps',
424
376
  'startOrderPolling',
425
377
  'stopOrderPolling',
426
378
  'getBuyWidgetData',
@@ -1222,6 +1174,12 @@ export class RampsController extends BaseController {
1222
1174
  * @param options.action - The ramp action type. Defaults to 'buy'.
1223
1175
  * @param options.forceRefresh - Whether to bypass cache.
1224
1176
  * @param options.ttl - Custom TTL for this request.
1177
+ * @param options.isFeeExcludedFromFiat - When true, requests quotes whose
1178
+ * fees are charged on top of `amount` rather than taken out of it, so
1179
+ * `amountOut` is what `amount` buys before fees. The ramps API honours it
1180
+ * only when the request names exactly one provider, because a fee-on-top
1181
+ * `amountOut` cannot be ranked against fee-inclusive ones. Defaults to the
1182
+ * existing fee-inclusive behaviour.
1225
1183
  * @returns The quotes response containing success, sorted, error, and customActions.
1226
1184
  */
1227
1185
  async getQuotes(options) {
@@ -1252,7 +1210,12 @@ export class RampsController extends BaseController {
1252
1210
  const { enabled: allProvidersEnabled, allowlist: providerAllowlist } = wantsAutoSelection
1253
1211
  ? __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_resolveAllProvidersFlag).call(this)
1254
1212
  : { enabled: false, allowlist: undefined };
1255
- const widenToAllProviders = wantsAutoSelection && allProvidersEnabled;
1213
+ // Fee-on-top quotes cannot be ranked against fee-inclusive quotes because
1214
+ // their amountOut values have different meanings. Keep this request on the
1215
+ // single-provider resolver even when all-provider widening is enabled.
1216
+ const widenToAllProviders = wantsAutoSelection &&
1217
+ allProvidersEnabled &&
1218
+ options.isFeeExcludedFromFiat !== true;
1256
1219
  let providersToUse;
1257
1220
  let widenedProviderCatalog = this.state.providers.data;
1258
1221
  if (options.providers) {
@@ -1328,6 +1291,7 @@ export class RampsController extends BaseController {
1328
1291
  (widenToAllProviders
1329
1292
  ? this.messenger.call('RampsService:getDefaultRedirectCallbackUrl')
1330
1293
  : undefined);
1294
+ const isFeeExcludedFromFiat = options.isFeeExcludedFromFiat === true;
1331
1295
  const cacheKey = createCacheKey('getQuotes', [
1332
1296
  normalizedRegion,
1333
1297
  normalizedFiat,
@@ -1338,6 +1302,7 @@ export class RampsController extends BaseController {
1338
1302
  [...providersToUse].sort().join(','),
1339
1303
  effectiveRedirectUrl,
1340
1304
  action,
1305
+ isFeeExcludedFromFiat,
1341
1306
  ]);
1342
1307
  const params = {
1343
1308
  region: normalizedRegion,
@@ -1349,6 +1314,7 @@ export class RampsController extends BaseController {
1349
1314
  providers: providersToUse,
1350
1315
  redirectUrl: effectiveRedirectUrl,
1351
1316
  action,
1317
+ isFeeExcludedFromFiat,
1352
1318
  };
1353
1319
  const response = await this.executeRequest(cacheKey, async () => {
1354
1320
  return this.messenger.call('RampsService:getQuotes', params);
@@ -1426,304 +1392,6 @@ export class RampsController extends BaseController {
1426
1392
  });
1427
1393
  __classPrivateFieldGet(this, _RampsController_orderPollingMeta, "f").delete(providerOrderId);
1428
1394
  }
1429
- /**
1430
- * Adds or updates a local autoramp last-seen cursor (e.g. after create).
1431
- *
1432
- * @param accountOrInput - Full account or create fields.
1433
- * @returns The upserted {@link AutorampAccount}.
1434
- */
1435
- addAutoramp(accountOrInput) {
1436
- const account = isFullAutorampAccount(accountOrInput)
1437
- ? accountOrInput
1438
- : createAutorampAccount(accountOrInput);
1439
- this.update((state) => {
1440
- const idx = state.autoramps.findIndex((existing) => existing.id === account.id);
1441
- if (idx === -1) {
1442
- state.autoramps.push(account);
1443
- }
1444
- else {
1445
- state.autoramps[idx] = {
1446
- ...state.autoramps[idx],
1447
- ...account,
1448
- };
1449
- }
1450
- });
1451
- return (this.state.autoramps.find((existing) => existing.id === account.id) ??
1452
- account);
1453
- }
1454
- /**
1455
- * Creates an autoramp via the neo-bank proxy and applies the returned
1456
- * snapshot as the local last-seen cursor.
1457
- *
1458
- * The vendor `customer_id` is resolved via
1459
- * {@link RampsController.resolveAutorampCustomerId} and injected into the
1460
- * request (any caller-supplied `customer_id` is overwritten).
1461
- *
1462
- * @param request - CreateAutoramp payload.
1463
- * @param options - Optional idempotency key forwarded to the proxy.
1464
- * @param options.idempotencyKey - Value sent as `Idempotency-Key`.
1465
- * @returns The created/updated local {@link AutorampAccount}.
1466
- */
1467
- async createAutoramp(request, options = {}) {
1468
- const customerId = await this.resolveAutorampCustomerId();
1469
- const body = { ...request, customer_id: customerId };
1470
- const remote = await this.messenger.call('NeoBankService:createAutoramp', body, options);
1471
- return __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_applyAutorampRemoteSnapshot).call(this, remote);
1472
- }
1473
- /**
1474
- * Resolves the vendor `customer_id` for autoramp / Money Account operations.
1475
- *
1476
- * Maps the wallet's Profile Sync id (the partner `external_id`) to the
1477
- * vendor customer via `GET /neobank/customers/{external_id}/external`.
1478
- *
1479
- * @returns The vendor customer id.
1480
- */
1481
- async resolveAutorampCustomerId() {
1482
- const profile = await this.messenger.call('AuthenticationController:getSessionProfile');
1483
- const canonical = profile?.canonicalProfileId;
1484
- const externalId = typeof canonical === 'string' && canonical.length > 0
1485
- ? canonical
1486
- : profile?.profileId;
1487
- if (typeof externalId !== 'string' || externalId.length === 0) {
1488
- throw new Error('Cannot resolve MoonPay customer id: wallet is not signed in to Profile Sync.');
1489
- }
1490
- const customer = await this.messenger.call('NeoBankService:getCustomerByExternalId', externalId);
1491
- const customerId = customer &&
1492
- typeof customer === 'object' &&
1493
- typeof customer.id === 'string'
1494
- ? customer.id
1495
- : null;
1496
- if (!customerId) {
1497
- throw new Error(`Cannot resolve MoonPay customer id: no MoonPay customer is mapped to external id "${externalId}".`);
1498
- }
1499
- return customerId;
1500
- }
1501
- /**
1502
- * Registers a Money Account wallet with MoonPay Iron via neobank-proxy.
1503
- *
1504
- * @param params - Money Account wallet registration parameters.
1505
- * @param params.address - Monad Money Account address.
1506
- * @returns The registration state, or `{ type: 'lookupUnavailable' }` when
1507
- * the address-list lookup fails (never treated as unregistered).
1508
- */
1509
- async registerMoneyAccountWallet({ address, }) {
1510
- let machine = transitionWalletRegistration(createInitialWalletRegistrationState(), { type: 'START' });
1511
- const toExistingResult = (status) => {
1512
- if (status.type === 'active') {
1513
- return { type: 'alreadyRegistered', registration: status.registration };
1514
- }
1515
- if (status.type === 'disabled') {
1516
- return {
1517
- type: 'registeredDisabled',
1518
- registration: status.registration,
1519
- };
1520
- }
1521
- return undefined;
1522
- };
1523
- const customerId = await this.resolveAutorampCustomerId();
1524
- const toLookupUnavailableResult = (error) => {
1525
- machine = transitionWalletRegistration(machine, {
1526
- type: 'LOOKUP_FAILED',
1527
- });
1528
- return {
1529
- type: 'lookupUnavailable',
1530
- error: error instanceof WalletRegistrationError
1531
- ? error
1532
- : new WalletRegistrationError('lookupUnavailable', {
1533
- message: 'self-hosted address lookup failed',
1534
- body: error instanceof Error ? error.message : undefined,
1535
- }),
1536
- };
1537
- };
1538
- const lookup = async () => {
1539
- try {
1540
- return await this.messenger.call('NeoBankService:getWalletRegistrationStatus', { customerId, address });
1541
- }
1542
- catch (error) {
1543
- return toLookupUnavailableResult(error);
1544
- }
1545
- };
1546
- const applyLookup = (status) => {
1547
- let eventType = 'LOOKUP_ABSENT';
1548
- if (status.type === 'active') {
1549
- eventType = 'LOOKUP_ACTIVE';
1550
- }
1551
- else if (status.type === 'disabled') {
1552
- eventType = 'LOOKUP_DISABLED';
1553
- }
1554
- machine = transitionWalletRegistration(machine, {
1555
- type: eventType,
1556
- });
1557
- return toExistingResult(status);
1558
- };
1559
- const resolveLookup = async () => {
1560
- const status = await lookup();
1561
- if (status.type === 'lookupUnavailable') {
1562
- return status;
1563
- }
1564
- return applyLookup(status);
1565
- };
1566
- const existingResult = await resolveLookup();
1567
- if (existingResult) {
1568
- return existingResult;
1569
- }
1570
- let idempotencyKey = createIdempotencyKey();
1571
- let lastMessage;
1572
- while (true) {
1573
- const message = buildOwnershipMessage({
1574
- address,
1575
- customerId,
1576
- now: new Date(),
1577
- });
1578
- if (lastMessage !== undefined && message !== lastMessage) {
1579
- idempotencyKey = createIdempotencyKey();
1580
- }
1581
- lastMessage = message;
1582
- let signature;
1583
- try {
1584
- signature = await this.messenger.call('KeyringController:signPersonalMessage', { data: message, from: address });
1585
- machine = transitionWalletRegistration(machine, { type: 'SIGN_OK' });
1586
- }
1587
- catch (error) {
1588
- machine = transitionWalletRegistration(machine, {
1589
- type: 'SIGN_FAILED',
1590
- retryable: false,
1591
- });
1592
- throw error;
1593
- }
1594
- try {
1595
- const result = await this.messenger.call('NeoBankService:registerSelfHostedWallet', {
1596
- address,
1597
- customerId,
1598
- message,
1599
- signature,
1600
- idempotencyKey,
1601
- });
1602
- machine = transitionWalletRegistration(machine, { type: 'SUBMIT_OK' });
1603
- return result;
1604
- }
1605
- catch (error) {
1606
- if (!(error instanceof WalletRegistrationError)) {
1607
- machine = transitionWalletRegistration(machine, {
1608
- type: 'SUBMIT_TERMINAL',
1609
- });
1610
- throw error;
1611
- }
1612
- if (error.kind === 'conflict') {
1613
- machine = transitionWalletRegistration(machine, {
1614
- type: 'SUBMIT_CONFLICT',
1615
- });
1616
- }
1617
- else if (error.kind === 'transient') {
1618
- machine = transitionWalletRegistration(machine, {
1619
- type: 'SUBMIT_TRANSIENT',
1620
- });
1621
- }
1622
- else if (error.kind === 'validation') {
1623
- machine = transitionWalletRegistration(machine, {
1624
- type: 'SUBMIT_VALIDATION',
1625
- utcRollover: buildOwnershipMessage({
1626
- address,
1627
- customerId,
1628
- now: new Date(),
1629
- }) !== message,
1630
- });
1631
- }
1632
- else if (error.kind === 'rateLimited') {
1633
- machine = transitionWalletRegistration(machine, {
1634
- type: 'SUBMIT_RATE_LIMITED',
1635
- });
1636
- }
1637
- else {
1638
- machine = transitionWalletRegistration(machine, {
1639
- type: 'SUBMIT_TERMINAL',
1640
- });
1641
- }
1642
- if (machine.status === 'disambiguate409' ||
1643
- machine.status === 'checkThenRetry') {
1644
- const reconciledResult = await resolveLookup();
1645
- if (reconciledResult) {
1646
- return reconciledResult;
1647
- }
1648
- }
1649
- if (machine.status !== 'signing') {
1650
- throw error;
1651
- }
1652
- }
1653
- }
1654
- }
1655
- /**
1656
- * Removes a local autoramp last-seen cursor by id.
1657
- *
1658
- * @param autorampId - MoonPay autoramp id.
1659
- */
1660
- removeAutoramp(autorampId) {
1661
- this.update((state) => {
1662
- state.autoramps = state.autoramps.filter((autoramp) => autoramp.id !== autorampId);
1663
- });
1664
- }
1665
- /**
1666
- * Marks that the UI has already notified for the autoramp's current status.
1667
- *
1668
- * @param autorampId - MoonPay autoramp id.
1669
- */
1670
- markAutorampAsNotified(autorampId) {
1671
- const existing = this.state.autoramps.find((autoramp) => autoramp.id === autorampId);
1672
- if (!existing) {
1673
- return;
1674
- }
1675
- const notified = markAutorampNotified(existing);
1676
- this.update((state) => {
1677
- const idx = state.autoramps.findIndex((autoramp) => autoramp.id === autorampId);
1678
- if (idx !== -1) {
1679
- state.autoramps[idx] = notified;
1680
- }
1681
- });
1682
- }
1683
- /**
1684
- * Applies a remote autoramp snapshot from a websocket / webhook push.
1685
- *
1686
- * @param remote - Remote autoramp snapshot.
1687
- * @returns The updated local account.
1688
- */
1689
- applyAutorampStatusFromPush(remote) {
1690
- return __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_applyAutorampRemoteSnapshot).call(this, remote);
1691
- }
1692
- /**
1693
- * Fetches one autoramp from the neo-bank proxy and applies it to the
1694
- * last-seen cursor. Does not recreate a cursor that was removed while the
1695
- * request was in flight.
1696
- *
1697
- * @param autorampId - MoonPay autoramp id.
1698
- * @returns The updated local account, or an unpersisted snapshot if the
1699
- * cursor was removed during the fetch.
1700
- */
1701
- async refreshAutoramp(autorampId) {
1702
- const remote = await this.messenger.call('NeoBankService:getAutoramp', autorampId);
1703
- return __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_applyAutorampRemoteSnapshot).call(this, remote, { allowInsert: false });
1704
- }
1705
- /**
1706
- * Refreshes all known local autoramps from MoonPay.
1707
- * Intended for app resume / unlock catch-up when webhooks were missed.
1708
- *
1709
- * @returns Updated autoramp accounts (failed fetches are skipped).
1710
- */
1711
- async refreshAutoramps() {
1712
- const ids = this.state.autoramps.map((autoramp) => autoramp.id);
1713
- const updated = [];
1714
- for (const id of ids) {
1715
- try {
1716
- const account = await this.refreshAutoramp(id);
1717
- if (this.state.autoramps.some((autoramp) => autoramp.id === account.id)) {
1718
- updated.push(account);
1719
- }
1720
- }
1721
- catch {
1722
- // Keep local cursor for this id; continue remaining refreshes.
1723
- }
1724
- }
1725
- return updated;
1726
- }
1727
1395
  /**
1728
1396
  * Starts polling all pending V2 orders at a fixed interval.
1729
1397
  * Each poll cycle iterates orders with non-terminal statuses,
@@ -2013,16 +1681,17 @@ export class RampsController extends BaseController {
2013
1681
  * @param network - The blockchain network identifier.
2014
1682
  * @param paymentMethod - The payment method identifier.
2015
1683
  * @param fiatAmount - The fiat amount as a string.
1684
+ * @param isFeeExcludedFromFiat - Whether Transak charges fees on top.
2016
1685
  * @returns The buy quote with pricing and fee details.
2017
1686
  */
2018
- async transakGetBuyQuote(fiatCurrency, cryptoCurrency, network, paymentMethod, fiatAmount) {
1687
+ async transakGetBuyQuote(fiatCurrency, cryptoCurrency, network, paymentMethod, fiatAmount, isFeeExcludedFromFiat = false) {
2019
1688
  this.update((state) => {
2020
1689
  state.nativeProviders.transak.buyQuote.isLoading = true;
2021
1690
  state.nativeProviders.transak.buyQuote.error = null;
2022
1691
  delete state.nativeProviders.transak.buyQuote.errorKey;
2023
1692
  });
2024
1693
  try {
2025
- const quote = await this.messenger.call('TransakService:getBuyQuote', fiatCurrency, cryptoCurrency, network, paymentMethod, fiatAmount);
1694
+ const quote = await this.messenger.call('TransakService:getBuyQuote', fiatCurrency, cryptoCurrency, network, paymentMethod, fiatAmount, isFeeExcludedFromFiat);
2026
1695
  this.update((state) => {
2027
1696
  state.nativeProviders.transak.buyQuote.data = quote;
2028
1697
  state.nativeProviders.transak.buyQuote.isLoading = false;
@@ -2682,30 +2351,6 @@ async function _RampsController_resolveProviderIdsForPaymentMethods({ assetId, r
2682
2351
  }
2683
2352
  }
2684
2353
  return orderedIds;
2685
- }, _RampsController_applyAutorampRemoteSnapshot = function _RampsController_applyAutorampRemoteSnapshot(remote, { allowInsert = true } = {}) {
2686
- const local = this.state.autoramps.find((autoramp) => autoramp.id === remote.id) ??
2687
- null;
2688
- if (local === null && !allowInsert) {
2689
- return applyAutorampRemoteStatus(null, remote).account;
2690
- }
2691
- const result = applyAutorampRemoteStatus(local, remote);
2692
- this.update((state) => {
2693
- const idx = state.autoramps.findIndex((autoramp) => autoramp.id === result.account.id);
2694
- if (idx === -1) {
2695
- state.autoramps.push(result.account);
2696
- }
2697
- else {
2698
- state.autoramps[idx] = result.account;
2699
- }
2700
- });
2701
- if (result.statusChanged) {
2702
- this.messenger.publish('RampsController:autorampStatusChanged', {
2703
- autoramp: result.account,
2704
- previousStatus: result.previousStatus,
2705
- shouldNotify: result.shouldNotify,
2706
- });
2707
- }
2708
- return (this.state.autoramps.find((autoramp) => autoramp.id === result.account.id) ?? result.account);
2709
2354
  }, _RampsController_refreshOrder =
2710
2355
  /**
2711
2356
  * Refreshes a single order via the V2 API and updates it in state.