feat(ramps): Add TransakService for native deposit flow integration#7922
Open
georgeweiler wants to merge 17 commits intomainfrom
Open
feat(ramps): Add TransakService for native deposit flow integration#7922georgeweiler wants to merge 17 commits intomainfrom
georgeweiler wants to merge 17 commits intomainfrom
Conversation
Contributor
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
| quoteId, | ||
| walletAddress, | ||
| paymentInstrumentId: translation.paymentMethod, | ||
| }, |
There was a problem hiding this comment.
Missing payment method fallback on translation miss
Medium Severity
getTranslation() allows paymentMethod to be undefined, but createOrder() and confirmPayment() do not handle that safely. createOrder() can send no paymentInstrumentId, and confirmPayment() falls back to raw paymentMethodId (for example a ramps path), which can be invalid for Transak’s API format.
Additional Locations (1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Explanation
Introduces a new
TransakServiceclass that provides a direct integration with the Transak API for native buy/deposit flows within the ramps-controller package. This enables a "V2" native flow where MetaMask communicates directly with Transak's APIs for authentication, KYC, quoting, and order management -- rather than routing everything through the aggregator widget.What changed
New files:
TransakService.ts-- API client wrapping Transak's REST endpoints. Handles authentication (OTP login/verify), buy quotes, KYC requirements, order creation/cancellation, user management, payment confirmation, and a translation layer that maps generic ramps identifiers to Transak-specific ones. Uses the messenger pattern withregisterMethodActionHandlersto expose 23 methods as callable actions.TransakService-method-action-types.ts-- TypeScript action type definitions for each exposed messenger method.TransakService.test.ts-- Comprehensive test suite usingnockfor HTTP mocking. Covers all public methods, error paths, authentication guards, environment switching (staging/production), order ID transformations, and retry logic.Modified files:
RampsController.ts-- AddsnativeProviders.transakstate (authentication status, user details, buy quote, KYC requirement) with loading/error tracking viaResourceState. Adds ~25transak*methods that delegate to the TransakService via messenger calls, with stateful methods (transakGetUserDetails,transakGetBuyQuote,transakGetKycRequirement) managing loading and error state. ChangesstartQuotePollingto return early instead of throwing when no provider is selected.RampsController.test.ts-- Adds tests for all new transak methods on the controller, including state management, error handling, and fallback error messages. Updates existing snapshot assertions to include the newnativeProvidersstate shape.RampsService.ts-- Minor change (debug logging).index.ts-- Exports all new types, classes (TransakService,TransakEnvironment,TransakOrderIdTransformer), and action types from the package.Key design decisions
TransakServiceregisters its methods as messenger actions, andRampsControllercalls them viathis.messenger.call(...). This keeps the service decoupled from the controller and allows other consumers to call TransakService directly.getTranslationendpoint maps generic ramps identifiers (chain IDs, asset IDs, payment method paths) to Transak-native identifiers before calling Transak APIs. This keeps the controller's interface provider-agnostic.TransakOrderIdTransformerconverts between Transak's raw order IDs and the deposit-format IDs used by the ramps orders API (/providers/transak-native/orders/{id}).nativeProviders.transakto support future native provider integrations under the same pattern. State is not persisted (persist: false) since it contains session-specific data.Test plan
TransakService.test.ts-- all new service-level tests pass (auth flows, API calls, error handling, order ID transforms)RampsController.test.ts-- all new controller-level tests pass (messenger delegation, state updates, error state management)RampsControllertests continue to pass with updated snapshotsReferences
Checklist
Note
Medium Risk
Adds a large new API integration layer and new controller state/messenger actions, which could affect deposit flows and error handling; however the changes are mostly additive and are covered by substantial new tests.
Overview
Introduces a new
TransakService(plus generated messenger action types and extensive tests) that integrates directly with Transak for native deposit flows, including OTP auth, KYC checks, quote fetching, order lifecycle management (create/get/cancel/retry-on-conflict), user updates, spending limits, OTT, and payment widget URL generation.Extends
RampsControllerwith a non-persistednativeProviders.transakstate slice (auth flag + resource states for user details, buy quote, KYC requirement) and a set oftransak*convenience methods that callTransakService:*messenger actions and manage loading/error state for key resources; the controller’s required delegated actions list is expanded accordingly. Also tightens quote polling by throwing when no payment method is selected (previously returned early), and extendsPaymentMethodwith optionalisManualBankTransfer.Exports the new service, types, and action types from
index.ts, and updates the package changelog to document the additions.Written by Cursor Bugbot for commit eb87565. This will update automatically on new commits. Configure here.