Skip to content

Batch wallet coin balance fetches via getUserCoins#14136

Draft
dylanjeffers wants to merge 3 commits intomainfrom
cursor/batch-wallet-user-coin-fetches-e37e
Draft

Batch wallet coin balance fetches via getUserCoins#14136
dylanjeffers wants to merge 3 commits intomainfrom
cursor/batch-wallet-user-coin-fetches-e37e

Conversation

@dylanjeffers
Copy link
Copy Markdown
Contributor

@dylanjeffers dylanjeffers commented Apr 17, 2026

Summary

Wallet rows were each calling useUserCoin, which issued one GET /v1/users/{id}/coins/{mint} per mint, even right after GET /v1/users/{id}/coins loaded the same balances.

This update follows the collections-style pattern more closely:

  1. Cache priming — When useUserCoins completes, it calls primeUserCoinQueriesFromList, which seeds each per-mint useUserCoin query key with aggregate fields from the list (balance, decimals, etc.) and empty accounts. Keys that already have data are left alone (so a full getUserCoin response is never overwritten). Child rows then read initialData from the cache while the batched detail fetch runs.

  2. BatcheruseUserCoin now uses getUserCoinBatcher (batshit windowScheduler(10)), so many mints requested in the same tick are deduped and fetched with parallel getUserCoin calls inside one batch window, each result written back to the query cache.

  3. Reverted the useCoinBalance / useFormattedCoinBalance “list override” API; the wallet list again uses the normal useUserCoin path.

USER_COINS_WALLET_LIST_PARAMS (limit: 100) remains on wallet useUserCoins so one stable query key is used.

Test plan

  • Wallet with many coins: after list loads, rows show aggregate balances quickly; network shows batched/deduped getUserCoin rather than N unrelated timings.
  • Coin detail external wallets: still receives full accounts after fetch.
  • Send/swap flows that invalidate getUserCoinQueryKey still behave.
Open in Web Open in Cursor 

Wallet rows called useFormattedCoinBalance per mint, each triggering
getUserCoin. Reuse the paginated getUserCoins response (already fetched
for the list) when aggregate balance is sufficient, with per-mint
fallback if a mint is missing from the loaded page.

Co-authored-by: Dylan Jeffers <dylanjeffers@users.noreply.github.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 17, 2026

⚠️ No Changeset found

Latest commit: 25343d7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

cursoragent and others added 2 commits April 17, 2026 22:39
Export USER_COINS_WALLET_LIST_PARAMS and use the same limit/offset in
WalletCoinsList, YourCoins, and useCoinBalance so React Query dedupes
to a single getUserCoins request.

Co-authored-by: Dylan Jeffers <dylanjeffers@users.noreply.github.com>
- Move getUserCoinQueryKey to userCoinQueryKey for reuse
- After getUserCoins, prime per-mint userCoin cache (aggregate-only stub)
- Route useUserCoin through batshit batcher so parallel mints coalesce
- Revert useCoinBalance list override; wallet uses normal useUserCoin flow

Co-authored-by: Dylan Jeffers <dylanjeffers@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

🌐 Web preview ready

Preview URL: https://audius-web-preview-pr-14136.audius.workers.dev

Unique preview for this PR (deployed from this branch).
Workflow run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants