fix: MUSD-282 Add useTokensBuyability hook#25539
Conversation
|
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. |
…-ramps-tokens-api-endpoint
…-ramps-tokens-api-endpoint
…-ramps-tokens-api-endpoint
| */ | ||
| export function useRampTokens(): UseRampTokensResult { | ||
| export function useRampTokens( | ||
| { fetchOnMount }: UseRampTokensOptions = { fetchOnMount: true }, |
There was a problem hiding this comment.
fetchOnMount: true by default for backwards compatibility.
…-ramps-tokens-api-endpoint
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.
| export function getTokenBuyabilityKey(token: TokenI): string { | ||
| const caipChainId = getTokenCaipChainId(token); | ||
| return `${caipChainId}:${token.address.toLowerCase()}`; | ||
| } |
There was a problem hiding this comment.
Buyability keys mismatch across token formats
Low Severity
getTokenBuyabilityKey lowercases and concatenates token.address even when it is already a CAIP asset id, so equivalent tokens represented as CAIP vs hex+chain generate different keys. This can make buyabilityByTokenKey lookups return false negatives when callers mix token representations across useTokensBuyability inputs and reads.
Additional Locations (1)
|
Is it possible to add a small loom video to show how it is working? |
Sure thing @amitabh94 - here it is. https://www.loom.com/share/ef9929d2e19743ffba33b2b7a226b0d2 I'm mainly trying to avoid duplicate network requests since the legacy |
…-ramps-tokens-api-endpoint
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
The changes are internal refactoring that maintain backwards compatibility. The external API of
SmokeRamps is the appropriate tag as it covers fiat on-ramp (buy crypto) and off-ramp (sell crypto) features, which directly use these hooks. The changes don't affect wallet platform features, confirmations, or other areas significantly enough to warrant additional tags. Performance Test Selection: |
The committed fixture schema is out of date. To update, comment: |
|





Description
This PR introduces
useTokensBuyability(tokens)to evaluate buyability for multiple tokens in a single hook call, and keepsuseTokenBuyability(token)as a backward-compatible convenience wrapper over the batch hook.useTokensBuyabilityreturns buyability asbuyabilityByTokenKey(keyed by normalized chain + token address).Motivation: reduce redundant legacy ramp token fetches when checking multiple tokens in the same render path. Previously, calling
useTokenBuyabilityN times could trigger repeated legacy useRampTokens mount-driven fetch behavior.This change also preserves V2 efficiency by passing
fetchOnMount: !isV2Enabled, so the legacy fetch is suppressed when unified buy V2 is enabled and controller-backed tokens are used.Changelog
CHANGELOG entry: refactored Ramp buyability to add batched useTokensBuyability with keyed results and keep useTokenBuyability as a backward-compatible wrapper, reducing redundant legacy token-cache fetches for multi-token checks.
Related issues
Fixes: MUSD-282: mUSD Asset List CTA is spamming the Ramps Tokens API endpoint
Manual testing steps
Screenshots/Recordings
Before
N/A
After
When
MM_RAMPS_UNIFIED_BUY_V2_ENABLED="true"useMusdRampAvailabilityleverages ramp token cache.Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Changes Ramp buyability evaluation and when the legacy token-cache API is fetched; regressions could hide/show buy CTAs incorrectly or delay buyability data if the new fetch gating is misused.
Overview
Introduces
useTokensBuyability(tokens)and supporting helpers (e.g.,getTokenBuyabilityKey) to compute Ramp buyability for multiple tokens in one hook call, while keepinguseTokenBuyability(token)as a backward-compatible wrapper.Adds a
fetchOnMountoption touseRampTokensand uses it from buyability logic to skip legacy token-cache fetching when Unified Ramps V2 is enabled, reducing repeated API calls.Refactors
useMusdRampAvailabilityto derive per-chain mUSD buyability viauseTokensBuyability(using mUSD token addresses per chain), and updates/expands tests across Ramp and Earn hooks to cover the new batching and fetch gating behavior.Written by Cursor Bugbot for commit 437bc20. This will update automatically on new commits. Configure here.