Skip to content
5 changes: 0 additions & 5 deletions eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -701,11 +701,6 @@
"count": 1
}
},
"packages/core-backend/src/index.ts": {
"no-restricted-syntax": {
"count": 4
}
},
"packages/core-backend/src/ws/AccountActivityService.ts": {
"no-restricted-syntax": {
"count": 1
Expand Down
4 changes: 4 additions & 0 deletions packages/core-backend/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `RampsActivityService` for validated, profile-scoped ramps activity notifications over `BackendWebSocketService` (`ramps-activity.v1.<profileId>`) ([#10304](https://github.com/MetaMask/core/pull/10304))

### Changed

- Bump `uuid` from `^9.0.1` to `^11.1.1` ([#10243](https://github.com/MetaMask/core/pull/10243))
Expand Down
31 changes: 31 additions & 0 deletions packages/core-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Core backend services for MetaMask, serving as the data layer between Backend se
- [Constructor Options](#constructor-options-1)
- [Methods](#methods-1)
- [Events Published](#events-published)
- [RampsActivityService](#rampsactivityservice)

## Installation

Expand Down Expand Up @@ -655,3 +656,33 @@ interface AccountActivityServiceOptions {
- `AccountActivityService:balanceUpdated` - Real-time balance changes
- `AccountActivityService:transactionUpdated` - Transaction status updates
- `AccountActivityService:statusChanged` - Chain/service status changes

### RampsActivityService

Profile-scoped service for receiving ramps activity notifications through
`BackendWebSocketService`. It derives the
`ramps-activity.v1.<profileId>` channel from
`AuthenticationController:getSessionProfile`, preferring
`canonicalProfileId` (the same identity Ramps uses as MoonPay `external_id`)
and falling back to the per-SRP `profileId`. It validates every server event at
runtime, and automatically resubscribes after WebSocket reconnects, profile
changes, and wallet unlocks.

```typescript
const rampsActivityService = new RampsActivityService({
messenger: rampsActivityServiceMessenger,
});

await rampsActivityService.init();

messenger.subscribe('RampsActivityService:eventReceived', (event) => {
if (event.needsFetch) {
// Refresh ramps data via RampsController (GET is source of truth).
}
});
```

Published events:

- `RampsActivityService:eventReceived` - A validated profile-scoped ramps activity event
- `RampsActivityService:statusChanged` - The backend WebSocket connection status
25 changes: 21 additions & 4 deletions packages/core-backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ export type {
SubscriptionOptions,
AccountActivityServiceOptions,
AccountActivityServiceActions,
AllowedActions as AccountActivityServiceAllowedActions,
AccountActivityServiceTransactionUpdatedEvent,
AccountActivityServiceBalanceUpdatedEvent,
AccountActivityServiceSubscriptionErrorEvent,
AccountActivityServiceStatusChangedEvent,
AccountActivityServiceEvents,
AllowedEvents as AccountActivityServiceAllowedEvents,
AccountActivityServiceMessenger,
} from './ws/AccountActivityService.js';

Expand All @@ -64,6 +62,27 @@ export type {
AccountActivityMessage,
} from './types.js';

// ============================================================================
// RAMPS ACTIVITY SERVICE
// ============================================================================

export {
RampsActivityService,
RAMPS_ACTIVITY_SERVICE_ALLOWED_ACTIONS,
RAMPS_ACTIVITY_SERVICE_ALLOWED_EVENTS,
} from './ws/RampsActivityService.js';

export type {
RampsActivityEntity,
RampsActivityEvent,
RampsActivityServiceOptions,
RampsActivityServiceActions,
RampsActivityServiceEventReceivedEvent,
RampsActivityServiceStatusChangedEvent,
RampsActivityServiceEvents,
RampsActivityServiceMessenger,
} from './ws/RampsActivityService.js';

// ============================================================================
// API PLATFORM CLIENT SERVICE
// ============================================================================
Expand Down Expand Up @@ -96,12 +115,10 @@ export type {
OHLCVSystemNotificationData,
OHLCVServiceOptions,
OHLCVServiceActions,
OHLCVServiceAllowedActions,
OHLCVServiceBarUpdatedEvent,
OHLCVServiceChainStatusChangedEvent,
OHLCVServiceSubscriptionErrorEvent,
OHLCVServiceEvents,
OHLCVServiceAllowedEvents,
OHLCVServiceMessenger,
} from './ws/ohlcv/index.js';

Expand Down
Loading
Loading