## Explanation
Adds an optional `isNetworkAllowed` constructor option to
`RampsController` so the host can block RampsController network access
at runtime.
Every method that can reach the network checks the option before any
state write or request, and throws an error carrying the new
`RAMPS_ERROR_CODES.NETWORK_ACCESS_DENIED` code when it returns `false`.
Denied calls do not serve non-expired request-cache entries either, so
hosts render already-fetched data from controller state while access is
denied.
`addOrder`, `addPrecreatedOrder`, `removeOrder`, and `transakLogout`
still apply their local change and skip only the remote call; deferred
order writes are picked up by the next full sync. Order polling pauses
while access is denied without extending its backoff. Omitting the
option keeps the existing behavior.
## References
Client PR: MetaMask/metamask-extension#47843
## Checklist
- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] 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]
> **Medium Risk**
> Touches many network entry points plus order sync and polling;
incorrect host wiring could block ramps or leave remote state briefly
stale until the next sync, though defaults preserve prior behavior.
>
> **Overview**
> Adds an optional host-controlled **`isNetworkAccessAllowed`** callback
to `RampsController` so ramps can be blocked from reaching the network
at runtime without changing default behavior when it is omitted.
>
> **Gated methods** call **`#assertNetworkAccessAllowed()`** up front
(including **`executeRequest`**, so the exposed action cannot bypass the
gate). Denied calls throw with **`errorKey: NETWORK_ACCESS_DENIED`**,
skip messenger/service requests, avoid state writes on reads, and **do
not return cached request results** while denied—UI is expected to read
already-loaded data from controller state.
>
> **Exceptions** still apply local-only work when denied:
**`addOrder`**, **`addPrecreatedOrder`**, and **`removeOrder`** update
state but defer User Storage incremental sync until the next allowed
**`syncOrdersWithUserStorage`**; **`transakLogout`** clears the local
Transak session without calling the API; order polling **skips refresh**
without advancing error backoff. Full sync aborts queued follow-up
passes if access is revoked mid-sync.
>
> Docs, changelog, messenger JSDoc, and broad unit tests cover gate
classification, deferred sync, and polling behavior.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
1e6f645. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Description
Ramps network access was enforced by wrapping every
RampsControllernetwork method after construction. That duplicated the policy the UI already needed for order syncing, and wrapping methods made the gate easy to miss whenever the controller grew a new call.This moves the policy into
shared/lib/ramps/network-access.ts, read by the background controller and by ramps order syncing, and hands it to the controller throughisNetworkAccessAllowed. The controller no longer calls the ramps API until onboarding is complete and basic functionality is on, and it re-reads that state on every check, so turning basic functionality off takes effect without a restart. The per-method wrapper and its tests are deleted.Ramps order syncing now runs from
RampsBootstrapand lives underui/hooks/ramps/instead ofui/hooks/identity/, so money movement owns the whole sync path. It uses the same predicate and layers backup-and-sync on top, which removes the duplicated onboarding check there. Non-production builds also shorten the controller request cache TTL to 60 seconds so a fresh request can be observed while manually testing the gate; production keeps the controller default.@metamask/ramps-controller@30.0.0is the release that exposesisNetworkAccessAllowedandrequestCacheTTL. A@metamask/ramps-controller@^29.0.0resolution points the copy used by@metamask/transaction-pay-controller(which still asks for^29.0.0until its next bump) at the same version, keeping one copy and dropping the duplicate LavaMoat policy entry.Changelog
CHANGELOG entry: null
Related issues
Core PR: MetaMask/core#11222
Why now: #47325 (comment)
Manual testing steps
Screenshots/Recordings
After
ramps-bf-gate-refactor.mp4
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Changes how and when ramps hits external APIs based on onboarding and privacy settings; behavior is covered by new tests but regressions would affect buy-flow hydration and order sync.
Overview
Ramps API access is now gated inside
@metamask/ramps-controller@30.0.0viaisNetworkAccessAllowedinstead of wrapping controller methods after construction. The onboarding + basic-functionality rule lives inshared/lib/ramps/network-access.tsso the background init path and UI stay aligned;ramps-network-gateand its tests are removed.RampsControllerInitpasses a callback that re-reads onboarding and preferences on every check (privacy toggles apply without restart), sets a 60srequestCacheTTLin non-production for easier manual gate testing, and leaves production on the controller default. Order syncing is triggered fromRampsBootstrap(notMetamaskIdentityProvider), withuseRampsOrderSyncingusing the same shared network predicate plus backup-and-sync gates.Dependency bumps include a resolution so dependents still on
^29.0.0resolve to 30.0.0, with matching LavaMoat policy updates.Reviewed by Cursor Bugbot for commit 76ca99a. Bugbot is set up for automated code reviews on this repo. Configure here.