Skip to content

Fix autolock field to accept decimals in Firefox#19653

Merged
mcmire merged 6 commits intodevelopfrom
fix-autolock-time-field
Jun 22, 2023
Merged

Fix autolock field to accept decimals in Firefox#19653
mcmire merged 6 commits intodevelopfrom
fix-autolock-time-field

Conversation

@mcmire
Copy link
Copy Markdown
Contributor

@mcmire mcmire commented Jun 18, 2023

Explanation

The autolock field on the Settings screen — the field that allows users to set the duration that MetaMask will wait for until automatically locking — does not always accept decimal numbers. This breaks the e2e test for this feature as it attempts to set this field to "0.1".

More specifically, the React component responsible for this field passes whatever the user inputs through the Number function immediately and then uses this to repopulate the input. Therefore, if the user enters "3" followed by a ".", Number("3.") will be called. This evaluates to the number 3, and "3" becomes the new value of the field. As a result, the "." can never be typed.

Curiously, this behavior only happens in Firefox; Chrome seems to keep the "." in the input field when it's typed. This happens because onChange event doesn't seem to get fired until a number is typed after the ".". This may be due to underlying differences in the DOM between Chrome and Firefox.

Regardless, always passing the input through Number creates other odd behavior, such as the fact that the input can never be cleared (because Number("") evaluates to 0).

This commit solves these problems by saving the "raw" version of the user's input as well as the normalized version. The raw version is always used to populate the input, whereas the normalized version is saved in state.

Screenshots/Screencaps

Before

Chrome

It's hard to see, but 1) pressing Backspace when it says "0" does nothing and 2) adding numbers after the decimal does nothing.

before-chrome.mov

Firefox

It's hard to see, but 1) pressing Backspace when it says "0" does nothing, 2) adding decimals or anything after the decimal resets the field to "0".

before-firefox.mov

After

Chrome

after-chrome.mov

Firefox

after-firefox.mov

Manual Testing Steps

Fundamentally you should ensure that if you go into Settings > Advanced, update the autolock setting to 1, save, then wait 1 minute, MetaMask should automatically lock. You should also see an error (and should not be able to save) if you enter a number past 10080.

With this change, however, you should also be able to enter 0.1, and MetaMask should autolock in 5 seconds.

Also, if you empty the field, it should default to 5 minutes (this has always been the placeholder value for this input, it's just that it never got used).

All of this behavior should be the same in both Chrome and Firefox.

Past this, all other settings on the page should work as intended.

Pre-merge author checklist

  • I've clearly explained:
    • What problem this PR is solving
    • How this problem was solved
    • How reviewers can test my changes
  • Sufficient automated test coverage has been added

Pre-merge reviewer checklist

  • Manual testing (e.g. pull and build branch, run in browser, test code being changed)
  • PR is linked to the appropriate GitHub issue
  • IF this PR fixes a bug in the release milestone, add this PR to the release milestone

If further QA is required (e.g. new feature, complex testing steps, large refactor), add the Extension QA Board label.

In this case, a QA Engineer approval will be be required.

@github-actions
Copy link
Copy Markdown
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.

@mcmire mcmire force-pushed the fix-autolock-time-field branch 3 times, most recently from 5ac3611 to 0c121aa Compare June 18, 2023 04:14
@codecov
Copy link
Copy Markdown

codecov bot commented Jun 18, 2023

Codecov Report

Merging #19653 (c7958f3) into develop (7949ec9) will decrease coverage by 0.00%.
The diff coverage is 78.95%.

@@             Coverage Diff             @@
##           develop   #19653      +/-   ##
===========================================
- Coverage    70.79%   70.79%   -0.00%     
===========================================
  Files          988      988              
  Lines        38366    38375       +9     
  Branches     10042    10046       +4     
===========================================
+ Hits         27161    27167       +6     
- Misses       11205    11208       +3     
Impacted Files Coverage Δ
ui/ducks/metamask/metamask.js 77.78% <ø> (ø)
...es/settings/advanced-tab/advanced-tab.component.js 59.76% <69.23%> (-0.37%) ⬇️
app/scripts/controllers/app-state.js 40.30% <100.00%> (+0.45%) ⬆️
shared/constants/preferences.ts 100.00% <100.00%> (ø)
ui/pages/routes/routes.container.js 58.82% <100.00%> (+2.57%) ⬆️
...es/settings/advanced-tab/advanced-tab.container.js 44.83% <100.00%> (ø)

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [0c121aa]
Page Load Metrics (1498 ± 45 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint111180130178
domContentLoaded1360179014979345
load1360179014989345
domInteractive1360179014979345
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 8 bytes
  • ui: 397 bytes
  • common: 0 bytes

@mcmire mcmire force-pushed the fix-autolock-time-field branch from 0c121aa to 1f32af1 Compare June 18, 2023 04:55
@mcmire mcmire changed the title Fix autolock time field Fix autolock field to accept decimals in Firefox Jun 18, 2023
@mcmire mcmire force-pushed the fix-autolock-time-field branch 2 times, most recently from ae0f5f9 to cc247be Compare June 18, 2023 05:13
The autolock field on the Settings screen — the field that allows users
to set the duration that MetaMask will wait for until automatically
locking — does not always accept decimal numbers. This breaks the e2e
test for this feature as it attempts to set this field to "0.1".

More specifically, the React component responsible for this field passes
whatever the user inputs through the `Number` function immediately and
then uses this to repopulate the input. Therefore, if the user enters
"3" followed by a ".", `Number("3.")` will be called. This evaluates to
the number 3, and "3" becomes the new value of the field. As a result,
the "." can never be typed.

Curiously, this behavior only happens in Firefox; Chrome seems to
keep the "." in the input field when it's typed. This happens because
`onChange` event doesn't seem to get fired until a number is typed
*after* the ".". This may be due to underlying differences in the DOM
between Chrome and Firefox.

Regardless, always passing the input through `Number` creates other odd
behavior, such as the fact that the input can never be cleared (because
`Number("")` evaluates to 0).

This commit solves these problems by saving the "raw" version of the
user's input as well as the normalized version. The raw version is
always used to populate the input, whereas the normalized version is
saved in state.
@mcmire mcmire force-pushed the fix-autolock-time-field branch from cc247be to 363a85d Compare June 18, 2023 05:30
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [363a85d]
Page Load Metrics (1569 ± 43 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint97178117189
domContentLoaded1436170615427033
load1436180915699043
domInteractive1436170615427033
Bundle size diffs
  • background: 0 bytes
  • ui: 332 bytes
  • common: 0 bytes

@mcmire mcmire marked this pull request as ready for review June 18, 2023 23:32
@mcmire mcmire requested a review from a team as a code owner June 18, 2023 23:32
@mcmire mcmire requested a review from Gtonizuka June 18, 2023 23:32
Gudahtt
Gudahtt previously approved these changes Jun 19, 2023
Copy link
Copy Markdown
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [511b2f2]
Page Load Metrics (1480 ± 26 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint9313510594
domContentLoaded1371157714545125
load1371157814805526
domInteractive1371157714545125
Bundle size diffs
  • background: 0 bytes
  • ui: 332 bytes
  • common: 0 bytes

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [2069663]
Page Load Metrics (1631 ± 65 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint103161122157
domContentLoaded1471191315989947
load14712058163113465
domInteractive1471191315989947
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 171 bytes
  • ui: 1029 bytes
  • common: 64 bytes

Copy link
Copy Markdown
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [c7958f3]
Page Load Metrics (1629 ± 45 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint103166128189
domContentLoaded1439179116038842
load1465179216299345
domInteractive1439179116038842
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 171 bytes
  • ui: 1029 bytes
  • common: 87 bytes

@mcmire mcmire merged commit bd12ea7 into develop Jun 22, 2023
@mcmire mcmire deleted the fix-autolock-time-field branch June 22, 2023 16:29
@github-actions github-actions bot locked and limited conversation to collaborators Jun 22, 2023
@metamaskbot metamaskbot added the release-10.34.0 Issue or pull request that will be included in release 10.34.0 label Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-10.34.0 Issue or pull request that will be included in release 10.34.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants