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 #12709

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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 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';

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<T>(): Promise<T> {
return request('');
}

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}`;
}
5 changes: 4 additions & 1 deletion 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 Expand Up @@ -1808,7 +1811,7 @@ app:
NVM_SHA256SUM: '8e45fa547f428e9196a5613efad3bfa4d4608b74ca870f930090598f5af5f643'
- opts:
is_expand: false
NODE_VERSION: 20.18.0
NODE_VERSION: 20.17.0
- opts:
is_expand: false
YARN_VERSION: 1.22.22
Expand Down
Loading