Conversation
pkowalski
approved these changes
Mar 24, 2026
Contributor
Author
|
@metamaskbot publish-previews |
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
micaelae
pushed a commit
that referenced
this pull request
Mar 24, 2026
…#8278) ## Explanation Moves provider ID normalization from call sites into `RampsService` at URL construction time, so callers can pass `provider.id` in either path format (`/providers/transak`) or short format (`transak`) without pre-normalizing. Root cause: Every caller of `getOrder` and `getOrderFromCallback` had to remember to call `normalizeProviderCode()` before passing the provider ID. This created scattered normalization logic across the controller and mobile app, and was error-prone as new call sites were added. Changes: 1. **`RampsService`** — Added a private `#toProviderSegment()` helper that strips the `/providers/` prefix (if present) before building API URLs. Applied in both `getOrder` and `getOrderFromCallback`. This is the primary change: the service now accepts both ID formats. 2. **`RampsController`** — Removed `normalizeProviderCode()` calls from `#refreshOrder` and `addPrecreatedOrder`. The controller now passes `provider.id` through as-is, since the service handles normalization internally. `addPrecreatedOrder` stores the `providerCode` as received instead of normalizing and re-prefixing. 3. **`normalizeProviderCode`** — Kept exported from the package for backward compatibility. Existing consumers (e.g. current mobile) that still call it will continue to work (double-stripping is harmless). This change is fully backward-compatible: callers that still normalize before passing to the service will keep working, and callers that pass raw `.id` will also work. ## Link to metamask-mobile TBD — mobile PR will be created after this is published. Mobile changes remove `normalizeProviderCode` usage from 6 files. ## References [TRAM-3244](https://consensyssoftware.atlassian.net/browse/TRAM-3244) ## 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 - [ ] 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 ## Metamask Mobile Mobile will remove `normalizeProviderCode` imports and usage from: - `unifiedOrderProcessor.ts` - `BuildQuote.tsx` - `Checkout.tsx` - `OrderDetails.tsx` - `BankDetails.tsx` - `useTransakRouting.ts` This is safe to do after the core change is published since the service now handles both formats. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Medium risk because it changes how provider IDs are propagated and how order/callback URLs are constructed, which could break order fetching/polling if normalization is wrong or provider IDs are unexpectedly formatted. > > **Overview** > Centralizes provider ID normalization in `RampsService` by stripping an optional `/providers/` prefix when building V2 order and callback API paths, so `getOrder`/`getOrderFromCallback` accept either format. > > Updates `RampsController` to pass provider IDs through unchanged (including polling refreshes and `addPrecreatedOrder` stubs) and adjusts tests/docs/changelog to match the new behavior. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit fd9bff4. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
Merged
4 tasks
github-merge-queue Bot
pushed a commit
that referenced
this pull request
Mar 26, 2026
…efixed provider ids (#8289) ## Explanation Fixes `addPrecreatedOrder` to always store `provider.id` in the canonical `/providers/{code}` format, matching the shape returned by API responses. The previous commit ([#8278](#8278)) moved provider ID normalization into `RampsService` at URL construction time and stopped normalizing in `addPrecreatedOrder`. However, this caused the stub order's `provider.id` to be stored as whatever format the caller passed (e.g. `"paypal"` instead of `"/providers/paypal"`). This mismatch breaks downstream equality checks — `getOrdersProviders`, `determinePreferredProvider`, and `useSortedQuotes` all compare `provider.id` against API-sourced provider lists which use the `/providers/` prefix. Changes: 1. **`RampsController.ts`** — Restore `normalizeProviderCode()` call in `addPrecreatedOrder` to strip any incoming prefix, then rebuild in canonical `/providers/{normalizedCode}` format. This ensures stub orders match the shape of API-fetched orders. 2. **`RampsController.test.ts`** — Update `addPrecreatedOrder` test expectation back to `/providers/paypal`. 3. **`CHANGELOG.md`** — Add Fixed entry for the id format correction. ## Link to mobile PR link to: [MetaMask/metamask-mobile#27893](MetaMask/metamask-mobile#27893) ## References [TRAM-3244](https://consensyssoftware.atlassian.net/browse/TRAM-3244) Follows: [#8278](#8278) ## 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 <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Low risk: small, localized change to how `addPrecreatedOrder` formats `provider.id`, plus corresponding test and changelog updates. > > **Overview** > Ensures `RampsController.addPrecreatedOrder` always stores stub orders with a canonical `provider.id` of `/providers/{code}` by normalizing any incoming `providerCode` (with or without the `/providers/` prefix). > > Updates the related unit test expectation and adds a changelog *Fixed* entry documenting the provider id normalization for precreated order stubs. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 934834c. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
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
Moves provider ID normalization from call sites into
RampsServiceat URL construction time, so callers can passprovider.idin either path format (/providers/transak) or short format (transak) without pre-normalizing.Root cause: Every caller of
getOrderandgetOrderFromCallbackhad to remember to callnormalizeProviderCode()before passing the provider ID. This created scattered normalization logic across the controller and mobile app, and was error-prone as new call sites were added.Changes:
RampsService— Added a private#toProviderSegment()helper that strips the/providers/prefix (if present) before building API URLs. Applied in bothgetOrderandgetOrderFromCallback. This is the primary change: the service now accepts both ID formats.RampsController— RemovednormalizeProviderCode()calls from#refreshOrderandaddPrecreatedOrder. The controller now passesprovider.idthrough as-is, since the service handles normalization internally.addPrecreatedOrderstores theproviderCodeas received instead of normalizing and re-prefixing.normalizeProviderCode— Kept exported from the package for backward compatibility. Existing consumers (e.g. current mobile) that still call it will continue to work (double-stripping is harmless).This change is fully backward-compatible: callers that still normalize before passing to the service will keep working, and callers that pass raw
.idwill also work.Link to metamask-mobile
TBD — mobile PR will be created after this is published. Mobile changes remove
normalizeProviderCodeusage from 6 files.References
TRAM-3244
Checklist
Metamask Mobile
Mobile will remove
normalizeProviderCodeimports and usage from:unifiedOrderProcessor.tsBuildQuote.tsxCheckout.tsxOrderDetails.tsxBankDetails.tsxuseTransakRouting.tsThis is safe to do after the core change is published since the service now handles both formats.
Note
Medium Risk
Medium risk because it changes how provider identifiers flow from
RampsControllerintoRampsServiceand affects construction of order/callback API URLs used by polling and callbacks; mistakes would surface as failed order lookups.Overview
Moves provider-id normalization into
RampsServiceforgetOrderandgetOrderFromCallback, allowing callers to pass eithertransakor/providers/transakwhile always building V2 API paths with the short provider segment.Updates
RampsControllerto stop stripping/re-prefixing provider ids during order polling andaddPrecreatedOrderstub creation, and adjusts/extends unit tests plus the changelog to reflect the new pass-through behavior and normalization coverage.Written by Cursor Bugbot for commit fd9bff4. This will update automatically on new commits. Configure here.