Skip to content

Commit 8867976

Browse files
authored
refactor(deposit): use sdk env according MetaMask env (#20520)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** This PR changes Deposit SDK environment to be aligned with the MetaMask Environment and LaunchDarkly API keys. ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: Remap Deposit SDK environment to use MetaMask Environment. ## **Related issues** Fixes: ## **Manual testing steps** ```gherkin Feature: Deposit Scenario: user opens the Deposit flow Given the app is a dev build When user visits the Deposit feature Then the app uses non-prod API Scenario: user opens the Deposit flow Given the app is a prod build When user visits the Deposit feature Then the app uses prod API ``` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Derives Deposit SDK environment from METAMASK_ENVIRONMENT via new helper, replaces old flag-based logic, adds tests, and updates Babel test config exclusions. > > - **Deposit SDK**: > - **Env resolution**: Introduce `app/components/UI/Ramp/Deposit/sdk/getSdkEnvironment.ts` to map `process.env.METAMASK_ENVIRONMENT` to `SdkEnvironment` (`production|beta|rc` -> `Production`; others/default -> `Staging`). > - **Usage**: Replace inline env logic in `app/components/UI/Ramp/Deposit/sdk/index.tsx` with `getSdkEnvironment()`. > - **Tests**: > - Add `getSdkEnvironment.test.ts` covering production, staging, defaults, and edge cases. > - **Build/Config**: > - Update `babel.config.tests.js` to exclude Deposit `getSdkEnvironment` files from `transform-inline-environment-variables`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 2adc2e8. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 6ca921e commit 8867976

File tree

4 files changed

+112
-11
lines changed

4 files changed

+112
-11
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { SdkEnvironment } from '@consensys/native-ramps-sdk';
2+
import { getSdkEnvironment } from './getSdkEnvironment';
3+
4+
describe('getSdkEnvironment', () => {
5+
const originalEnv = process.env.METAMASK_ENVIRONMENT;
6+
7+
afterEach(() => {
8+
process.env.METAMASK_ENVIRONMENT = originalEnv;
9+
});
10+
11+
describe('Production Environment', () => {
12+
it('returns Production for production environment', () => {
13+
process.env.METAMASK_ENVIRONMENT = 'production';
14+
const result = getSdkEnvironment();
15+
expect(result).toBe(SdkEnvironment.Production);
16+
});
17+
18+
it('returns Production for beta environment', () => {
19+
process.env.METAMASK_ENVIRONMENT = 'beta';
20+
const result = getSdkEnvironment();
21+
expect(result).toBe(SdkEnvironment.Production);
22+
});
23+
24+
it('returns Production for rc environment', () => {
25+
process.env.METAMASK_ENVIRONMENT = 'rc';
26+
const result = getSdkEnvironment();
27+
expect(result).toBe(SdkEnvironment.Production);
28+
});
29+
});
30+
31+
describe('Staging Environment', () => {
32+
it('returns Staging for dev environment', () => {
33+
process.env.METAMASK_ENVIRONMENT = 'dev';
34+
const result = getSdkEnvironment();
35+
expect(result).toBe(SdkEnvironment.Staging);
36+
});
37+
38+
it('returns Staging for exp environment', () => {
39+
process.env.METAMASK_ENVIRONMENT = 'exp';
40+
const result = getSdkEnvironment();
41+
expect(result).toBe(SdkEnvironment.Staging);
42+
});
43+
44+
it('returns Staging for test environment', () => {
45+
process.env.METAMASK_ENVIRONMENT = 'test';
46+
const result = getSdkEnvironment();
47+
expect(result).toBe(SdkEnvironment.Staging);
48+
});
49+
50+
it('returns Staging for e2e environment', () => {
51+
process.env.METAMASK_ENVIRONMENT = 'e2e';
52+
const result = getSdkEnvironment();
53+
expect(result).toBe(SdkEnvironment.Staging);
54+
});
55+
});
56+
57+
describe('Default/Unknown Environment', () => {
58+
it('returns Staging for undefined environment', () => {
59+
delete process.env.METAMASK_ENVIRONMENT;
60+
const result = getSdkEnvironment();
61+
expect(result).toBe(SdkEnvironment.Staging);
62+
});
63+
64+
it('returns Staging for unknown environment value', () => {
65+
process.env.METAMASK_ENVIRONMENT = 'unknown-env';
66+
const result = getSdkEnvironment();
67+
expect(result).toBe(SdkEnvironment.Staging);
68+
});
69+
70+
it('returns Staging for empty string environment', () => {
71+
process.env.METAMASK_ENVIRONMENT = '';
72+
const result = getSdkEnvironment();
73+
expect(result).toBe(SdkEnvironment.Staging);
74+
});
75+
});
76+
77+
describe('Edge Cases', () => {
78+
it('handles case sensitivity correctly', () => {
79+
process.env.METAMASK_ENVIRONMENT = 'PRODUCTION';
80+
const result = getSdkEnvironment();
81+
expect(result).toBe(SdkEnvironment.Staging);
82+
});
83+
84+
it('handles whitespace in environment value', () => {
85+
process.env.METAMASK_ENVIRONMENT = ' production ';
86+
const result = getSdkEnvironment();
87+
expect(result).toBe(SdkEnvironment.Staging);
88+
});
89+
});
90+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { SdkEnvironment } from '@consensys/native-ramps-sdk';
2+
3+
export function getSdkEnvironment() {
4+
const metamaskEnvironment = process.env.METAMASK_ENVIRONMENT;
5+
switch (metamaskEnvironment) {
6+
case 'production':
7+
case 'beta':
8+
case 'rc':
9+
return SdkEnvironment.Production;
10+
11+
case 'dev':
12+
case 'exp':
13+
case 'test':
14+
case 'e2e':
15+
default:
16+
return SdkEnvironment.Staging;
17+
}
18+
}

app/components/UI/Ramp/Deposit/sdk/index.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { selectDepositProviderApiKey } from '../../../../../selectors/featureFla
1313
import {
1414
NativeRampsSdk,
1515
NativeTransakAccessToken,
16-
SdkEnvironment,
1716
Context,
1817
DepositPaymentMethod,
1918
DepositRegion,
@@ -24,6 +23,7 @@ import {
2423
resetProviderToken,
2524
storeProviderToken,
2625
} from '../utils/ProviderTokenVault';
26+
import { getSdkEnvironment } from './getSdkEnvironment';
2727
import {
2828
fiatOrdersGetStartedDeposit,
2929
setFiatOrdersGetStartedDeposit,
@@ -58,16 +58,7 @@ export interface DepositSDK {
5858
setSelectedCryptoCurrency: (cryptoCurrency: DepositCryptoCurrency) => void;
5959
}
6060

61-
const isDevelopment =
62-
process.env.NODE_ENV !== 'production' ||
63-
process.env.RAMP_DEV_BUILD === 'true';
64-
const isInternalBuild = process.env.RAMP_INTERNAL_BUILD === 'true';
65-
const isDevelopmentOrInternalBuild = isDevelopment || isInternalBuild;
66-
67-
let environment = SdkEnvironment.Production;
68-
if (isDevelopmentOrInternalBuild) {
69-
environment = SdkEnvironment.Staging;
70-
}
61+
const environment = getSdkEnvironment();
7162

7263
const context =
7364
Platform.OS === 'ios' ? Context.MobileIOS : Context.MobileAndroid;

babel.config.tests.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const newOverrides = [
1717
'app/core/Engine/controllers/network-controller/utils.test.ts',
1818
'app/core/Engine/controllers/gator-permissions-controller/gator-permissions-controller-init.ts',
1919
'app/core/Engine/controllers/gator-permissions-controller/gator-permissions-controller-init.test.ts',
20+
'app/components/UI/Ramp/Deposit/sdk/getSdkEnvironment.ts',
21+
'app/components/UI/Ramp/Deposit/sdk/getSdkEnvironment.test.ts',
2022
'app/components/UI/Ramp/Aggregator/sdk/getSdkEnvironment.ts',
2123
'app/components/UI/Ramp/Aggregator/sdk/getSdkEnvironment.test.ts',
2224
'app/store/migrations/**',

0 commit comments

Comments
 (0)