feat(ramps-controller): export Transak API error helpers and codes - #9135
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
|
Coordination
|
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
Link the Transak API error helper changelog entry to #9135 and apply lint:misc import-order formatting for the new ramps-controller files. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
Export only getTransakApiMessage and isTransakPhoneRegisteredError for mobile consumers. Drop shared error code constants and generic helpers from the public API and leave TransakService order-retry logic unchanged. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@metamaskbot publish-preview |
|
@metamaskbot publish-preview Re-publishing after |
Keep getTransakApiMessage and isTransakPhoneRegisteredError as the only public helpers while sharing ORDER_EXISTS and PHONE_ALREADY_REGISTERED in transakErrorCodes.ts for TransakService and error utils. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@metamaskbot publish-preview After |
Co-authored-by: Cursor <cursoragent@cursor.com>
|
@metamaskbot publish-preview After |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
## Explanation **Current state:** `@metamask/ramps-controller@14.2.0` is the latest publish on npm. Since then, two consumer-facing changes merged to `main` but are not yet published: - **MetaMask#9159 (TRAM-3539)** — `RampsController` now merges orders on the internal MetaMask order code (from canonical `order.id`, e.g. `c-{guid}`) instead of `providerOrderId`. Without this, Moonpay redirect buys can produce duplicate Activity rows (precreate stub + provider callback row). - **MetaMask#9135** — exports `getTransakApiMessage`, `isTransakPhoneRegisteredError`, and centralized Transak API error codes for client-side error handling. Mobile QA is currently blocked on a **preview build** (`@metamask-previews/ramps-controller`) for TestFlight; we need a real npm release to drop preview/resolution pins. **Solution:** Release **1055.0.0** publishes **`@metamask/ramps-controller@14.3.0`**. This PR only versions and ships what is already on `main` — no new feature work in the diff. **What's in 14.3.0:** | Category | Change | |----------|--------| | **Fixed** | Compare internal order codes in `addOrder` / `getOrder` / `addPrecreatedOrder` ([MetaMask#9159](MetaMask#9159)) | | **Added** | Transak API error helpers (`getTransakApiMessage`, `isTransakPhoneRegisteredError`, `transakErrorCodes.ts`) ([MetaMask#9135](MetaMask#9135)) | | **Changed** | Bump `@metamask/profile-sync-controller` to `^28.2.0` ([MetaMask#9119](MetaMask#9119)) | **SemVer:** Minor bump (14.2.0 → 14.3.0) — includes new exports plus a bug fix. No breaking API changes. **Other packages / deps:** Only `@metamask/ramps-controller` is published in this release. Dependency bumps listed above were already merged separately and are included because they landed after 14.2.0. **Worth noting for reviewers:** The fix normalizes stored `providerOrderId` to the internal order code for polling/lookup consistency. Order Details “copy id” may show the MetaMask `c-…` code rather than the provider-native UUID — support should use provider link / tx hash for native references. ## References - TRAM-3539 — duplicate Moonpay Activity rows on redirect buys - [MetaMask#9159](MetaMask#9159) — internal order id merge fix - [MetaMask#9135](MetaMask#9135) — Transak API error helpers - [MetaMask#9119](MetaMask#9119) — profile-sync-controller dep bump - [MetaMask/metamask-mobile#31837](MetaMask/metamask-mobile#31837) — mobile QA PR (preview pin; update to `^14.3.0` after this release) **Mobile follow-up after merge + npm publish:** 1. Bump `@metamask/ramps-controller` to `^14.3.0` 2. Remove preview alias / `resolutions` / `previewBuilds` 3. Re-run TestFlight QA for Moonpay redirect buy (single Activity row) ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md) - [ ] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them _(N/A — no breaking changes)_ <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Release-only version, changelog, and lockfile updates with no runtime code changes in this diff. > > **Overview** > Release **1055.0.0** publishes **`@metamask/ramps-controller@14.3.0`** to npm. The PR diff is versioning and dependency wiring only—no new feature code. > > **`@metamask/ramps-controller`** goes **14.2.0 → 14.3.0** with changelog section **14.3.0** (content already on `main`): Transak error helpers (`getTransakApiMessage`, `isTransakPhoneRegisteredError`, `transakErrorCodes.ts`), bump to `@metamask/profile-sync-controller` ^28.2.0, and the documented order-id merge fix for duplicate Moonpay Activity rows. > > Root **`package.json`** is bumped **1054.0.0 → 1055.0.0**. **`@metamask/transaction-pay-controller`** updates its dependency to **`@metamask/ramps-controller` ^14.3.0** and records that in its changelog; **`yarn.lock`** is updated accordingly. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 4685db4. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…etaMask#31580) ## **Description** Unified Buy v2 (`NativeFlow/BasicInfo`) submits personal details via `@metamask/ramps-controller`, which throws `TransakApiError` with top-level `errorCode` and `apiMessage`. The screen was still checking a legacy Axios response shape, so Transak error code `2020` (phone already registered) was never detected and the **Log in with email** logout CTA stayed hidden. This PR: 1. Detects phone-already-registered errors with `isTransakPhoneRegisteredError` and reads the user-facing message via `getTransakApiMessage` from `@metamask/ramps-controller` ([MetaMask/core#9135](MetaMask/core#9135)). 2. Preserves quote context when routing back to Enter Email after logout so re-auth can resume the buy flow. 3. Bumps `@metamask/ramps-controller` to `^14.3.0` (core MetaMask#9135 shipped in 14.3.0). Deposit v1 already handled `2020` via the legacy SDK/Axios path ([MetaMask#22183](MetaMask#22183)); this aligns UB2 with the controller error model. ## **Changelog** CHANGELOG entry: null ## **Related issues** Fixes: [TRAM-3654](https://consensyssoftware.atlassian.net/browse/TRAM-3654) ## **Manual testing steps** ```gherkin Feature: Unified Buy v2 phone already registered logout Scenario: user sees login-with-email when phone is registered to another account Given unified buy v2 is enabled and user is authenticated with email A And user reaches NativeFlow BasicInfo with a valid buy quote When user submits BasicInfo with a phone number already registered to email B Then an error banner is shown with localized phone-already-registered copy And a "Log in with email" action is visible When user taps "Log in with email" Then user is logged out of the Transak session And user is navigated to Enter Email with quote context preserved And user can authenticate with email B and continue the buy flow ``` **Unit tests:** `yarn jest app/components/UI/Ramp/Views/NativeFlow/BasicInfo.test.tsx` **RC QA:** TestFlight build **5530** from `fix/ub2-transak-phone-registered-logout` (RC workflow run [27652822118](https://github.com/MetaMask/metamask-mobile/actions/runs/27652822118)). ## **Screenshots/Recordings** N/A — pending QA on RC TestFlight build 5530. Will attach before/after recordings once verified. ### **Before** https://github.com/user-attachments/assets/78047789-fdd9-4a2d-a2cb-519853deae65 N/A ### **After** https://github.com/user-attachments/assets/c51913f8-42ca-48b9-bba1-de287cfcde9c N/A ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [ ] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. #### Performance checks (if applicable) - [ ] I've tested on Android - Ideally on a mid-range device; emulator is acceptable - [ ] I've tested with a power user scenario - Use these [power-user SRPs](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/edit-v2/401401446401?draftShareId=9d77e1e1-4bdc-4be1-9ebb-ccd916988d93) to import wallets with many accounts and tokens - [ ] I've instrumented key operations with Sentry traces for production performance metrics - See [`trace()`](/app/util/trace.ts) for usage and [`addToken`](/app/components/Views/AddAsset/components/AddCustomToken/AddCustomToken.tsx#L274) for an example For performance guidelines and tooling, see the [Performance Guide](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/400085549067/Performance+Guide+for+Engineers). ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. [TRAM-3654]: https://consensyssoftware.atlassian.net/browse/TRAM-3654?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Touches buy/KYC error handling and post-logout navigation in the ramps native flow; changes are localized and aligned with the controller error model, with unit test coverage. > > **Overview** > Unified Buy v2 **BasicInfo** now treats Transak failures from `@metamask/ramps-controller` correctly, so **phone already registered** (error `2020`) shows the error banner and **Log in with email** instead of being missed when the screen only read a legacy Axios `response.data.error` shape. > > Submission errors use **`isTransakPhoneRegisteredError`** and **`getTransakApiMessage`** (with existing `parseUserFacingError` as fallback). After logout, navigation always goes through **`createV2EnterEmailNavDetails`** with quote fields (`amount`, `currency`, `assetId`, optional `headlessSessionId`) so users can re-auth and continue the buy. > > **`@metamask/ramps-controller`** is bumped to **`^14.3.0`**; unit tests mock **`TransakApiError`** and assert the logout CTA and post-logout navigation. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit af1cac5. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Explanation
Unified Buy v2 (and other
@metamask/ramps-controllerconsumers) need to detect specific Transak API failures fromTransakApiError— for example error code2020when a phone number is already registered to a different email. Today, mobile duplicated string literals and ad-hocinstanceof/ Axios-shaped parsing because ramps-controller only exportedTransakApiErroritself, not reusable helpers or known codes.This PR adds shared Transak error codes and small type guards/helpers so consumers can branch on
errorCodeand readapiMessageconsistently:TRANSAK_ERROR_CODES(ORDER_EXISTS: '4005',PHONE_ALREADY_REGISTERED: '2020') andTransakErrorCodeisTransakApiError,getTransakErrorCode,getTransakApiMessage,isTransakErrorCode,isTransakPhoneRegisteredErrorTransakServicenow usesTRANSAK_ERROR_CODES.ORDER_EXISTSinstead of a private'4005'constant so order-exists retry logic and public exports stay aligned.No breaking changes. Changelog updated under
@metamask/ramps-controllerUnreleased.References
Checklist