Skip to content

Commit 47c0d65

Browse files
authored
fix: in recipient validations for internal accounts (#20694)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** fix: recipient validation for internal accounts ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: ## **Related issues** Ref: MetaMask/MetaMask-planning#5931 ## **Manual testing steps** ```gherkin Feature: my feature name Scenario: user [verb for user action] Given [describe expected initial app state] When user [verb for user action] Then [describe expected outcome] ``` ## **Screenshots/Recordings** TODO ## **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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Stop skipping to-address validation for internal-account and address-book recipients across EVM and non-EVM flows, and update tests accordingly. > > - **Validation**: > - EVM: `shouldSkipValidation` no longer skips when `toAddress` is in the address book or matches an internal account (continues validation instead). > - Non-EVM: `shouldSkipValidation` no longer skips when `toAddress` matches an internal account. > - **Tests**: > - Remove assertions expecting skip when `toAddress` is in address book or an internal account for both EVM and non-EVM hooks. > - Keep existing validation tests (burn address, contract address warning, ENS/confusables, Solana). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 27fc32f. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 8b934b0 commit 47c0d65

File tree

4 files changed

+3
-65
lines changed

4 files changed

+3
-65
lines changed

app/components/Views/confirmations/hooks/send/evm/useEvmToAddressValidation.test.ts

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -54,48 +54,6 @@ describe('shouldSkipValidation', () => {
5454
} as unknown as ShouldSkipValidationArgs),
5555
).toStrictEqual(true);
5656
});
57-
it('returns true if to address is present in address book', () => {
58-
expect(
59-
shouldSkipValidation({
60-
toAddress: '0x935E73EDb9fF52E23BaC7F7e043A1ecD06d05477',
61-
chainId: '0x1',
62-
addressBook: {},
63-
internalAccounts: [],
64-
} as unknown as ShouldSkipValidationArgs),
65-
).toStrictEqual(false);
66-
expect(
67-
shouldSkipValidation({
68-
toAddress: '0x935E73EDb9fF52E23BaC7F7e043A1ecD06d05477',
69-
chainId: '0x1',
70-
addressBook: {
71-
'0x1': {
72-
'0x935E73EDb9fF52E23BaC7F7e043A1ecD06d05477': {},
73-
},
74-
},
75-
internalAccounts: [],
76-
} as unknown as ShouldSkipValidationArgs),
77-
).toStrictEqual(true);
78-
});
79-
it('returns true if to address is an internal account', () => {
80-
expect(
81-
shouldSkipValidation({
82-
toAddress: '0x935E73EDb9fF52E23BaC7F7e043A1ecD06d05477',
83-
chainId: '0x1',
84-
addressBook: {},
85-
internalAccounts: [],
86-
} as unknown as ShouldSkipValidationArgs),
87-
).toStrictEqual(false);
88-
expect(
89-
shouldSkipValidation({
90-
toAddress: '0x935E73EDb9fF52E23BaC7F7e043A1ecD06d05477',
91-
chainId: '0x1',
92-
addressBook: {},
93-
internalAccounts: [
94-
{ address: '0x935E73EDb9fF52E23BaC7F7e043A1ecD06d05477' },
95-
],
96-
} as unknown as ShouldSkipValidationArgs),
97-
).toStrictEqual(true);
98-
});
9957
});
10058

10159
describe('validateToAddress', () => {

app/components/Views/confirmations/hooks/send/evm/useEvmToAddressValidation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ export const shouldSkipValidation = ({
4646
const existingContact =
4747
address && chainId && addressBook[chainId as Hex]?.[address];
4848
if (existingContact) {
49-
return true;
49+
return false;
5050
}
5151

5252
// sending to an internal account
5353
const internalAccount = internalAccounts.find((account) =>
5454
areAddressesEqual(account.address, address),
5555
);
5656
if (internalAccount) {
57-
return true;
57+
return false;
5858
}
5959

6060
return false;

app/components/Views/confirmations/hooks/send/non-evm/useNonEvmToAddressValidation.test.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,6 @@ describe('shouldSkipValidation', () => {
5050
} as unknown as ShouldSkipValidationArgs),
5151
).toStrictEqual(true);
5252
});
53-
it('returns true if to address is an internal account', () => {
54-
expect(
55-
shouldSkipValidation({
56-
toAddress: '0x935E73EDb9fF52E23BaC7F7e043A1ecD06d05477',
57-
chainId: '0x1',
58-
addressBook: {},
59-
internalAccounts: [],
60-
} as unknown as ShouldSkipValidationArgs),
61-
).toStrictEqual(false);
62-
expect(
63-
shouldSkipValidation({
64-
toAddress: '0x935E73EDb9fF52E23BaC7F7e043A1ecD06d05477',
65-
chainId: '0x1',
66-
addressBook: {},
67-
internalAccounts: [
68-
{ address: '0x935E73EDb9fF52E23BaC7F7e043A1ecD06d05477' },
69-
],
70-
} as unknown as ShouldSkipValidationArgs),
71-
).toStrictEqual(true);
72-
});
7353
});
7454

7555
describe('validateToAddress', () => {

app/components/Views/confirmations/hooks/send/non-evm/useNonEvmToAddressValidation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const shouldSkipValidation = ({
3030
areAddressesEqual(account.address, toAddress),
3131
);
3232
if (internalAccount) {
33-
return true;
33+
return false;
3434
}
3535

3636
return false;

0 commit comments

Comments
 (0)