Skip to content
Merged
8 changes: 8 additions & 0 deletions packages/ramps-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add persisted `autorampTransactionRecords` on `RampsController`. Each autoramp stores `syncedAt` and the last seen status string per transaction id. The first successful fetch seeds the record and calls nothing ([#11017](https://github.com/MetaMask/core/pull/11017))
- Add `diffAutorampTransactions`, which reports a transaction id that is new or whose status string changed. A transaction missing from the fetch stays in the record ([#11017](https://github.com/MetaMask/core/pull/11017))
- Add an optional `trackAutorampTransactionStatusChanged` constructor callback. `refreshAutorampTransactions` loads the newest autoramp transaction page (`page_size` 50) and calls it after the record is written, once per new transaction id or status change. `previousStatus` is omitted for a new id. Overlapping calls for one autoramp share one request. A failed fetch writes nothing. Removing an autoramp, replacing the autoramp cursor, or discarding a foreign VBA session clears the matching records. A fetch still in flight when that autoramp leaves the cursor does not write the record or call the callback. A callback that throws is ignored, so one failing change does not drop the rest of the batch ([#11017](https://github.com/MetaMask/core/pull/11017))

### Changed

- **BREAKING:** `RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS` now includes `NeoBankService:listAutorampTransactions`. Hosts must delegate that action to `RampsController` ([#11017](https://github.com/MetaMask/core/pull/11017))
- `NeoBankService.listAutorampTransactions` accepts an optional `pageSize`, sent as `page_size`. Omitting it keeps the previous query ([#11017](https://github.com/MetaMask/core/pull/11017))
- Bump `@metamask/utils` from `^12.0.0` to `^12.0.1` ([#11107](https://github.com/MetaMask/core/pull/11107))

## [27.2.0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ export type NeoBankServiceGetDepositInstructionsAction = {
* (`Completed`, `Failed`, …). The deprecated `state` field is ignored.
*
* @param autorampId - MoonPay autoramp id.
* @param options - Optional page size. Omitted requests use the API default.
* @param options.pageSize - `page_size` query value. Callers that diff
* status pass 50.
* @returns Transaction summaries from the newest page.
*/
export type NeoBankServiceListAutorampTransactionsAction = {
Expand Down
25 changes: 25 additions & 0 deletions packages/ramps-controller/src/NeoBankService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ import { RampsEnvironment } from './RampsService.js';

const STAGING_BASE = 'https://on-ramp.uat-api.cx.metamask.io';

const isAutorampTransactionQuery = (
query: Record<string, string | string[] | undefined>,
pageSize?: string,
): boolean => {
const pageMatches =
pageSize === undefined ? true : query.page_size === pageSize;
return (
query.autoramp_id === 'ar-1' && query.sort_order === 'desc' && pageMatches
);
};

/**
* Builds a NeoBankService with AuthenticationController bearer auth stubbed.
*
Expand Down Expand Up @@ -757,6 +768,20 @@ describe('NeoBankService', () => {
expect(scope.isDone()).toBe(true);
});

it('sends page_size when a page size is requested', async () => {
const scope = nock(STAGING_BASE)
.get('/neobank/autoramp-transactions')
.query((query) => isAutorampTransactionQuery(query, '50'))
.reply(200, { items: [] });

const service = createService();

expect(
await service.listAutorampTransactions('ar-1', { pageSize: 50 }),
).toStrictEqual([]);
expect(scope.isDone()).toBe(true);
});

it('throws when a transaction is missing an id', async () => {
nock(STAGING_BASE)
.get('/neobank/autoramp-transactions')
Expand Down
7 changes: 7 additions & 0 deletions packages/ramps-controller/src/NeoBankService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -763,14 +763,21 @@ export class NeoBankService {
* (`Completed`, `Failed`, …). The deprecated `state` field is ignored.
*
* @param autorampId - MoonPay autoramp id.
* @param options - Optional page size. Omitted requests use the API default.
* @param options.pageSize - `page_size` query value. Callers that diff
* status pass 50.
* @returns Transaction summaries from the newest page.
*/
async listAutorampTransactions(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proxy has /autoramp-transactions/ids for targeted refresh. Do we have any plan to use it (e.g. after push) vs forever listing?

autorampId: string,
options?: { pageSize?: number },
): Promise<AutorampTransactionSummary[]> {
const response = await this.#getJson<unknown>('autoramp-transactions', {
autoramp_id: autorampId,
sort_order: 'desc',
...(options?.pageSize === undefined
? {}
: { page_size: options.pageSize }),
});
const transactions = readPagedItems(
response,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,27 @@ export type RampsControllerRefreshAutorampsAction = {
handler: RampsController['refreshAutoramps'];
};

/**
* Fetches the newest page of transactions for one autoramp and calls
* `trackAutorampTransactionStatusChanged` for each new id or status change.
*
* The updated record is written before the callback runs. A failed fetch
* leaves the record untouched. Concurrent calls for the same autoramp share
* one request. The first successful fetch seeds the record and calls
* nothing. When this autoramp was on the cursor at the start of the fetch
* and was removed before the response is applied (`removeAutoramp`, a cursor
* replace that drops the id, or a foreign VBA session discard), the record
* is not restored and the callback is not called. A callback that throws
* is ignored, so one failing change does not drop the rest of the batch.
*
* @param autorampId - MoonPay autoramp id.
* @returns Transaction summaries from the newest page.
*/
export type RampsControllerRefreshAutorampTransactionsAction = {
type: `RampsController:refreshAutorampTransactions`;
handler: RampsController['refreshAutorampTransactions'];
};

/**
* Starts polling all pending V2 orders at a fixed interval.
* Each poll cycle iterates orders with non-terminal statuses,
Expand Down Expand Up @@ -968,6 +989,7 @@ export type RampsControllerMethodActions =
| RampsControllerApplyAutorampStatusFromPushAction
| RampsControllerRefreshAutorampAction
| RampsControllerRefreshAutorampsAction
| RampsControllerRefreshAutorampTransactionsAction
| RampsControllerStartOrderPollingAction
| RampsControllerStopOrderPollingAction
| RampsControllerGetBuyWidgetDataAction
Expand Down
Loading
Loading