feat(money): implement MoneyAccountApiDataService#9402
Conversation
|
@metamaskbot publish-preview |
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.
Reviewed by Cursor Bugbot for commit fc75e0e. Configure here.
| }, | ||
| }, | ||
| options?.cursor ?? undefined, | ||
| ); |
There was a problem hiding this comment.
History cache returns wrong page
Medium Severity
fetchHistory omits cursor from the TanStack query key but can populate the infinite-query cache with a cursor-driven request as pages[0]. A later call with the same filters and no cursor goes through BaseDataService’s pageParam === undefined path and returns that cached pages[0] while data is still fresh, so the first page of cash-flow history can be wrong until stale time expires or the cache is invalidated.
Reviewed by Cursor Bugbot for commit fc75e0e. Configure here.
fc75e0e to
b3ee420
Compare
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # packages/money-account-api-data-service/CHANGELOG.md # packages/money-account-api-data-service/LICENSE # packages/money-account-api-data-service/README.md # packages/money-account-api-data-service/jest.config.js # packages/money-account-api-data-service/package.json # packages/money-account-api-data-service/src/index.ts # packages/money-account-api-data-service/tsconfig.build.json # packages/money-account-api-data-service/tsconfig.json # yarn.lock
b3ee420 to
2143e62
Compare
|
@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
The Earn team currently lacks a dedicated data service for fetching user positions, interest accruals, cash-flow history, and vault rate history from the Money Account API (vertical app hosted at
money.api.cx.metamask.io).Follow up to #9278
This PR introduces
@metamask/money-account-api-data-service, a new package that:BaseDataServiceto leverage TanStack Query caching, service policy (retries + circuit-breaking), and messenger integration out of the box.fetchPositions,fetchInterest,fetchHistory,fetchRateHistory.@metamask/superstructfor runtime response validation, with types derived from structs (Infer<typeof ...Struct>) to prevent type/struct drift.causechain) for easier production debugging.fetchInfiniteQueryfor the cursor-paginated history endpoint, giving consumers proper TanStack Query pagination semantics.retryFilterPolicyto skip retrying validation errors (malformed responses won't fix themselves).dev/uat/prd) via anEnvenum + URL map, following theclaims-controllerpattern.This is architected as an independent service. The client calls it directly for API-sourced data, separate from
money-account-balance-servicewhich handles RPC-based balance fetching. A future orchestration layer may unify these.Checklist
Note
Low Risk
New isolated package with no changes to existing controllers; risk is limited to future consumers trusting API-sourced financial display data and external API contract stability.
Overview
Adds
@metamask/money-account-api-data-service, a new Earn-team package that fetches vault positions, interest, cash-flow history, and vault rate history from the Money Account HTTP API (separate from RPC-basedmoney-account-balance-service).MoneyAccountApiDataServiceextendsBaseDataServicewith TanStack Query caching, messenger actions (fetchPositions,fetchInterest,fetchHistory,fetchRateHistory,invalidateQueries), dev/uat/prd base URLs viaEnv, and superstruct-validated responses withMoneyAccountApiResponseValidationError(no retries on validation failures). History usesfetchInfiniteQueryfor cursor pagination; other endpoints use tuned stale times aligned with server cache TTLs.Monorepo wiring updates CODEOWNERS, README, teams.json, root tsconfig references, and yarn.lock for the new workspace package.
Reviewed by Cursor Bugbot for commit ae6334b. Bugbot is set up for automated code reviews on this repo. Configure here.