-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 utility function to get supported chains from the Security Alerts API #10267
base: main
Are you sure you want to change the base?
Conversation
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
|
|
There is usage of
|
); | ||
} | ||
|
||
return response.json(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove the duplication and create a request
function for example that accepts the method and some extra properties?
@@ -19,6 +21,10 @@ export async function validateWithSecurityAlertsAPI( | |||
return postRequest(endpoint, request); | |||
} | |||
|
|||
export async function getSupportedChains(): Promise<Hex[]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe getSecurityAlertsAPISupportedChainIds
to be explicit?
const supportedChains = isSecurityAlertsAPIEnabled() | ||
? await getSupportedChains() | ||
: BLOCKAID_SUPPORTED_CHAIN_IDS; | ||
return supportedChains.includes(chainId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, but could we remove some duplication with something like:
let supportedChainIds = BLOCKAID_SUPPORTED_CHAIN_IDS;
try {
if(isSecurityAlertsAPIEnabled()) {
supportedChainIds = getSupportedChainds();
}
} catch (e) {
Logger.log(
`Error fetching supported chains from security alerts API: ${e}`,
);
}
return supportedChainIds.includes(chainId);
@@ -238,6 +238,9 @@ describe('PPOM Utils', () => { | |||
|
|||
it('uses security alerts API if enabled', async () => { | |||
isSecurityAlertsEnabledMock.mockReturnValue(true); | |||
jest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, but could we create a persistent variable for this such as getSupportedChainsMock
like we do for isSecurityAlertsEnabledMock
?
Description
This PR aims to include a new utility function to get supported chains from the Security Alerts API when enabled.
Related Repository
Refer to the Security Alerts API repository for more details.
Related issues
Fixes:
Manual testing steps
Test blockaid regression
add the envs
security-alerts
and find the call to the API service.Existing PPOM logic should function as before, even with the above environment variables added, due to the fallback to the controller in the event of an error.
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist