Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ord validation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| * Follows the `AiDigestService` pattern: plain class with `baseUrl` config, | ||
| * direct `fetch()` calls, and superstruct response validation. | ||
| */ | ||
| export class SocialService implements SocialDataService { |
There was a problem hiding this comment.
Our team recently released the BaseDataService class under @metamask/base-data-service. This superclass is designed to represent our latest patterns and best practices for fetching data that we've developed in collaboration with other teams. Would you mind implementing this in your class?
- You can learn more about data service classes here: https://www.notion.so/metamask-consensys/Data-Services-Pattern-330f86d67d688059b5dfe2eccd98a1aa.
- You can see an example data service class along with its tests here: https://github.com/MetaMask/core/blob/bb9a7bc6e1751b406097846e6166c8798788de57/packages/sample-controllers/src/sample-gas-prices-service/sample-gas-prices-service.ts. Also you can see how data service types get exported here:
core/packages/sample-controllers/src/index.ts
Lines 1 to 10 in bb9a7bc
The main things are:
- Data services inherit from
BaseDataService. - They have a messenger associated with them. This allows the service to used anywhere within a client without needing a direct reference to the instance of the class itself.
SampleGasPricesServicehas an example of how to set up the types for this as well as the constructor and expose methods on your class through the messenger. - In each method you are making a request, you do this:
- Use
fetchQueryand pass aqueryKeythat matches the name of the method in<ServiceName>:<method>format. - Inside of the
queryFn, you callfetch, throwing if the response is not 200. (If there is an HTTP error you want to represent, useHttpErrorfrom@metamask/controller-utils:)core/packages/controller-utils/src/util.ts
Line 407 in 157d483
- Outside of
fetchQuerycall, you validate the response and throw an error if it is not valid.
- Use
There was a problem hiding this comment.
Ok happy to adopt the new pattern, this is great stuff! Just wanted to flag that the SampleGasPricesService you linked doesn't extend BaseDataService yet, so we initially followed its pattern (along with AiDigestService). I'll use the notion doc and ExampleDataService from base-data-service/tests as our reference going forward.
| ); | ||
| return response.json(); | ||
| }, | ||
| }); |
There was a problem hiding this comment.
Mutation operations cached by fetchQuery skip repeated requests
High Severity
The follow (PUT) and unfollow (DELETE) methods wrap their HTTP requests in this.fetchQuery, which delegates to QueryClient.fetchQuery from @tanstack/query-core. This caches results keyed by queryKey and returns stale-but-fresh data without re-executing queryFn. BaseDataService sets a default staleTime of 1 minute, so calling follow or unfollow with the same parameters within that window silently returns the cached response — the actual HTTP request is never sent. Write operations must not be cached this way.
Additional Locations (1)
There was a problem hiding this comment.
@mcmire This unresolved bugbot comment brings up an interesting gap in the new BaseDataService. It only exposes fetchQuery and fetchInfiniteQuery, which are read-oriented (TanStack Query caches results by queryKey). Our follow and unfollow methods are write operations (PUT/DELETE) that shouldn't be cached or deduplicated (else they'll never return new data). We worked around this with staleTime: 0, but that still feels like a read API being used for writes. Is there a recommended pattern for mutations in data services, or would it make sense to add something like executeMutation to BaseDataService?
…ibility Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…esponses Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
## Explanation Adds SocialController — a BaseController extension that manages social trading state for the extension UI. Consumes the SocialService from TSA-317 and exposes 4 messenger actions for leaderboard and follow state management. ### Why no TTL or caching logic The controller acts as a simple store — no TTL, no eviction, no staleness checks. The social-api already caches upstream (leaderboard at 5min, positions at 30s), and the UI knows best when to re-fetch (screen focus, pull-to-refresh, user actions). Double-caching adds complexity without meaningful benefit. State is persisted across sessions so the UI can render immediately on startup while a fresh fetch is in flight. See CHANGELOG.md for the full list of additions. <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> ## 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] > **Medium Risk** > Adds a new persisted `BaseController` with messenger-exposed methods that update stored follow/leaderboard state, which could affect UI behavior and state persistence if wiring or state updates are incorrect. Changes are scoped to the new `@metamask/social-controllers` package with good test coverage. > > **Overview** > Introduces **`SocialController`** (a `BaseController`) that persists social trading UI state and exposes messenger actions `updateLeaderboard`, `followTrader`, `unfollowTrader`, and `updateFollowing`, updating `leaderboardEntries` and `followingAddresses` based on `SocialService` responses. > > Exports the new controller/types from `index.ts`, adds `SocialControllerState` to `social-types`, and wires in the `@metamask/base-controller` dependency/TS project references. Adds comprehensive unit tests covering state updates, messenger callability, and error propagation, and updates the changelog accordingly. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit a6a3c13. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
No dependency changes detected. Learn more about Socket for GitHub. 👍 No dependency changes detected in pull request |
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |


Explanation
Adds SocialService — a stateless data service that wraps all social-api endpoints with TypeScript types and superstruct response validation. This is the data layer that a future SocialController (TSA-318) will consume.
We intentionally shipped the service without the controller so callers can weigh in on what state shape and messenger actions they actually need before we wire up BaseController. The service stands on its own and can be used directly for testing integration with the social-api once it's deployed.
See CHANGELOG.md for the full list of additions.
References
Checklist
Note
Medium Risk
Introduces new network-facing
SocialServiceendpoints with runtime schema validation and a persisted-stateSocialController, so integration/caching/state update semantics could impact consumers despite being additive.Overview
Adds a new
SocialService(extendsBaseDataService) that wraps social-api endpoints (leaderboard, trader profile, positions, followers/following, follow/unfollow) withsuperstructresponse validation and consistentHttpErrorhandling, and exposes these methods over the messenger.Adds a new
SocialController(extendsBaseController) that persists simple UI state (leaderboardEntries,followingAddresses) and provides messenger-callable actions toupdateLeaderboard,followTrader,unfollowTrader, andupdateFollowingby delegating toSocialService.Updates package exports/tests/changelog, and adds required dependencies plus TS project references to support the new controller/service architecture.
Written by Cursor Bugbot for commit 26038d8. This will update automatically on new commits. Configure here.