@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.
- package/CHANGELOG.md +3 -4
- package/dist/NeoBankService-method-action-types.cjs +7 -0
- package/dist/NeoBankService-method-action-types.cjs.map +1 -0
- package/dist/NeoBankService-method-action-types.d.cts +126 -0
- package/dist/NeoBankService-method-action-types.d.cts.map +1 -0
- package/dist/NeoBankService-method-action-types.d.mts +126 -0
- package/dist/NeoBankService-method-action-types.d.mts.map +1 -0
- package/dist/NeoBankService-method-action-types.mjs +6 -0
- package/dist/NeoBankService-method-action-types.mjs.map +1 -0
- package/dist/NeoBankService.cjs +387 -0
- package/dist/NeoBankService.cjs.map +1 -0
- package/dist/NeoBankService.d.cts +191 -0
- package/dist/NeoBankService.d.cts.map +1 -0
- package/dist/NeoBankService.d.mts +191 -0
- package/dist/NeoBankService.d.mts.map +1 -0
- package/dist/NeoBankService.mjs +379 -0
- package/dist/NeoBankService.mjs.map +1 -0
- package/dist/RampsController-method-action-types.cjs.map +1 -1
- package/dist/RampsController-method-action-types.d.cts +91 -8
- package/dist/RampsController-method-action-types.d.cts.map +1 -1
- package/dist/RampsController-method-action-types.d.mts +91 -8
- package/dist/RampsController-method-action-types.d.mts.map +1 -1
- package/dist/RampsController-method-action-types.mjs.map +1 -1
- package/dist/RampsController.cjs +375 -20
- package/dist/RampsController.cjs.map +1 -1
- package/dist/RampsController.d.cts +153 -14
- package/dist/RampsController.d.cts.map +1 -1
- package/dist/RampsController.d.mts +153 -14
- package/dist/RampsController.d.mts.map +1 -1
- package/dist/RampsController.mjs +374 -19
- package/dist/RampsController.mjs.map +1 -1
- package/dist/RampsService-method-action-types.cjs.map +1 -1
- package/dist/RampsService-method-action-types.d.cts +0 -1
- package/dist/RampsService-method-action-types.d.cts.map +1 -1
- package/dist/RampsService-method-action-types.d.mts +0 -1
- package/dist/RampsService-method-action-types.d.mts.map +1 -1
- package/dist/RampsService-method-action-types.mjs.map +1 -1
- package/dist/RampsService.cjs +0 -4
- package/dist/RampsService.cjs.map +1 -1
- package/dist/RampsService.d.cts +0 -23
- package/dist/RampsService.d.cts.map +1 -1
- package/dist/RampsService.d.mts +0 -23
- package/dist/RampsService.d.mts.map +1 -1
- package/dist/RampsService.mjs +0 -4
- package/dist/RampsService.mjs.map +1 -1
- package/dist/TransakService-method-action-types.cjs.map +1 -1
- package/dist/TransakService-method-action-types.d.cts +2 -10
- package/dist/TransakService-method-action-types.d.cts.map +1 -1
- package/dist/TransakService-method-action-types.d.mts +2 -10
- package/dist/TransakService-method-action-types.d.mts.map +1 -1
- package/dist/TransakService-method-action-types.mjs.map +1 -1
- package/dist/TransakService.cjs +5 -45
- package/dist/TransakService.cjs.map +1 -1
- package/dist/TransakService.d.cts +3 -15
- package/dist/TransakService.d.cts.map +1 -1
- package/dist/TransakService.d.mts +3 -15
- package/dist/TransakService.d.mts.map +1 -1
- package/dist/TransakService.mjs +5 -45
- package/dist/TransakService.mjs.map +1 -1
- package/dist/autoramp-types.cjs +3 -0
- package/dist/autoramp-types.cjs.map +1 -0
- package/dist/autoramp-types.d.cts +22 -0
- package/dist/autoramp-types.d.cts.map +1 -0
- package/dist/autoramp-types.d.mts +22 -0
- package/dist/autoramp-types.d.mts.map +1 -0
- package/dist/autoramp-types.mjs +2 -0
- package/dist/autoramp-types.mjs.map +1 -0
- package/dist/autorampAccount.cjs +155 -0
- package/dist/autorampAccount.cjs.map +1 -0
- package/dist/autorampAccount.d.cts +126 -0
- package/dist/autorampAccount.d.cts.map +1 -0
- package/dist/autorampAccount.d.mts +126 -0
- package/dist/autorampAccount.d.mts.map +1 -0
- package/dist/autorampAccount.mjs +147 -0
- package/dist/autorampAccount.mjs.map +1 -0
- package/dist/index.cjs +20 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +13 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +5 -1
- package/dist/index.mjs.map +1 -1
- package/dist/ownership-message.cjs +26 -0
- package/dist/ownership-message.cjs.map +1 -0
- package/dist/ownership-message.d.cts +22 -0
- package/dist/ownership-message.d.cts.map +1 -0
- package/dist/ownership-message.d.mts +22 -0
- package/dist/ownership-message.d.mts.map +1 -0
- package/dist/ownership-message.mjs +22 -0
- package/dist/ownership-message.mjs.map +1 -0
- package/dist/wallet-registration-machine.cjs +144 -0
- package/dist/wallet-registration-machine.cjs.map +1 -0
- package/dist/wallet-registration-machine.d.cts +81 -0
- package/dist/wallet-registration-machine.d.cts.map +1 -0
- package/dist/wallet-registration-machine.d.mts +81 -0
- package/dist/wallet-registration-machine.d.mts.map +1 -0
- package/dist/wallet-registration-machine.mjs +139 -0
- package/dist/wallet-registration-machine.mjs.map +1 -0
- package/dist/wallet-registration-service.cjs +351 -0
- package/dist/wallet-registration-service.cjs.map +1 -0
- package/dist/wallet-registration-service.d.cts +144 -0
- package/dist/wallet-registration-service.d.cts.map +1 -0
- package/dist/wallet-registration-service.d.mts +144 -0
- package/dist/wallet-registration-service.d.mts.map +1 -0
- package/dist/wallet-registration-service.mjs +344 -0
- package/dist/wallet-registration-service.mjs.map +1 -0
- package/package.json +1 -1
package/dist/RampsController.mjs
CHANGED
|
@@ -9,16 +9,20 @@ 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_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_applyAutorampRemoteSnapshot, _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";
|
|
15
16
|
import { getHeadlessProviderAllowlist, isHeadlessAllProvidersEnabled, normalizeHeadlessProviderId } from "./featureFlags.mjs";
|
|
16
17
|
import { PENDING_ORDER_STATUSES, TERMINAL_ORDER_STATUSES } from "./orderStatus.mjs";
|
|
18
|
+
import { buildOwnershipMessage } from "./ownership-message.mjs";
|
|
17
19
|
import { mergePaymentMethodsById, pickPaymentMethod } from "./paymentMethodMerge.mjs";
|
|
18
20
|
import { getProvidersServingAsset, normalizeRampsAssetId, providerServesAsset } from "./providerAvailability.mjs";
|
|
19
21
|
import { RAMPS_ERROR_CODES } from "./rampsErrorCodes.mjs";
|
|
20
22
|
import { RampsOrderStatus } from "./RampsService.mjs";
|
|
21
23
|
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";
|
|
22
26
|
// === GENERAL ===
|
|
23
27
|
/**
|
|
24
28
|
* The name of the {@link RampsController}, used to namespace the
|
|
@@ -67,7 +71,36 @@ export const RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS = [
|
|
|
67
71
|
'TransakService:cancelOrder',
|
|
68
72
|
'TransakService:cancelAllActiveOrders',
|
|
69
73
|
'TransakService:getActiveOrders',
|
|
74
|
+
'NeoBankService:getAutoramp',
|
|
75
|
+
'NeoBankService:createAutoramp',
|
|
76
|
+
'NeoBankService:getCustomerByExternalId',
|
|
77
|
+
'NeoBankService:getWalletRegistrationStatus',
|
|
78
|
+
'NeoBankService:registerSelfHostedWallet',
|
|
70
79
|
];
|
|
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
|
+
}
|
|
71
104
|
/**
|
|
72
105
|
* Default TTL for quotes requests (15 seconds).
|
|
73
106
|
* Quotes are time-sensitive and should have a shorter cache duration.
|
|
@@ -179,6 +212,12 @@ const rampsControllerMetadata = {
|
|
|
179
212
|
includeInStateLogs: true,
|
|
180
213
|
usedInUi: true,
|
|
181
214
|
},
|
|
215
|
+
autoramps: {
|
|
216
|
+
persist: true,
|
|
217
|
+
includeInDebugSnapshot: true,
|
|
218
|
+
includeInStateLogs: true,
|
|
219
|
+
usedInUi: true,
|
|
220
|
+
},
|
|
182
221
|
providerAutoSelected: {
|
|
183
222
|
persist: true,
|
|
184
223
|
includeInDebugSnapshot: true,
|
|
@@ -228,6 +267,7 @@ export function getDefaultRampsControllerState() {
|
|
|
228
267
|
},
|
|
229
268
|
},
|
|
230
269
|
orders: [],
|
|
270
|
+
autoramps: [],
|
|
231
271
|
providerAutoSelected: false,
|
|
232
272
|
};
|
|
233
273
|
}
|
|
@@ -373,6 +413,14 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
373
413
|
'getQuotes',
|
|
374
414
|
'addOrder',
|
|
375
415
|
'removeOrder',
|
|
416
|
+
'addAutoramp',
|
|
417
|
+
'createAutoramp',
|
|
418
|
+
'removeAutoramp',
|
|
419
|
+
'registerMoneyAccountWallet',
|
|
420
|
+
'markAutorampAsNotified',
|
|
421
|
+
'applyAutorampStatusFromPush',
|
|
422
|
+
'refreshAutoramp',
|
|
423
|
+
'refreshAutoramps',
|
|
376
424
|
'startOrderPolling',
|
|
377
425
|
'stopOrderPolling',
|
|
378
426
|
'getBuyWidgetData',
|
|
@@ -1174,12 +1222,6 @@ export class RampsController extends BaseController {
|
|
|
1174
1222
|
* @param options.action - The ramp action type. Defaults to 'buy'.
|
|
1175
1223
|
* @param options.forceRefresh - Whether to bypass cache.
|
|
1176
1224
|
* @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.
|
|
1183
1225
|
* @returns The quotes response containing success, sorted, error, and customActions.
|
|
1184
1226
|
*/
|
|
1185
1227
|
async getQuotes(options) {
|
|
@@ -1210,12 +1252,7 @@ export class RampsController extends BaseController {
|
|
|
1210
1252
|
const { enabled: allProvidersEnabled, allowlist: providerAllowlist } = wantsAutoSelection
|
|
1211
1253
|
? __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_resolveAllProvidersFlag).call(this)
|
|
1212
1254
|
: { enabled: false, allowlist: undefined };
|
|
1213
|
-
|
|
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;
|
|
1255
|
+
const widenToAllProviders = wantsAutoSelection && allProvidersEnabled;
|
|
1219
1256
|
let providersToUse;
|
|
1220
1257
|
let widenedProviderCatalog = this.state.providers.data;
|
|
1221
1258
|
if (options.providers) {
|
|
@@ -1291,7 +1328,6 @@ export class RampsController extends BaseController {
|
|
|
1291
1328
|
(widenToAllProviders
|
|
1292
1329
|
? this.messenger.call('RampsService:getDefaultRedirectCallbackUrl')
|
|
1293
1330
|
: undefined);
|
|
1294
|
-
const isFeeExcludedFromFiat = options.isFeeExcludedFromFiat === true;
|
|
1295
1331
|
const cacheKey = createCacheKey('getQuotes', [
|
|
1296
1332
|
normalizedRegion,
|
|
1297
1333
|
normalizedFiat,
|
|
@@ -1302,7 +1338,6 @@ export class RampsController extends BaseController {
|
|
|
1302
1338
|
[...providersToUse].sort().join(','),
|
|
1303
1339
|
effectiveRedirectUrl,
|
|
1304
1340
|
action,
|
|
1305
|
-
isFeeExcludedFromFiat,
|
|
1306
1341
|
]);
|
|
1307
1342
|
const params = {
|
|
1308
1343
|
region: normalizedRegion,
|
|
@@ -1314,7 +1349,6 @@ export class RampsController extends BaseController {
|
|
|
1314
1349
|
providers: providersToUse,
|
|
1315
1350
|
redirectUrl: effectiveRedirectUrl,
|
|
1316
1351
|
action,
|
|
1317
|
-
isFeeExcludedFromFiat,
|
|
1318
1352
|
};
|
|
1319
1353
|
const response = await this.executeRequest(cacheKey, async () => {
|
|
1320
1354
|
return this.messenger.call('RampsService:getQuotes', params);
|
|
@@ -1392,6 +1426,304 @@ export class RampsController extends BaseController {
|
|
|
1392
1426
|
});
|
|
1393
1427
|
__classPrivateFieldGet(this, _RampsController_orderPollingMeta, "f").delete(providerOrderId);
|
|
1394
1428
|
}
|
|
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
|
+
}
|
|
1395
1727
|
/**
|
|
1396
1728
|
* Starts polling all pending V2 orders at a fixed interval.
|
|
1397
1729
|
* Each poll cycle iterates orders with non-terminal statuses,
|
|
@@ -1681,17 +2013,16 @@ export class RampsController extends BaseController {
|
|
|
1681
2013
|
* @param network - The blockchain network identifier.
|
|
1682
2014
|
* @param paymentMethod - The payment method identifier.
|
|
1683
2015
|
* @param fiatAmount - The fiat amount as a string.
|
|
1684
|
-
* @param isFeeExcludedFromFiat - Whether Transak charges fees on top.
|
|
1685
2016
|
* @returns The buy quote with pricing and fee details.
|
|
1686
2017
|
*/
|
|
1687
|
-
async transakGetBuyQuote(fiatCurrency, cryptoCurrency, network, paymentMethod, fiatAmount
|
|
2018
|
+
async transakGetBuyQuote(fiatCurrency, cryptoCurrency, network, paymentMethod, fiatAmount) {
|
|
1688
2019
|
this.update((state) => {
|
|
1689
2020
|
state.nativeProviders.transak.buyQuote.isLoading = true;
|
|
1690
2021
|
state.nativeProviders.transak.buyQuote.error = null;
|
|
1691
2022
|
delete state.nativeProviders.transak.buyQuote.errorKey;
|
|
1692
2023
|
});
|
|
1693
2024
|
try {
|
|
1694
|
-
const quote = await this.messenger.call('TransakService:getBuyQuote', fiatCurrency, cryptoCurrency, network, paymentMethod, fiatAmount
|
|
2025
|
+
const quote = await this.messenger.call('TransakService:getBuyQuote', fiatCurrency, cryptoCurrency, network, paymentMethod, fiatAmount);
|
|
1695
2026
|
this.update((state) => {
|
|
1696
2027
|
state.nativeProviders.transak.buyQuote.data = quote;
|
|
1697
2028
|
state.nativeProviders.transak.buyQuote.isLoading = false;
|
|
@@ -2351,6 +2682,30 @@ async function _RampsController_resolveProviderIdsForPaymentMethods({ assetId, r
|
|
|
2351
2682
|
}
|
|
2352
2683
|
}
|
|
2353
2684
|
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);
|
|
2354
2709
|
}, _RampsController_refreshOrder =
|
|
2355
2710
|
/**
|
|
2356
2711
|
* Refreshes a single order via the V2 API and updates it in state.
|