Skip to content

Commit 8765c91

Browse files
fix: cp-7.53.0 handle unrecognised Blockaid reasons in confirmation alerts (MetaMask#18077)
## **Description** Handle unrecognised Blockaid reasons in confirmation alerts, by displaying a generic message as a fallback. ## **Changelog** CHANGELOG entry: Fixed bug causing missing translation error in some Blockaid alerts ## **Related issues** Fixes: MetaMask#17823 ## **Manual testing steps** ## **Screenshots/Recordings** ### **Before** ### **After** ## **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.
1 parent dafe349 commit 8765c91

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

app/components/Views/confirmations/components/blockaid-alert-content/blockaid-alert-content.test.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { deflate } from 'react-native-gzip';
1010
import { BLOCKAID_SUPPORTED_NETWORK_NAMES } from '../../../../../util/networks';
1111
import BlockaidVersionInfo from '../../../../../lib/ppom/blockaid-version';
1212
import { ResultType as BlockaidResultType } from '../../constants/signatures';
13+
import { strings } from '../../../../../../locales/i18n';
1314

1415
jest.mock('react-native-gzip', () => ({
1516
deflate: jest.fn().mockResolvedValue('compressedData'),
@@ -161,4 +162,23 @@ describe('BlockaidAlertContent', () => {
161162
expect(deflate).not.toHaveBeenCalled();
162163
});
163164
});
165+
166+
it('renders generic reason message if reason not recognised', () => {
167+
const mockSecurityAlertResponseWithUnknownReason: SecurityAlertResponse = {
168+
...mockSecurityAlertResponse,
169+
reason: 'unknown_reason' as Reason,
170+
};
171+
172+
const { getByText } = render(
173+
<BlockaidAlertContent
174+
alertDetails={ALERT_DETAILS_MOCK}
175+
securityAlertResponse={mockSecurityAlertResponseWithUnknownReason}
176+
onContactUsClicked={mockOnContactUsClicked}
177+
/>,
178+
);
179+
180+
expect(
181+
getByText(strings('blockaid_banner.other_description')),
182+
).toBeDefined();
183+
});
164184
});

app/components/Views/confirmations/components/blockaid-alert-content/blockaid-alert-content.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const BlockaidAlertContent: React.FC<BlockaidAlertContentProps> = ({
9393
{strings(
9494
REASON_DESCRIPTION_I18N_KEY_MAP[
9595
securityAlertResponse.reason as Reason
96-
],
96+
] ?? 'blockaid_banner.other_description',
9797
)}
9898
</Text>
9999
<Accordion

0 commit comments

Comments
 (0)