Skip to content
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

fix: Prevent coercing symbols to zero in the edit spending cap modal #28192

Merged
merged 1 commit into from
Nov 4, 2024

Conversation

pedronfigueiredo
Copy link
Contributor

@pedronfigueiredo pedronfigueiredo commented Oct 30, 2024

Description

Since the TextField in the "edit spending cap" modal has a type TextFieldType.Number, it already blocks most symbols and letters. However, it does currently support +, - and e characters as they can be used to construe numbers.

For example, when a - sign is introduced in the input field, the interim value is coerced to '', as there is no numerical equivalent to the sign by itself. The first part of this fix was to disable the "Save" button on such cases. If the user wants to revoke the spending cap, they can introduce 0, but '' is not a valid response.

Furthermore, when a valid number is introduced but that uses scientific notation or +/- signs, the submission is disabled and a validation message is shown to the user: "Enter numbers only".

Open in GitHub Codespaces

Related issues

Fixes: #28096

Manual testing steps

  1. Deploy an erc20 token contract in the test DApp
  2. Trigger an approve confirmation
  3. Attempt to edit the spending cap with -1, 10e10, or any others.
  4. You should be prevented from submitting and see the validation message.

Screenshots/Recordings

Before

After

Screenshot 2024-10-30 at 17 46 48

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.

@pedronfigueiredo pedronfigueiredo added the team-confirmations Push issues to confirmations team label Oct 30, 2024
@pedronfigueiredo pedronfigueiredo self-assigned this Oct 30, 2024
@pedronfigueiredo pedronfigueiredo requested review from a team as code owners October 30, 2024 17:57
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot
Copy link
Collaborator

Builds ready [e0b1cf3]
Page Load Metrics (1931 ± 101 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint168825951936214103
domContentLoaded16762546190720297
load168726051931210101
domInteractive1697522412
backgroundConnect9112292713
firstReactRender461981054019
getState469192010
initialActions01000
loadScripts11491845139317483
setupStore1172272211
uiStartup19012775217019895
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 177 Bytes (0.00%)
  • common: 63 Bytes (0.00%)

@@ -124,6 +124,8 @@ export const EditSpendingCapModal = ({
decimals &&
parseInt(decimals, 10) < countDecimalDigits(customSpendingCapInputValue);

const showSpecialCharacterError = /[-+e]/u.test(customSpendingCapInputValue);
Copy link
Member

Choose a reason for hiding this comment

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

Minor, is it worth a constant for the regex such as SPECIAL_CHARACTERS_PATTERN?

@@ -171,6 +173,15 @@ export const EditSpendingCapModal = ({
{t('editSpendingCapError', [decimals])}
</Text>
)}
{showSpecialCharacterError && (
<Text
Copy link
Member

Choose a reason for hiding this comment

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

Minor, is it worth a local Error component to avoid the duplication with the above decimal error?

@pedronfigueiredo pedronfigueiredo added this pull request to the merge queue Nov 4, 2024
Merged via the queue into develop with commit 49e5e78 Nov 4, 2024
76 checks passed
@pedronfigueiredo pedronfigueiredo deleted the pnf/28096 branch November 4, 2024 11:03
@github-actions github-actions bot locked and limited conversation to collaborators Nov 4, 2024
@metamaskbot metamaskbot added the release-12.8.0 Issue or pull request that will be included in release 12.8.0 label Nov 4, 2024
@sleepytanya
Copy link
Contributor

@pedronfigueiredo
User can use 0 as an input (Spending Cap request turns into Remove Permission) - expected behavior? Thank you!

spendingCapZero.mov

@pedronfigueiredo
Copy link
Contributor Author

Hey @sleepytanya, thanks for flagging this. It is expected!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.8.0 Issue or pull request that will be included in release 12.8.0 team-confirmations Push issues to confirmations team
Projects
None yet
5 participants