Skip to content

Conversation

@georgeweiler
Copy link
Contributor

@georgeweiler georgeweiler commented Jan 29, 2026

Explanation

  • Restructured RampsControllerState to use nested ResourceState objects for each resource type: userRegion, countries, providers, tokens, paymentMethods, and quotes
  • Each resource now contains data, selected, isLoading, and error properties in a single object
  • Removed all trigger methods (e.g., fetchUserRegion) from hooks - the controller now manages fetching internally
  • Removed flat selected* properties (e.g., selectedProvider) - these are now nested within each resource

This eliminates the need for consumers to reconstruct cache keys to check loading/error states, and provides a consistent, unified structure for accessing resource data and metadata.

Before

const requestSelector = useMemo(
  () => selectPaymentMethodsRequest({ region, action, paymentMethodCurrency, ... }),
  [region, action, paymentMethodCurrency, ...]
);
const { isLoading, error } = useSelector(requestSelector);
const paymentMethods = useSelector(selectPaymentMethods);
const selectedPaymentMethod = useSelector(selectSelectedPaymentMethod);

After

const {
  data: paymentMethods,
  selected: selectedPaymentMethod,
  isLoading,
  error,
} = useSelector(selectPaymentMethods);

New State Structure

interface ResourceState<TData, TSelected = null> {
  data: TData;
  selected: TSelected;
  isLoading: boolean;
  error: string | null;
}

interface RampsControllerState {
  userRegion: ResourceState<UserRegion | null>;
  countries: ResourceState<Country[]>;
  providers: ResourceState<Provider[], Provider | null>;
  tokens: ResourceState<TokensResponse | null, RampsToken | null>;
  paymentMethods: ResourceState<PaymentMethod[], PaymentMethod | null>;
  quotes: ResourceState<QuotesResponse | null>;
  requests: RequestsState;
}

Breaking Changes

  • All resource properties are now nested objects with data, selected, isLoading, and error
  • Removed flat properties: selectedProvider, selectedToken, selectedPaymentMethod
  • Removed flat loading/error properties: userRegionLoading, userRegionError, etc.

References

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

Medium Risk
Medium risk due to a breaking state-shape change (nested ResourceState + moved selected* fields) and updated request execution to mutate per-resource loading/error flags, which can affect UI selectors and persistence semantics.

Overview
Refactors RampsControllerState to a nested ResourceState model per resource (userRegion, countries, providers, tokens, paymentMethods, quotes), moving selected*, loading, and error tracking into each resource object and updating defaults/metadata accordingly.

Extends executeRequest with resourceType to automatically maintain resource-level isLoading/error (including defaulting missing error messages to "Unknown error"), updates controller methods to read/write *.data/*.selected, and replaces the former sync trigger* APIs with an internal #fireAndForget helper.

Updates public exports (ResourceState, ResourceType, TokensResponse, RampsToken) and revises tests/snapshots to match the new state structure.

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

@georgeweiler georgeweiler changed the title Ramps loading state feat(ramps): adds top-level loading and error state to RampsController Jan 29, 2026
@georgeweiler georgeweiler marked this pull request as ready for review January 29, 2026 21:06
@georgeweiler georgeweiler requested review from a team as code owners January 29, 2026 21:06
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 2 potential issues.

@georgeweiler georgeweiler changed the title feat(ramps): adds top-level loading and error state to RampsController feat(ramps): refactor RampsControllerState to use nested objects for each resource type Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants