Skip to content

Commit 2d1566e

Browse files
committed
feat(ramps-controller): update countries endpoint to v2 and add amount fields
- Update getCountries endpoint from /regions/countries to /v2/regions/countries - Add defaultAmount and quickAmounts fields to Country type - Update test mocks to use new v2 endpoint path
1 parent 4a1b947 commit 2d1566e

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

packages/ramps-controller/src/RampsService.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ describe('RampsService', () => {
275275

276276
it('returns the countries from the cache API filtered by support', async () => {
277277
nock('https://on-ramp-cache.uat-api.cx.metamask.io')
278-
.get('/regions/countries')
278+
.get('/v2/regions/countries')
279279
.query({
280280
action: 'buy',
281281
sdk: '2.1.6',
@@ -326,7 +326,7 @@ describe('RampsService', () => {
326326

327327
it('uses the production cache URL when environment is Production', async () => {
328328
nock('https://on-ramp-cache.api.cx.metamask.io')
329-
.get('/regions/countries')
329+
.get('/v2/regions/countries')
330330
.query({
331331
action: 'buy',
332332
sdk: '2.1.6',
@@ -379,7 +379,7 @@ describe('RampsService', () => {
379379

380380
it('uses staging cache URL when environment is Development', async () => {
381381
nock('https://on-ramp-cache.uat-api.cx.metamask.io')
382-
.get('/regions/countries')
382+
.get('/v2/regions/countries')
383383
.query({
384384
action: 'buy',
385385
sdk: '2.1.6',
@@ -432,7 +432,7 @@ describe('RampsService', () => {
432432

433433
it('passes the action parameter correctly', async () => {
434434
nock('https://on-ramp-cache.uat-api.cx.metamask.io')
435-
.get('/regions/countries')
435+
.get('/v2/regions/countries')
436436
.query({
437437
action: 'sell',
438438
sdk: '2.1.6',
@@ -516,7 +516,7 @@ describe('RampsService', () => {
516516
},
517517
];
518518
nock('https://on-ramp-cache.uat-api.cx.metamask.io')
519-
.get('/regions/countries')
519+
.get('/v2/regions/countries')
520520
.query({
521521
action: 'sell',
522522
sdk: '2.1.6',
@@ -564,7 +564,7 @@ describe('RampsService', () => {
564564
},
565565
];
566566
nock('https://on-ramp-cache.uat-api.cx.metamask.io')
567-
.get('/regions/countries')
567+
.get('/v2/regions/countries')
568568
.query({
569569
action: 'buy',
570570
sdk: '2.1.6',
@@ -586,7 +586,7 @@ describe('RampsService', () => {
586586
});
587587
it('throws if the countries API returns an error', async () => {
588588
nock('https://on-ramp-cache.uat-api.cx.metamask.io')
589-
.get('/regions/countries')
589+
.get('/v2/regions/countries')
590590
.query({
591591
action: 'buy',
592592
sdk: '2.1.6',
@@ -607,13 +607,13 @@ describe('RampsService', () => {
607607
await clock.runAllAsync();
608608
await flushPromises();
609609
await expect(countriesPromise).rejects.toThrow(
610-
`Fetching 'https://on-ramp-cache.uat-api.cx.metamask.io/regions/countries?action=buy&sdk=2.1.6&controller=${CONTROLLER_VERSION}&context=mobile-ios' failed with status '500'`,
610+
`Fetching 'https://on-ramp-cache.uat-api.cx.metamask.io/v2/regions/countries?action=buy&sdk=2.1.6&controller=${CONTROLLER_VERSION}&context=mobile-ios' failed with status '500'`,
611611
);
612612
});
613613

614614
it('throws if the API returns a non-array response', async () => {
615615
nock('https://on-ramp-cache.uat-api.cx.metamask.io')
616-
.get('/regions/countries')
616+
.get('/v2/regions/countries')
617617
.query({
618618
action: 'buy',
619619
sdk: '2.1.6',
@@ -636,7 +636,7 @@ describe('RampsService', () => {
636636

637637
it('throws if the API returns an object instead of an array', async () => {
638638
nock('https://on-ramp-cache.uat-api.cx.metamask.io')
639-
.get('/regions/countries')
639+
.get('/v2/regions/countries')
640640
.query({
641641
action: 'buy',
642642
sdk: '2.1.6',
@@ -754,7 +754,7 @@ describe('RampsService', () => {
754754
},
755755
];
756756
nock('https://on-ramp-cache.uat-api.cx.metamask.io')
757-
.get('/regions/countries')
757+
.get('/v2/regions/countries')
758758
.query({
759759
action: 'buy',
760760
sdk: '2.1.6',
@@ -807,7 +807,7 @@ describe('RampsService', () => {
807807
},
808808
];
809809
nock('https://on-ramp-cache.uat-api.cx.metamask.io')
810-
.get('/regions/countries')
810+
.get('/v2/regions/countries')
811811
.query({
812812
action: 'buy',
813813
sdk: '2.1.6',
@@ -864,7 +864,7 @@ describe('RampsService', () => {
864864
},
865865
];
866866
nock('https://on-ramp-cache.uat-api.cx.metamask.io')
867-
.get('/regions/countries')
867+
.get('/v2/regions/countries')
868868
.query({
869869
action: 'buy',
870870
sdk: '2.1.6',
@@ -905,7 +905,7 @@ describe('RampsService', () => {
905905
},
906906
];
907907
nock('https://on-ramp-cache.uat-api.cx.metamask.io')
908-
.get('/regions/countries')
908+
.get('/v2/regions/countries')
909909
.query({
910910
action: 'buy',
911911
sdk: '2.1.6',

packages/ramps-controller/src/RampsService.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ export type Country = {
134134
* Array of state objects.
135135
*/
136136
states?: State[];
137+
/**
138+
* Default amount for ramps transactions.
139+
*/
140+
defaultAmount?: number;
141+
/**
142+
* Quick amount options for ramps transactions.
143+
*/
144+
quickAmounts?: number[];
137145
};
138146

139147
/**
@@ -535,7 +543,7 @@ export class RampsService {
535543
async getCountries(action: 'buy' | 'sell' = 'buy'): Promise<Country[]> {
536544
const countries = await this.#request<Country[]>(
537545
RampsApiService.Regions,
538-
'regions/countries',
546+
'v2/regions/countries',
539547
{ action, responseType: 'json' },
540548
);
541549

0 commit comments

Comments
 (0)