-
-
Notifications
You must be signed in to change notification settings - Fork 267
refactor: update RampsController with selectedProvider and selectedToken #7734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
| logos: ProviderLogos; | ||
| supportedCryptoCurrencies: Map<string, boolean>; | ||
| supportedFiatCurrencies: Map<string, boolean>; | ||
| supportedPaymentMethods: Map<string, boolean>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provider type uses Map for JSON data fields
Low Severity
The Provider type adds three new required fields (supportedCryptoCurrencies, supportedFiatCurrencies, supportedPaymentMethods) typed as Map<string, boolean>. However, these fields come from JSON API responses parsed via fetchResponse.json(), which produces plain JavaScript objects, not Map instances. If any code attempts to use Map methods (like .get(), .has(), .entries()) on these fields, it would fail at runtime. Additionally, these fields aren't used anywhere in the codebase, making them unused type definitions.
| (pm: PaymentMethod) => pm.id === state.selectedPaymentMethod?.id, | ||
| ); | ||
| if (!currentSelectionStillValid) { | ||
| state.selectedPaymentMethod = response.payments[0] ?? null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Race condition when rapidly changing token/provider selection
Medium Severity
When setSelectedToken or setSelectedProvider is called, it triggers getPaymentMethods asynchronously. If the user rapidly changes their selection, multiple requests with different cache keys run in parallel. When responses arrive out of order, state.paymentMethods is unconditionally overwritten without verifying it still matches the current selectedToken/selectedProvider. This can result in showing payment methods for a previously selected token while the UI shows a different selected token.
Explanation
This PR refactors the RampsController to improve naming consistency and add token selection support.
Breaking Changes
preferredProvidertoselectedProvider: Aligns naming with the newselectedTokenstate for consistency across selected entitiesgetPaymentMethodssignature: Changed fromgetPaymentMethods(options)togetPaymentMethods(region, options)to match the pattern used bygetTokensandgetProvidersNew Features
selectedTokenstate: Stores the user's selected token withsetSelectedToken()method. When a token is selected, payment methods are automatically fetched for that tokenRampsEnvironment.Local: New environment option for RampsService that points tolocalhost:3000for local developmentReferences
https://consensyssoftware.atlassian.net/browse/TRAM-3232
Checklist
Note
Introduces token selection and aligns provider naming, plus updates payment-methods API usage and service environments.
preferredProvider→selectedProviderandsetPreferredProvider()→setSelectedProvider(); clear on region changegetPaymentMethods(options)→getPaymentMethods(region, options);triggerGetPaymentMethodssignature updated accordinglyselectedTokenstate withsetSelectedToken(); auto-fetches payment methods (andgetPaymentMethodsnow defaultsassetId/providerfromselectedToken/selectedProvider)getPaymentMethodsnow setsselectedPaymentMethodto the first returned method when current selection is missing; preserves when still valid; handles empty returnsRampsEnvironment.Localand optionalbaseUrlOverride; switch payments endpoint tov2/regions/{region}/paymentsand queryassetId→crypto; Provider type includessupported*mapsWritten by Cursor Bugbot for commit 9d0e8f6. This will update automatically on new commits. Configure here.