Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add mm portfolio api with env based feature flag #12703

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 @@
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
Loading