-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add-mm-portfolio-api-with-env-based-feature-flag
- Loading branch information
Showing
4 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters