Skip to content

Conversation

@georgeweiler
Copy link
Contributor

@georgeweiler georgeweiler commented Jan 23, 2026

Explanation

Reorganizes RampsController initialization to separate critical startup data from region-specific data fetching. This change improves app startup performance by deferring non-essential data fetching until the wallet home page loads.

Additionally, there are interface updates as the API now returns countries with supported: { buy: true, sell: true }.

Changes

  • init() method: Now only fetches geolocation and countries (24h TTL) on engine instantiation
  • hydrateState() method: New method that fetches providers and tokens for the user's region, called on wallet home page load
  • Countries state: Added countries: Country[] to controller state with 24 hour TTL caching
  • getCountries(): Removed action parameter - API now returns buy/sell support info in a single response
  • setUserRegion(): Refactored to use countries from state instead of fetching them
  • SupportedActions type: New type { buy: boolean; sell: boolean } for region support info
  • Country.supported / State.supported: Changed from boolean to SupportedActions object

Benefits

  • Faster app startup - only essential data (geolocation) fetched during initialization
  • Better separation of concerns - region-specific data fetched when needed
  • Improved caching - countries stored in state with 24h TTL, reducing redundant API calls
  • Cleaner architecture - prepares for mobile integration where hydrateState() will be called on wallet page load
  • Fixes bug where setUserRegion() could fail if sell countries were fetched after init

References

https://consensyssoftware.atlassian.net/browse/TRAM-3230

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

Scope

  • Reworks init() to fetch only getGeolocation and getCountries (saved to state.countries with TTL caching); defers region-specific data.
  • Adds hydrateState() to asynchronously fetch tokens and providers for the current userRegion.

API/Type updates (BREAKING)

  • Country.supported and State.supported changed from boolean to SupportedActions ({ buy; sell }).
  • getCountries() no longer accepts an action parameter; service/controller updated accordingly.
  • setUserRegion() now resolves strictly from state.countries and triggers token/provider fetches; cleans dependent state on region change.

Other

  • Adds countries: Country[] to controller state (persisted, exposed to UI).
  • Removes updateUserRegion and associated trigger; introduces hydrateState and updated trigger methods.
  • Updates tests and exports to reflect new behavior and types.

Written by Cursor Bugbot for commit 74a0e27. This will update automatically on new commits. Configure here.

…geolocation and countries, add countries to state, and create hydrateStore() for providers/tokens
@georgeweiler georgeweiler marked this pull request as ready for review January 23, 2026 03:11
@georgeweiler georgeweiler requested review from a team as code owners January 23, 2026 03:11
@georgeweiler
Copy link
Contributor Author

cursor review

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@georgeweiler georgeweiler changed the title feat: Reorganize RampsController initialization feat(ramps): Reorganize RampsController initialization Jan 23, 2026
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Copy link

@cursor cursor bot left a comment

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 and found 1 potential issue.

if (country.states && country.states.length > 0) {
const hasSupportedState = country.states.some(
(state) => state.supported !== false,
(state) => state.supported?.buy ?? state.supported?.sell,
Copy link

Choose a reason for hiding this comment

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

Nullish coalescing incorrectly filters sell-only supported states

High Severity

The state filtering logic uses ?? (nullish coalescing) instead of || (logical OR) to check for buy/sell support. When a state has supported: { buy: false, sell: true }, the expression state.supported?.buy ?? state.supported?.sell evaluates to false because false is not nullish. This incorrectly filters out states that only support sell operations, making sell functionality unavailable in those regions. The country-level check correctly uses || on line 622-623, but the state check is inconsistent.

Fix in Cursor Fix in Web

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants