Skip to content

feat: Implement gas input validations in redesigned gas modals #15478

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

Merged
merged 6 commits into from
May 21, 2025

Conversation

OGPoyraz
Copy link
Member

Description

This PR aims to implement gas input validations.

To see it in action, please see the recordings below.

Related issues

Fixes: https://github.com/MetaMask/MetaMask-planning/issues/4919

Manual testing steps

N/A

Screenshots/Recordings

Before

After

eip1559.compatible.transaction.validations.mp4
legacy.transaction.validations.mp4

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.

@OGPoyraz OGPoyraz requested a review from a team as a code owner May 20, 2025 09:45
@metamaskbot metamaskbot added the team-confirmations Push issues to confirmations team label May 20, 2025
return strings('transactions.gas_modal.gas_limit_too_low');
};

export const validateGas = (value: string): string | boolean => {
Copy link
Contributor

Choose a reason for hiding this comment

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

minor, could we rename this to validateGasLimit to be more explicit?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call @digiwand, in fact we should use gas because we deprecated gasLimit https://github.com/MetaMask/core/blob/main/packages/transaction-controller/src/types.ts#L809

But I just noticed that I created input as gas-limit-input which creates confusion I guess, will rename it on ogp/4831 after merging this one 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

I am merging this now and will fix the concern in ultimate gas modal PR here: #15234

});
const isAnyErrorExists = errors.gasLimit || errors.gasPrice;
Copy link
Contributor

Choose a reason for hiding this comment

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

[suggestion] possibly we can rename isAnyErrorExistshasError

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

label: string;
} & TextFieldProps;

export const TextInputEnhanced = (props: TextInputEnhancedProps) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: as we're using TextField rather than TextInput, shall we rename this? maybe TextFieldWithLabel

Copy link
Member Author

Choose a reason for hiding this comment

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

Make sense, done

autoCorrect={false}
<TextInputEnhanced
error={error}
key="gas-limit"
Copy link
Contributor

Choose a reason for hiding this comment

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

[suggestion] possibly to prevent collision, we can incorporate more of the file path name
"modal-gas-fee-limit-input"

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think this will cause a collision since we are not rendering any list but I also agree that key is making a confusion and purpose is not clear - so I renamed this to inputType

Comment on lines 10 to 11


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

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -14,24 +17,28 @@ jest.mock('../../../../../../../../core/Engine', () => ({
},
}));

jest.mock('../../../../../utils/gas-validations', () => ({
validateGasPrice: jest.fn(),
}));
Copy link
Contributor

Choose a reason for hiding this comment

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

I am hesitant about mocking validateGasPrice. I think we can use jest spy without mocking its return value to verify it's called with the expected input

same comment applies to other instances in PR

Copy link
Member Author

Choose a reason for hiding this comment

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

I understand your point on spy over mocking. But we don't really need / want validation functions to be run on these tests because then it's not testing functionality of this unit and it's not an integration test. This is why we are capsulating all validation logic under different file and assuming that they are executing.

Copy link
Member Author

Choose a reason for hiding this comment

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

@digiwand to save some time, I am merging this into final gas modal PR. We can carry this conversation there <3

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.

Looking good! some comments and suggestions before approving

@OGPoyraz OGPoyraz added No QA Needed Apply this label when your PR does not need any QA effort. No E2E Smoke Needed If the PR does not need E2E smoke test run no-changelog Indicates no external facing user changes, therefore no changelog documentation needed labels May 21, 2025
@OGPoyraz OGPoyraz merged commit 6e92413 into ogp/4831 May 21, 2025
41 of 44 checks passed
@OGPoyraz OGPoyraz deleted the ogp/4919 branch May 21, 2025 11:41
@github-actions github-actions bot locked and limited conversation to collaborators May 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
No E2E Smoke Needed If the PR does not need E2E smoke test run No QA Needed Apply this label when your PR does not need any QA effort. no-changelog Indicates no external facing user changes, therefore no changelog documentation needed team-confirmations Push issues to confirmations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants