Skip to content

Commit 889b955

Browse files
authored
fix(ramps): Fix addPrecreatedOrder's provider id format for legacy prefixed 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 -->
1 parent 38cd6a5 commit 889b955

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

packages/ramps-controller/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
### Changed
1616

1717
- Stop persisting `providers` and `tokens` state across sessions to prevent stale data when API availability changes ([#8307](https://github.com/MetaMask/core/pull/8307))
18-
- `RampsService.getOrder` and `getOrderFromCallback` accept provider codes with or without a `/providers/` prefix; API paths use the short provider segment. `RampsController` forwards provider ids (including from order polling and `addPrecreatedOrder` stubs) to the service without stripping the prefix. ([#8278](https://github.com/MetaMask/core/pull/8278))
18+
- `RampsService.getOrder` and `getOrderFromCallback` accept provider codes with or without a `/providers/` prefix; API paths use the short provider segment. `RampsController` forwards provider ids from order polling to the service without stripping the prefix. ([#8278](https://github.com/MetaMask/core/pull/8278))
19+
20+
### Fixed
21+
22+
- `addPrecreatedOrder` normalizes `providerCode` (stripping a leading `/providers/` when present) and sets stub `provider.id` to `/providers/{code}` so precreated stubs match the resource id shape used elsewhere for polling. ([#8289](https://github.com/MetaMask/core/pull/8289))
1923

2024
## [12.0.1]
2125

packages/ramps-controller/src/RampsController.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5466,7 +5466,7 @@ describe('RampsController', () => {
54665466
expect(controller.state.orders).toHaveLength(1);
54675467
const stub = controller.state.orders[0];
54685468
expect(stub?.providerOrderId).toBe('abc123');
5469-
expect(stub?.provider?.id).toBe('paypal');
5469+
expect(stub?.provider?.id).toBe('/providers/paypal');
54705470
expect(stub?.walletAddress).toBe('0xabc');
54715471
expect(stub?.status).toBe(RampsOrderStatus.Precreated);
54725472
});

packages/ramps-controller/src/RampsController.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1965,10 +1965,12 @@ export class RampsController extends BaseController<
19651965
if (!orderCode?.trim()) {
19661966
return;
19671967
}
1968+
const normalizedProviderCode = normalizeProviderCode(providerCode);
1969+
19681970
const stubOrder: RampsOrder = {
19691971
providerOrderId: orderCode,
19701972
provider: {
1971-
id: providerCode,
1973+
id: `/providers/${normalizedProviderCode}`,
19721974
name: '',
19731975
environmentType: '',
19741976
description: '',

0 commit comments

Comments
 (0)