Skip to content

feat(ramps): Move provider ID normalization into RampsService of Core#8278

Merged
imyugioh merged 3 commits intomainfrom
feat/ramps-3244-normalize-provider-ids-in-service
Mar 24, 2026
Merged

feat(ramps): Move provider ID normalization into RampsService of Core#8278
imyugioh merged 3 commits intomainfrom
feat/ramps-3244-normalize-provider-ids-in-service

Conversation

@imyugioh
Copy link
Copy Markdown
Contributor

@imyugioh imyugioh commented Mar 24, 2026

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

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • 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
  • I've introduced breaking changes 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.


Note

Medium Risk
Medium risk because it changes how provider identifiers flow from RampsController into RampsService and 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 RampsService for getOrder and getOrderFromCallback, allowing callers to pass either transak or /providers/transak while always building V2 API paths with the short provider segment.

Updates RampsController to stop stripping/re-prefixing provider ids during order polling and addPrecreatedOrder stub 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.

@imyugioh imyugioh self-assigned this Mar 24, 2026
@imyugioh imyugioh requested a review from a team as a code owner March 24, 2026 02:21
@imyugioh imyugioh requested a review from a team as a code owner March 24, 2026 02:28
@imyugioh imyugioh added this pull request to the merge queue Mar 24, 2026
Merged via the queue into main with commit 57daf93 Mar 24, 2026
325 of 326 checks passed
@imyugioh imyugioh deleted the feat/ramps-3244-normalize-provider-ids-in-service branch March 24, 2026 12:38
@imyugioh
Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-previews

@imyugioh imyugioh restored the feat/ramps-3244-normalize-provider-ids-in-service branch March 24, 2026 12:57
@github-actions
Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@5.0.1-preview-fd9bff420
@metamask-previews/accounts-controller@37.0.0-preview-fd9bff420
@metamask-previews/address-book-controller@7.1.0-preview-fd9bff420
@metamask-previews/ai-controllers@0.5.0-preview-fd9bff420
@metamask-previews/analytics-controller@1.0.0-preview-fd9bff420
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-fd9bff420
@metamask-previews/announcement-controller@8.0.0-preview-fd9bff420
@metamask-previews/app-metadata-controller@2.0.0-preview-fd9bff420
@metamask-previews/approval-controller@9.0.0-preview-fd9bff420
@metamask-previews/assets-controller@3.1.0-preview-fd9bff420
@metamask-previews/assets-controllers@101.0.1-preview-fd9bff420
@metamask-previews/base-controller@9.0.0-preview-fd9bff420
@metamask-previews/base-data-service@0.0.0-preview-fd9bff420
@metamask-previews/bridge-controller@69.2.0-preview-fd9bff420
@metamask-previews/bridge-status-controller@70.0.0-preview-fd9bff420
@metamask-previews/build-utils@3.0.4-preview-fd9bff420
@metamask-previews/chain-agnostic-permission@1.4.0-preview-fd9bff420
@metamask-previews/claims-controller@0.4.3-preview-fd9bff420
@metamask-previews/client-controller@1.0.0-preview-fd9bff420
@metamask-previews/compliance-controller@1.0.1-preview-fd9bff420
@metamask-previews/composable-controller@12.0.0-preview-fd9bff420
@metamask-previews/config-registry-controller@0.1.1-preview-fd9bff420
@metamask-previews/connectivity-controller@0.1.0-preview-fd9bff420
@metamask-previews/controller-utils@11.19.0-preview-fd9bff420
@metamask-previews/core-backend@6.2.0-preview-fd9bff420
@metamask-previews/delegation-controller@2.0.2-preview-fd9bff420
@metamask-previews/earn-controller@11.1.2-preview-fd9bff420
@metamask-previews/eip-5792-middleware@3.0.1-preview-fd9bff420
@metamask-previews/eip-7702-internal-rpc-middleware@0.1.0-preview-fd9bff420
@metamask-previews/eip1193-permission-middleware@1.0.3-preview-fd9bff420
@metamask-previews/ens-controller@19.1.0-preview-fd9bff420
@metamask-previews/error-reporting-service@3.0.1-preview-fd9bff420
@metamask-previews/eth-block-tracker@15.0.1-preview-fd9bff420
@metamask-previews/eth-json-rpc-middleware@23.1.0-preview-fd9bff420
@metamask-previews/eth-json-rpc-provider@6.0.0-preview-fd9bff420
@metamask-previews/foundryup@1.0.1-preview-fd9bff420
@metamask-previews/gas-fee-controller@26.1.0-preview-fd9bff420
@metamask-previews/gator-permissions-controller@2.1.1-preview-fd9bff420
@metamask-previews/geolocation-controller@0.1.1-preview-fd9bff420
@metamask-previews/json-rpc-engine@10.2.3-preview-fd9bff420
@metamask-previews/json-rpc-middleware-stream@8.0.8-preview-fd9bff420
@metamask-previews/keyring-controller@25.1.0-preview-fd9bff420
@metamask-previews/logging-controller@8.0.0-preview-fd9bff420
@metamask-previews/message-manager@14.1.0-preview-fd9bff420
@metamask-previews/messenger@0.3.0-preview-fd9bff420
@metamask-previews/multichain-account-service@7.1.0-preview-fd9bff420
@metamask-previews/multichain-api-middleware@1.2.7-preview-fd9bff420
@metamask-previews/multichain-network-controller@3.0.5-preview-fd9bff420
@metamask-previews/multichain-transactions-controller@7.0.2-preview-fd9bff420
@metamask-previews/name-controller@9.1.0-preview-fd9bff420
@metamask-previews/network-controller@30.0.0-preview-fd9bff420
@metamask-previews/network-enablement-controller@5.0.0-preview-fd9bff420
@metamask-previews/notification-services-controller@23.0.0-preview-fd9bff420
@metamask-previews/permission-controller@12.2.1-preview-fd9bff420
@metamask-previews/permission-log-controller@5.0.0-preview-fd9bff420
@metamask-previews/perps-controller@1.3.0-preview-fd9bff420
@metamask-previews/phishing-controller@17.0.0-preview-fd9bff420
@metamask-previews/polling-controller@16.0.3-preview-fd9bff420
@metamask-previews/preferences-controller@23.0.0-preview-fd9bff420
@metamask-previews/profile-metrics-controller@3.1.1-preview-fd9bff420
@metamask-previews/profile-sync-controller@28.0.0-preview-fd9bff420
@metamask-previews/ramps-controller@12.0.1-preview-fd9bff420
@metamask-previews/rate-limit-controller@7.0.0-preview-fd9bff420
@metamask-previews/react-data-query@0.0.0-preview-fd9bff420
@metamask-previews/remote-feature-flag-controller@4.1.0-preview-fd9bff420
@metamask-previews/sample-controllers@4.0.3-preview-fd9bff420
@metamask-previews/seedless-onboarding-controller@9.0.0-preview-fd9bff420
@metamask-previews/selected-network-controller@26.0.3-preview-fd9bff420
@metamask-previews/shield-controller@5.0.2-preview-fd9bff420
@metamask-previews/signature-controller@39.1.0-preview-fd9bff420
@metamask-previews/storage-service@1.0.0-preview-fd9bff420
@metamask-previews/subscription-controller@6.0.2-preview-fd9bff420
@metamask-previews/transaction-controller@63.1.0-preview-fd9bff420
@metamask-previews/transaction-pay-controller@18.0.0-preview-fd9bff420
@metamask-previews/user-operation-controller@41.1.0-preview-fd9bff420

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 -->
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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants