Skip to content

feat(social-controllers): route trader reads to the signed-in user's own route - #11325

Draft
xavier-brochard wants to merge 4 commits into
mainfrom
feat/social-trader-me-routes
Draft

xavier-brochard wants to merge 4 commits into
mainfrom
feat/social-trader-me-routes

Conversation

@xavier-brochard

@xavier-brochard xavier-brochard commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Explanation

Five existing SocialService methods are now viewer-aware: fetchTraderProfile, fetchOpenPositions, fetchClosedPositions, fetchTraderFeed, and fetchPositionById. When the trader is the signed-in user, they call the backend's GET /v1/traders/me/... routes, which include private trading. Otherwise they call the public routes.

Mobile callers should not have to choose between the owner and public routes themselves, because picking the wrong one is easy to do. The choice now lives inside SocialService, so callers cannot pick the wrong route.

What changed:

  • The signed-in viewer's sub is read from the bearer token, for routing only. The server still verifies the token.
  • fetchPositionById accepts an optional profileId. When it is set, the route is chosen from it directly. Without it, the owner route is tried first, and the public route is used on a 404.
  • fetchTraderProfile matches by profile ID. A wallet address never matches the signed-in user, so pass the profile ID to get your own profile. If the owner route returns a profile other than the one requested, it throws.
  • New exported TradingPrivacy type ('public' | 'private') and an optional tradingPrivacy field on TraderProfileResponse. TraderProfileResponseStruct validates the field, and responses from backends that omit it still parse.

Behaviour change: owners of private trading now get their own positions and feed from the existing method names. This is documented under Changed in the CHANGELOG. No public method was removed or renamed.

Backend dependency: the /v1/traders/me/* routes are implemented in va-mmcx-social-api (TSA-1333, TSA-1334). The backend PRs are being opened separately. The backend /v1/traders/me/* routes must be deployed before this Core release is published.

Testing:

  • yarn workspace @metamask/social-controllers run test:coverage: 301 tests passing, 100% coverage.
  • yarn lint: passed.
  • yarn changelog:validate: passed.
  • Messenger action types regenerated (SocialService-method-action-types.ts).

References

  • Refs TSA-1333
  • Refs TSA-1334
  • Backend /v1/traders/me/* routes in va-mmcx-social-api, which must be deployed before this Core release is published.

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

Note

Medium Risk
Changes how authenticated reads resolve routes and cache keys for trading privacy; wrong routing could hide or expose data until the server enforces authorization on /traders/me/*.

Overview
SocialService now picks owner vs public social-api routes for five trader read methods, so clients keep the same APIs while signed-in users can see private trading on their own data.

When the requested trader matches the bearer token’s sub (profile ID only—wallet addresses never count as “self”), calls go to GET …/traders/me/… for profile, open/closed positions, trader feed, and position-by-id. Other traders still use the public paths. fetchPositionById gains optional profileId for direct routing; without it, the service tries /traders/me/position/… first and falls back to the public route on 404. fetchTraderProfile throws if the owner route returns a different profile than requested. Per-user /me responses use staleTime: 0 so cached data is not shared across viewers.

Also adds exported TradingPrivacy and optional tradingPrivacy on TraderProfileResponse, plus FETCH_TRADER_PROFILE_MISMATCH, with broad unit tests for JWT parsing edge cases and routing.

Reviewed by Cursor Bugbot for commit 4e03580. Bugbot is set up for automated code reviews on this repo. Configure here.

…own route

fetchTraderProfile, fetchOpenPositions, fetchClosedPositions, fetchTraderFeed, and fetchPositionById are viewer-aware. When the trader is the signed-in user they call GET /v1/traders/me/... (which includes private trading); otherwise they call the public route. The choice stays inside SocialService so callers cannot pick the wrong one. The viewer is read from the bearer token's sub.

fetchPositionById accepts an optional profileId to route directly.

Add TradingPrivacy and an optional tradingPrivacy on TraderProfileResponse, validated by TraderProfileResponseStruct. Regenerate the messenger action types.

Co-authored-by: Cursor <cursoragent@cursor.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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 8e099f3. Configure here.

Co-authored-by: Cursor <cursoragent@cursor.com>
@xavier-brochard
xavier-brochard marked this pull request as draft November 5, 2026 20:04
xavier-brochard and others added 2 commits November 5, 2026 21:12
… position

Without a profileId, fetchPositionById probed the signed-in user's own route first. A 404 there was thrown as an error, so the default service policy retried it before the public fallback ran. The probe now resolves a 404 as null, so the miss is not retried. Owner 200s, owner 500s, and the public fallback on 404 are unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
The changelog check in CI requires an Unreleased entry that links to the current PR. Link the three new entries to #11325 and note that the owner-route 404 is not retried.

Co-authored-by: Cursor <cursoragent@cursor.com>

This branch was previously deployed

1 inactive (outdated) deployment
default-branch — 8e099f33 Deployed Nov 5, 2026 by xavier-brochard via Determine whether this PR is a release PR #6570
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant