Commit 915a340
authored
feat(ramps): add providers state and getProviders method to RampsController (#7652)
## Explanation
<!--
Thanks for your contribution! Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:
* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?
* Are there any changes whose purpose might not obvious to those
unfamiliar with the domain?
* If your primary goal was to update one package but you found you had
to update another one along the way, why did you do so?
* If you had to upgrade a dependency, why did you do so?
-->
## Add providers state and getProviders method to RampsController
Adds `providers` state to RampsController and fetches providers from the
V2 API endpoint.
**Changes:**
- Added `providers: Provider[]` to `RampsControllerState`
- Added `getProviders()` method to `RampsService` that calls
`/v2/regions/:regionCode/providers` with optional filters (provider,
crypto, fiat, payments)
- Added `getProviders()` method to `RampsController` with caching and
state management
- Providers are automatically fetched on `init()` when a region is
available
- Providers are automatically refetched when the region changes in
`updateUserRegion()` and `setUserRegion()`
- Providers are cleared when the region is cleared or changed
**Testing:**
- Added comprehensive tests for `getProviders` functionality
- Updated existing tests to include providers in state snapshots
- All 74 tests passing
## References
<!--
Are there any issues that this pull request is tied to?
Are there other links that reviewers should consult to understand these
changes better?
Are there client or consumer pull requests to adopt any breaking
changes?
For example:
* Fixes #12345
* Related to #67890
-->
https://consensyssoftware.atlassian.net/browse/TRAM-3153
## 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](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Adds provider fetching and state management across the ramps stack.
>
> - **RampsService**: New `getProviders(regionCode, { provider, crypto,
fiat, payments })` calling `v2/regions/:regionCode/providers`; validates
responses; exposed via messenger (`RampsService:getProviders`).
> - **RampsController**: New `providers` in state and `getProviders()`
with request caching and region normalization; integrates into `init()`,
`updateUserRegion()`, and `setUserRegion()`; clears `providers` (and
`tokens`) when region changes or fetch fails; persisted and included in
metadata.
> - **Tests**: Comprehensive tests for provider API, controller
integration, caching, filters, and state snapshots; selector tests
updated; changelog updated.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
cca85b7. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 9edeb53 commit 915a340
File tree
7 files changed
+820
-7
lines changed- packages/ramps-controller
- src
7 files changed
+820
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
0 commit comments