Skip to content

fix: Fix types associated with auto lock timer call#25109

Merged
danjm merged 5 commits intodevelopfrom
fix-auto-lock-timer
Jun 7, 2024
Merged

fix: Fix types associated with auto lock timer call#25109
danjm merged 5 commits intodevelopfrom
fix-auto-lock-timer

Conversation

@danjm
Copy link
Copy Markdown
Contributor

@danjm danjm commented Jun 6, 2024

Description

We see the following error in sentry
Screenshot from 2024-06-06 15-09-39

The problem occurs when the user sets this field in advanced settings
Screenshot from 2024-06-06 15-24-40

If that field is set to empty, then this code in /ui/pages/settings/advanced-tab/advanced-tab.component.test.js would result in setting the background state property to the string '0':

 if (autoLockTimeLimitBeforeNormalization === '') {
      this.setState({
        autoLockTimeLimitBeforeNormalization,
        autoLockTimeLimit: DEFAULT_AUTO_LOCK_TIME_LIMIT.toString(),
        lockTimeError: '',
      });

This toString call was introduced in #19653, but it doesn't seem to be necessary. It also conflicts with the type of the prop that is passed in to initially set this component state property. Also, the _resetTimer function in the app-state controller clearly expects this value to be a number.

The fix is to not set this component state value as a string. There are a couple of other type related fixes that are not strictly necessary for fixing the bug, but improve the code.

Open in GitHub Codespaces

Manual testing steps

  1. Go to the page Advanced Settings
  2. Set the "Auto-lock timer (minutes)" field to a non-zero integer (1 is best)
  3. Wait that many minutes without interacting with MetaMask, you will automatically be locked out
  4. Enter your password to unlock MetaMask
  5. Go to Advanced Settings
  6. Set the "Auto-lock timer (minutes)" field to empty (delete the number in the field but don't enter anything else) and save it
  7. Wait more than a minute, you won't be locked out.
  8. Check the service worker console, there will not be an error.

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've completed the PR template to the best of my ability
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). 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.

@danjm danjm requested a review from a team as a code owner June 6, 2024 18:02
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jun 6, 2024

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 metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Jun 6, 2024
@danjm danjm changed the title Fix types associated with auto lock timer call fix: Fix types associated with auto lock timer call Jun 7, 2024
@danjm danjm added the team-extension-platform Extension Platform team label Jun 7, 2024
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
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!

Comment on lines +291 to +298
// This is a temporary fix until we add a state migration.
// Due to a bug in ui/pages/settings/advanced-tab/advanced-tab.component.js,
// it was possible for timeoutMinutes to be saved as a string, as explained
// in PR 25109. `alarms.create` will fail in that case. We are
// converting this to a number here to prevent that failure. Once
// we add a migration to update the malformed state to the right type,
// we will remove this conversion.
const timeoutToSet = Number(timeoutMinutes);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we have an issue # for the migration task? I want to add a comment to it that this cast should be removed when the migration work is done.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I do not think we have created one yet

@codecov
Copy link
Copy Markdown

codecov bot commented Jun 7, 2024

Codecov Report

Attention: Patch coverage is 25.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 65.72%. Comparing base (7eaf6b7) to head (5af6083).
Report is 3 commits behind head on develop.

Files Patch % Lines
app/scripts/controllers/app-state.js 14.29% 6 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #25109   +/-   ##
========================================
  Coverage    65.71%   65.72%           
========================================
  Files         1360     1360           
  Lines        54041    54042    +1     
  Branches     14038    14038           
========================================
+ Hits         35513    35515    +2     
+ Misses       18528    18527    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@danjm danjm merged commit 4d7bbec into develop Jun 7, 2024
@danjm danjm deleted the fix-auto-lock-timer branch June 7, 2024 15:35
@github-actions github-actions bot locked and limited conversation to collaborators Jun 7, 2024
@metamaskbot metamaskbot added the release-12.1.0 Issue or pull request that will be included in release 12.1.0 label Jun 7, 2024
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [5af6083]
Page Load Metrics (49 ± 4 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint671078194
domContentLoaded9161021
load42734984
domInteractive9161021
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 26 Bytes (0.00%)
  • ui: -11 Bytes (-0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot metamaskbot added release-11.16.8 Issue or pull request that will be included in release 11.16.8 and removed release-12.1.0 Issue or pull request that will be included in release 12.1.0 labels Jun 7, 2024
@metamaskbot
Copy link
Copy Markdown
Collaborator

Missing release label release-11.16.8 on PR. Adding release label release-11.16.8 on PR and removing other release labels(release-12.1.0), as PR was cherry-picked in branch 11.16.8.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

INVALID-PR-TEMPLATE PR's body doesn't match template release-11.16.8 Issue or pull request that will be included in release 11.16.8 team-extension-platform Extension Platform team

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

TypeError: Error in invocation of alarms.create(optional string name, alarms.AlarmCreateInfo alarmInfo, opti...

5 participants