Skip to content

Commit

Permalink
add-mm-portfolio-api-with-env-based-feature-flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Bigshmow committed Dec 15, 2024
1 parent 491dc45 commit 3ef90e2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
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

0 comments on commit 3ef90e2

Please sign in to comment.