Skip to content

Commit a09d076

Browse files
authored
fix(cherry-pick) : selector getKnownMethodData should return empty object if user has opted out for using 4Byte Resolution (#27213)
## **Description** If user has toggled off **Decode smart contracts** setting he is not able to approve ERC20. This is regression introduced recently. ## **Related issues** Fixes: #27188 ## **Manual testing steps** 1. Toggle off setting "Decode smart contracts" 2. Try to approve an ERC 20 3. It should not throw error ## **Screenshots/Recordings** https://github.com/user-attachments/assets/7f0fd8f9-3d97-4f4b-8e99-c694445ad929 ## **Pre-merge author checklist** - [X] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.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 - [ ] 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-extension/blob/develop/.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 4b48aa9 commit a09d076

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

ui/pages/confirmations/components/confirm/info/hooks/useFourByte.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('useFourByte', () => {
3434
expect(result.current.params).toEqual([]);
3535
});
3636

37-
it('returns undefined if resolution is turned off', () => {
37+
it('returns empty object if resolution is turned off', () => {
3838
const currentConfirmation = genUnapprovedContractInteractionConfirmation({
3939
address: CONTRACT_INTERACTION_SENDER_ADDRESS,
4040
txData: depositHexData,
@@ -54,7 +54,7 @@ describe('useFourByte', () => {
5454
},
5555
);
5656

57-
expect(result.current).toBeUndefined();
57+
expect(result.current).toEqual({});
5858
});
5959

6060
it("returns undefined if it's not known even if resolution is enabled", () => {
@@ -75,6 +75,6 @@ describe('useFourByte', () => {
7575
},
7676
);
7777

78-
expect(result.current).toBeUndefined();
78+
expect(result.current).toEqual({});
7979
});
8080
});

ui/pages/confirmations/components/confirm/info/shared/transaction-details/transaction-details.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const MethodDataRow = () => {
7070

7171
const methodData = useFourByte(currentConfirmation);
7272

73-
if (!methodData) {
73+
if (!methodData?.name) {
7474
return null;
7575
}
7676

ui/selectors/selectors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ export function getKnownMethodData(state, data) {
12361236
const fourBytePrefix = prefixedData.slice(0, 10);
12371237
const { knownMethodData, use4ByteResolution } = state.metamask;
12381238
// If 4byte setting is off, we do not want to return the knownMethodData
1239-
return use4ByteResolution ? knownMethodData?.[fourBytePrefix] : undefined;
1239+
return use4ByteResolution ? knownMethodData?.[fourBytePrefix] ?? {} : {};
12401240
}
12411241

12421242
export function getFeatureFlags(state) {

0 commit comments

Comments
 (0)