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 utility function to get supported chains from the Security Alerts API #10267

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

vinistevam
Copy link
Contributor

@vinistevam vinistevam commented Jul 9, 2024

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

  1. Test blockaid regression

  2. add the envs

export SECURITY_ALERTS_API_URL='https://security-alerts.dev-api.cx.metamask.io'
export SECURITY_ALERTS_API_ENABLED='true'
  • Go to test dapp and trigger on of the malicious signatures
  • To verify in chrome go to dev tools > network. Search for 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

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Copy link
Contributor

github-actions bot commented Jul 9, 2024

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.

@metamaskbot metamaskbot added the team-confirmations Push issues to confirmations team label Jul 9, 2024
Copy link

sonarcloud bot commented Jul 10, 2024

@vinistevam vinistevam marked this pull request as ready for review July 10, 2024 12:21
@vinistevam vinistevam requested review from a team as code owners July 10, 2024 12:21
@vinistevam vinistevam added the Run Smoke E2E Triggers smoke e2e on Bitrise label Jul 10, 2024
Copy link
Contributor

github-actions bot commented Jul 10, 2024

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: a5129ef
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/1b92f74d-0db8-4195-b34e-ead46ea98544

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

@jpuri
Copy link
Contributor

jpuri commented Jul 10, 2024

There is usage of BLOCKAID_SUPPORTED_CHAIN_IDS here also:

export const isSupportedChainId = (chainId: string) => {

);
}

return response.json();
Copy link
Member

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[]> {
Copy link
Member

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);
Copy link
Member

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
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Run Smoke E2E Triggers smoke e2e on Bitrise team-confirmations Push issues to confirmations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants