diff --git a/.js.env.example b/.js.env.example index 56c7c1bb865..1b7ee23f66d 100644 --- a/.js.env.example +++ b/.js.env.example @@ -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" diff --git a/app/core/AppConstants.ts b/app/core/AppConstants.ts index 7d132663576..74b3becc9a2 100644 --- a/app/core/AppConstants.ts +++ b/app/core/AppConstants.ts @@ -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, @@ -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`, diff --git a/app/lib/ppom/mm-portfolio-api.ts b/app/lib/ppom/mm-portfolio-api.ts new file mode 100644 index 00000000000..bd43a6e433f --- /dev/null +++ b/app/lib/ppom/mm-portfolio-api.ts @@ -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 { + 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}`; +} diff --git a/bitrise.yml b/bitrise.yml index 44878376bba..3e17ef054f3 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -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 @@ -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