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

fix: Clicking on report link does not add external_link_clicked to si… #29969

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

Conversation

pnarayanaswamy
Copy link
Contributor

@pnarayanaswamy pnarayanaswamy commented Jan 29, 2025

…gnature events

Description

Fixes the bug that the external_link_clicked property is not added to the Signature approved, signature rejected , transaction approved and transaction rejected events
Adds integration tests to verify the property is added to the metrics

Open in GitHub Codespaces

Related issues

Fixes: #23995

Manual testing steps

  1. Go to this page...

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.

@pnarayanaswamy pnarayanaswamy requested a review from a team as a code owner January 29, 2025 15:30
Copy link
Contributor

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-qa QA team label Jan 29, 2025
@metamaskbot
Copy link
Collaborator

Builds ready [b22bea6]
Page Load Metrics (1619 ± 44 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint46617701564266128
domContentLoaded1435171815918842
load1445176816199144
domInteractive2378422110
backgroundConnect86124189
firstReactRender1599372814
getState47116189
initialActions00000
loadScripts1020130311668139
setupStore781172110
uiStartup166724321903212102
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 399 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@pnarayanaswamy pnarayanaswamy added the team-confirmations Push issues to confirmations team label Jan 30, 2025
@metamaskbot
Copy link
Collaborator

Builds ready [a3f8f6d]
Page Load Metrics (1705 ± 74 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint30020661643342164
domContentLoaded14652056168214771
load14742069170515574
domInteractive23171453316
backgroundConnect887272412
firstReactRender15100412713
getState45615178
initialActions01000
loadScripts10341510121611053
setupStore68015189
uiStartup17012440195919996
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 667 Bytes (0.01%)
  • common: 0 Bytes (0.00%)

@@ -45,6 +45,7 @@ function ReportLink({
<Text marginTop={1} display={Display.Flex}>
{t('somethingDoesntLookRight', [
<ButtonLink
data-testid="alert-provider-report-link"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We avoid adding data-testid in extension, in case its possible to query using button text it may be better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this suggestion. I do like using findByText to also test text expectations simultaneously

Copy link
Contributor

@digiwand digiwand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one thing, I think we should remove the console.log before merging. other than this, Lgtm!

...unapprovedTypedMessage,
};

console.log(state);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log(state);

Comment on lines +94 to +95
export const getMetamaskStateWithMaliciousPermit = (accountAddress: string) => {
const pendingPermitId = '48a75190-45ca-11ef-9001-f3886ec2397c';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor nit] we can move this out to avoid reinstantiating for each getMetamaskStateWithMaliciousPermit call

Suggested change
export const getMetamaskStateWithMaliciousPermit = (accountAddress: string) => {
const pendingPermitId = '48a75190-45ca-11ef-9001-f3886ec2397c';
const pendingPermitId = '48a75190-45ca-11ef-9001-f3886ec2397c';
export const getMetamaskStateWithMaliciousPermit = (accountAddress: string) => {

Comment on lines +311 to +326
await waitFor(() => {
updateSignatureEventFragment =
mockedBackgroundConnection.submitRequestToBackground.mock.calls?.find(
(call) =>
call[0] === 'updateEventFragment' &&
JSON.stringify(call[1]).includes(
JSON.stringify({
properties: {
external_link_clicked: 'security_alert_support_link',
},
}),
),
);

expect(updateSignatureEventFragment).toBeDefined();
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to use Jest's matchers rather than relying on string comparisons?

Suggested change
await waitFor(() => {
updateSignatureEventFragment =
mockedBackgroundConnection.submitRequestToBackground.mock.calls?.find(
(call) =>
call[0] === 'updateEventFragment' &&
JSON.stringify(call[1]).includes(
JSON.stringify({
properties: {
external_link_clicked: 'security_alert_support_link',
},
}),
),
);
expect(updateSignatureEventFragment).toBeDefined();
});
expect(
mockedBackgroundConnection.submitRequestToBackground,
).toHaveBeenCalledWith(
'updateEventFragment',
expect.arrayContaining([
expect.objectContaining({
properties: expect.objectContaining({
external_link_clicked: 'security_alert_support_link',
}),
}),
]),
);

...unapprovedTypedMessage,
};

console.log(state);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guessing this is forgotten

Comment on lines +39 to +48
const onClickSupportLink = () => {
const properties = {
properties: {
external_link_clicked: 'security_alert_support_link',
},
};
updateSignatureEventFragment(properties);
updateTransactionEventFragment(properties, ownerId);
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we create this callback with useCallback if it has ownerId dependency?

Suggested change
const onClickSupportLink = () => {
const properties = {
properties: {
external_link_clicked: 'security_alert_support_link',
},
};
updateSignatureEventFragment(properties);
updateTransactionEventFragment(properties, ownerId);
};
const onClickSupportLink = useCallback(() => {
const properties = {
properties: {
external_link_clicked: 'security_alert_support_link',
},
};
updateSignatureEventFragment(properties);
updateTransactionEventFragment(properties, ownerId);
}, [ownerId]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-confirmations Push issues to confirmations team team-qa QA team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Clicking on false positive, Blockaid link does not add external_link_clicked to signature events
7 participants