feat: sync V2 ramps orders from User Storage#44367
Conversation
Wire RampsController order syncing so orders created on mobile can be pulled into the extension on unlock, without adding ramps UI. Co-authored-by: Cursor <cursoragent@cursor.com>
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
✨ Files requiring CODEOWNER review ✨🔑 @MetaMask/accounts-engineers (8 files, +404 -5)
👨🔧 @MetaMask/money-movement (9 files, +550 -16)
|
Builds ready [1f54a22]
⚡ Performance Benchmarks (Total: 🟢 17 pass · 🟡 0 warn · 🔴 0 fail)
Bundle sizes
|
Match mobile by exposing a Buy & sell orders sub-toggle, and include ramps syncing in the reverse-cascade that disables the main Backup & Sync switch when every sub-feature is off. Co-authored-by: Cursor <cursoragent@cursor.com>
Builds ready [5b063e4]
⚡ Performance Benchmarks (Total: 🟢 17 pass · 🟡 0 warn · 🔴 0 fail)
Bundle sizes
|
Required after merging main so RampsController can read moneyHeadlessAllProviders for quote widening alongside order sync. Co-authored-by: Cursor <cursoragent@cursor.com>
Builds ready [bd074e8]
⚡ Performance Benchmarks (Total: 🟢 17 pass · 🟡 0 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
…into feat/ramps-order-syncing
Open a background Portfolio tab to upload Buy history, re-sign into DEV Profile Sync, sync all HD entropy sources, and prefer the prior provider (with /providers/ id normalize) instead of defaulting to Transak. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 4182484. Configure here.
| } catch (signOutError) { | ||
| console.error('performSignOut before migrate sync failed', signOutError); | ||
| } | ||
| await submitRequestToBackground('performSignIn'); |
There was a problem hiding this comment.
Buy migration signs users out
High Severity
runPortfolioBuyOrdersMigration always calls performSignOut then performSignIn before syncing, though the comment targets stale tokens in local DEV Profile Sync. On production builds, a first native Buy can sign the profile out; if performSignIn fails, sync is skipped while the session may stay signed out until another sign-in path runs, disrupting Backup & Sync during Buy.
Reviewed by Cursor Bugbot for commit 4182484. Configure here.
| // migrate+sync (previous bug: invalid token still marked done → permanent Transak). | ||
| if (syncSucceeded) { | ||
| await markPortfolioBuyOrdersMigrationCompleted(); | ||
| } |
There was a problem hiding this comment.
Migration completes without Portfolio done
Medium Severity
When the background Portfolio tab never posts the migrate-done URL, waitForMigrateDone still resolves after the timeout, the tab is closed, and a successful User Storage sync marks migration complete. Portfolio localStorage orders may never upload, yet retries are permanently disabled.
Reviewed by Cursor Bugbot for commit 4182484. Configure here.
Builds ready [4182484]
⚡ Performance Benchmarks (Total: 🟢 13 pass · 🟡 8 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|


Summary
RampsController.syncOrdersWithUserStorage()can run.syncRampsOrdersWithUserStorageon the ramps background API.useRampsOrderSyncinginMetamaskIdentityProvider(same gates as account/contact sync).selectIsRampsSyncingEnableddefaults totruewhen absent from persisted state.BACKUPANDSYNC_FEATURES.rampsSyncing), matching mobile.RampsController.orders/ existing hooks and selectors (no dedicated orders history UI in this PR).Depends on
Works with
QA / debugging (separate branch)
Orders home-tab demo for manual verification lives on
feat/ramps-orders-qa-tab(not included here). Use that branch to inspect synced orders and trigger manual sync during cross-client testing.Cross-client flow
useRampsOrderSyncingruns full sync.useRampsOrders/selectRampsOrders.Local testing (until core packages are published)
Copy built packages from core
feat/ramps-order-syncinginto extensionnode_modules:Then:
RampsController.orders(or usefeat/ramps-orders-qa-tabOrders tab)Test plan
useRampsOrderSyncing, identity provider, selectors@metamask/ramps-controller+@metamask/profile-sync-controlleronce core Allow running CircleCI locally #9474 is publishedNote
Medium Risk
Touches authentication (sign-out/sign-in around migrate sync), User Storage, and cross-client order data; failures are mostly logged and retried, but wrong env/auth could block sync until retry.
Overview
Wires V2 ramps buy/sell order sync through User Storage: the ramps messenger delegates User Storage, auth, and feature-flag actions; the background API exposes
syncRampsOrdersWithUserStorage; anduseRampsOrderSyncingruns a full sync fromMetamaskIdentityProviderwhen the same gates as account/contact sync pass (signed in, unlocked, Backup & Sync on, ramps sub-feature enabled).Adds a Buy & sell orders Backup & Sync sub-toggle (i18n + UI), includes ramps in the “all sub-features off → disable main” cascade, and
selectIsRampsSyncingEnableddefaults to true when missing from persisted state.For wallets that ever connected to Portfolio, native goToBuy runs a one-shot silent migration: background Portfolio tab uploads local buy orders, then User Storage sync pulls into the extension; migration completion is stored only after sync succeeds. Provider auto-selection re-runs when synced completed orders arrive, with normalized provider ids so Portfolio
/providers/...paths match the extension catalog.Local dev:
loadAuthenticationConfiguses Profile Sync DEV for development/testing builds so buy-widget JWTs and order-sync e2e align with staging Portfolio.Reviewed by Cursor Bugbot for commit 4182484. Bugbot is set up for automated code reviews on this repo. Configure here.