-
-
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.
feat: Adding blockaid banner to re-designed confirmation pages (#12863)
## **Description** Add blockaid banner to re-designed signature request pages. ## **Related issues** Fixes: MetaMask/MetaMask-planning#3741 ## **Manual testing steps** 1. Enable re-designs confirmations locally on mobile 2. Submit malicious signature request 3. Ensure that blockaid banner is present on the page ## **Screenshots/Recordings** <img width="378" alt="Screenshot 2025-01-08 at 4 36 09 PM" src="https://github.com/user-attachments/assets/3b0433de-73b8-4d51-997c-134d4cd63857" /> ## **Pre-merge author checklist** - [X] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [X] I've completed the PR template to the best of my ability - [X] I’ve included tests if applicable - [X] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [X] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **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.
- Loading branch information
Showing
7 changed files
with
220 additions
and
7 deletions.
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
10 changes: 10 additions & 0 deletions
10
...onfirmations/components/Confirm/SignatureBlockaidBanner/SignatureBlockaidBanner.styles.ts
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,10 @@ | ||
import { StyleSheet } from 'react-native'; | ||
|
||
const styleSheet = () => | ||
StyleSheet.create({ | ||
blockaidBanner: { | ||
marginBottom: 8, | ||
}, | ||
}); | ||
|
||
export default styleSheet; |
78 changes: 78 additions & 0 deletions
78
...confirmations/components/Confirm/SignatureBlockaidBanner/SignatureBlockaidBanner.test.tsx
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,78 @@ | ||
import React from 'react'; | ||
import { fireEvent } from '@testing-library/react-native'; | ||
|
||
import renderWithProvider from '../../../../../../util/test/renderWithProvider'; | ||
import { | ||
securityAlertResponse, | ||
typedSignV1ConfirmationState, | ||
} from '../../../../../../util/test/confirm-data-helpers'; | ||
import SignatureBlockaidBanner from './index'; | ||
|
||
jest.mock('react-native-gzip', () => ({ | ||
deflate: (str: string) => str, | ||
})); | ||
|
||
const mockTrackEvent = jest.fn(); | ||
jest.mock('../../../../../hooks/useMetrics', () => ({ | ||
useMetrics: () => ({ | ||
trackEvent: mockTrackEvent, | ||
createEventBuilder: () => ({ | ||
addProperties: () => ({ build: () => ({}) }), | ||
}), | ||
}), | ||
})); | ||
|
||
jest.mock('../../../../../../util/confirmation/signatureUtils', () => ({ | ||
getAnalyticsParams: () => ({}), | ||
})); | ||
|
||
const typedSignApproval = | ||
typedSignV1ConfirmationState.engine.backgroundState.ApprovalController | ||
.pendingApprovals['7e62bcb1-a4e9-11ef-9b51-ddf21c91a998']; | ||
const typedSignV1ConfirmationStateWithBlockaidResponse = { | ||
engine: { | ||
...typedSignV1ConfirmationState.engine, | ||
backgroundState: { | ||
...typedSignV1ConfirmationState.engine.backgroundState, | ||
ApprovalController: { | ||
pendingApprovals: { | ||
'fb2029e1-b0ab-11ef-9227-05a11087c334': { | ||
...typedSignApproval, | ||
requestData: { | ||
...typedSignApproval.requestData, | ||
securityAlertResponse, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
describe('Confirm', () => { | ||
it('should return null if request does not have securityAlertResponse', async () => { | ||
const { queryByText } = renderWithProvider(<SignatureBlockaidBanner />, { | ||
state: typedSignV1ConfirmationState, | ||
}); | ||
expect(queryByText('This is a deceptive request')).toBeNull(); | ||
}); | ||
|
||
it('should render blockaid banner alert if blockaid returns error', async () => { | ||
const { getByText } = renderWithProvider(<SignatureBlockaidBanner />, { | ||
state: typedSignV1ConfirmationStateWithBlockaidResponse, | ||
}); | ||
expect(getByText('This is a deceptive request')).toBeDefined(); | ||
}); | ||
|
||
it('should call trackMetrics method when report issue link is clicked', async () => { | ||
const { getByText, getByTestId } = renderWithProvider( | ||
<SignatureBlockaidBanner />, | ||
{ | ||
state: typedSignV1ConfirmationStateWithBlockaidResponse, | ||
}, | ||
); | ||
fireEvent.press(getByTestId('accordionheader')); | ||
fireEvent.press(getByText('Report an issue')); | ||
expect(mockTrackEvent).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
55 changes: 55 additions & 0 deletions
55
...iews/confirmations/components/Confirm/SignatureBlockaidBanner/SignatureBlockaidBanner.tsx
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,55 @@ | ||
import React, { useCallback } from 'react'; | ||
|
||
import { MetaMetricsEvents } from '../../../../../../core/Analytics'; | ||
import { getAnalyticsParams } from '../../../../../../util/confirmation/signatureUtils'; | ||
import { useStyles } from '../../../../../../component-library/hooks'; | ||
import { useMetrics } from '../../../../../hooks/useMetrics'; | ||
import BlockaidBanner from '../../../components/BlockaidBanner/BlockaidBanner'; | ||
import useApprovalRequest from '../../../hooks/useApprovalRequest'; | ||
import styleSheet from './SignatureBlockaidBanner.styles'; | ||
|
||
const SignatureBlockaidBanner = () => { | ||
const { approvalRequest } = useApprovalRequest(); | ||
const { trackEvent, createEventBuilder } = useMetrics(); | ||
const { styles } = useStyles(styleSheet, {}); | ||
|
||
const { | ||
type, | ||
requestData: { from: fromAddress }, | ||
} = approvalRequest ?? { | ||
requestData: {}, | ||
}; | ||
|
||
const onContactUsClicked = useCallback(() => { | ||
const analyticsParams = { | ||
...getAnalyticsParams( | ||
{ | ||
from: fromAddress, | ||
}, | ||
type, | ||
), | ||
external_link_clicked: 'security_alert_support_link', | ||
}; | ||
trackEvent( | ||
createEventBuilder(MetaMetricsEvents.SIGNATURE_REQUESTED) | ||
.addProperties(analyticsParams) | ||
.build(), | ||
); | ||
}, [trackEvent, createEventBuilder, type, fromAddress]); | ||
|
||
if (!approvalRequest?.requestData?.securityAlertResponse) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<BlockaidBanner | ||
onContactUsClicked={onContactUsClicked} | ||
securityAlertResponse={ | ||
approvalRequest?.requestData?.securityAlertResponse | ||
} | ||
style={styles.blockaidBanner} | ||
/> | ||
); | ||
}; | ||
|
||
export default SignatureBlockaidBanner; |
1 change: 1 addition & 0 deletions
1
app/components/Views/confirmations/components/Confirm/SignatureBlockaidBanner/index.ts
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 @@ | ||
export { default } from './SignatureBlockaidBanner'; |
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