Skip to content

Commit

Permalink
feat: add mm portfolio api with env based feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Devin Stewart authored and Devin Stewart committed Dec 13, 2024
1 parent 715476c commit ae3680f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .js.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export SECURITY_ALERTS_API_URL="https://security-alerts.api.cx.metamask.io"
# Enable Portfolio View
export PORTFOLIO_VIEW="true"

# Portfolio API base url
export MM_PORTFOLIO_API_BASE_URL="https://portfolio.dev-api.cx.metamask.io"

# Temporary mechanism to enable mm portfolio API prior to release.
export MM_PORTFOLIO_API_ENABLED="false"

# Temporary mechanism to enable security alerts API prior to release.
export MM_SECURITY_ALERTS_API_ENABLED="true"
Expand Down
4 changes: 4 additions & 0 deletions app/core/AppConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const DEVELOPMENT = 'development';
const PORTFOLIO_URL =
process.env.MM_PORTFOLIO_URL || 'https://portfolio.metamask.io';
const SECURITY_ALERTS_API_URL = process.env.SECURITY_ALERTS_API_URL ?? 'https://security-alerts.api.cx.metamask.io';
const MM_PORTFOLIO_API_BASE_URL = process.env.MM_PORTFOLIO_API_BASE_URL ?? 'https://portfolio.dev-api.cx.metamask.io'

Check warning on line 9 in app/core/AppConstants.ts

View workflow job for this annotation

GitHub Actions / scripts (lint)

Missing semicolon

Check warning on line 9 in app/core/AppConstants.ts

View workflow job for this annotation

GitHub Actions / scripts (lint)

Missing semicolon

export default {
IS_DEV: process.env?.NODE_ENV === DEVELOPMENT,
Expand All @@ -24,6 +25,9 @@ export default {
PORTFOLIO: {
URL: PORTFOLIO_URL,
},
PORTFOLIO_API: {
URL: MM_PORTFOLIO_API_BASE_URL,
},
BRIDGE: {
ACTIVE: true,
URL: `${PORTFOLIO_URL}/bridge`,
Expand Down
33 changes: 33 additions & 0 deletions app/lib/ppom/mm-portfolio-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import AppConstants from '../../core/AppConstants';

export function isMMPortfolioAPIEnabled() {
return process.env.MM_PORTFOLIO_API_ENABLED === 'true';
}

export async function getMMPortfolioHealthCheck(): Promise<any> {

Check failure on line 7 in app/lib/ppom/mm-portfolio-api.ts

View workflow job for this annotation

GitHub Actions / scripts (lint)

Unexpected any. Specify a different type

Check failure on line 7 in app/lib/ppom/mm-portfolio-api.ts

View workflow job for this annotation

GitHub Actions / scripts (lint)

Unexpected any. Specify a different type
return request("");

Check failure on line 8 in app/lib/ppom/mm-portfolio-api.ts

View workflow job for this annotation

GitHub Actions / scripts (lint)

Strings must use singlequote

Check failure on line 8 in app/lib/ppom/mm-portfolio-api.ts

View workflow job for this annotation

GitHub Actions / scripts (lint)

Strings must use singlequote
}

async function request(endpoint: string, options?: RequestInit) {
const url = getUrl(endpoint);

const response = await fetch(url, options);

if (!response.ok) {
throw new Error(
`MM Portfolio API request failed with status: ${response.status}`,
);
}

return response.json();
}

function getUrl(endpoint: string) {
const host = AppConstants.PORTFOLIO_API.URL;

if (!host) {
throw new Error('MM Portfolio API URL is not set');
}

return `${host}/${endpoint}`;
}
3 changes: 3 additions & 0 deletions bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,9 @@ app:
- opts:
is_expand: false
PORTFOLIO_VIEW: true
- opts:
is_expand: false
MM_PORTFOLIO_API_ENABLED: false
- opts:
is_expand: false
MM_MULTICHAIN_V1_ENABLED: true
Expand Down

0 comments on commit ae3680f

Please sign in to comment.