Commit cdd3cd7
fix: Improved
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->
## **Description**
<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->
[](https://codespaces.new/MetaMask/metamask-extension/pull/38002?quickstart=1)
This PR improves the `useTheme` hook implementation to provide more
robust theme resolution and updates the unlock page logo to properly
respond to theme changes.
### 1. **Enhanced `useTheme` Hook** (`ui/hooks/useTheme.ts`)
- **Refactored theme resolution logic** into a separate `resolveTheme()`
function for better code organization and testability
- **Improved fallback mechanism** with the following priority:
1. User's explicit theme setting (`light` or `dark`)
2. System theme when "OS" is selected
3. Document theme attribute on initial load
4. System preference as final fallback
### 2. **Unlock Page Logo Component** (`ui/pages/unlock-page/`)
- Created new `MetaMaskWordmarkLogo` component that responds to theme
changes
- Updated styles to properly display logo based on theme
- Integrated `useTheme` hook for dynamic theme-aware rendering
### 3. **Test Snapshots Updates**
Updated Jest snapshots to reflect the new consistent theme behavior:
-
`ui/components/multichain-accounts/smart-contract-account-toggle/__snapshots__/smart-contract-account-toggle.test.tsx.snap`
-
`ui/components/multichain/network-list-menu/__snapshots__/network-list-menu.test.tsx.snap`
-
`ui/pages/settings/advanced-tab/__snapshots__/advanced-tab.component.test.js.snap`
-
`ui/pages/settings/security-tab/__snapshots__/security-tab.test.js.snap`
**Why snapshots changed:**
The improved `useTheme` hook now properly resolves to `light` theme by
default in tests (instead of `undefined`), causing `ToggleButton`
components to consistently render with light theme colors (`rgb(183,
187, 200)` = `#b7bbc8` = `lightTheme.colors.icon.muted`).
## **Changelog**
<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`
If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`
(This helps the Release Engineer do their job more quickly and
accurately)
-->
CHANGELOG entry: Updated useTheme hook and logo for unlock page
## **Related issues**
Fixes:
## **Manual testing steps**
1. Open Extension
2. Create Wallet
3. Lock Wallet
4. Validate the changes
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
### **After**
<!-- [screenshots/recordings] -->
https://github.com/user-attachments/assets/d14095eb-b4e5-4db7-a93f-bad6682f91c6
## **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/main/.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
- [x] 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/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **Pre-merge reviewer checklist**
- [x] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [x] 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.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Refactors `useTheme` for reliable light/dark resolution and updates
the unlock page wordmark logo to respond to theme, with minor CSS tweaks
and snapshot updates.
>
> - **Hooks**:
> - **`useTheme`**: Extracts `resolveTheme(settingTheme)` with clear
priority (explicit setting > OS when selected > document on initial load
> system), validates against `validThemes`, warns and defaults to
`light` if invalid; initializes state via resolver and applies on
setting changes.
> - **Unlock Page UI**:
> - **New `MetamaskWordmarkLogo`**: Uses `useTheme` and renders
`MetaFoxHorizontalLogo` with theme awareness; replaces direct logo usage
in `unlock-page.component.js`.
> - **Styles**: Adjusts
`unlock-page__mascot-container__horizontal-logo--popup` margins with
responsive override.
> - **Tests**:
> - Snapshot updates across settings and multichain components
reflecting consistent toggle colors (e.g., off `rgb(183, 187, 200)`, on
`rgb(68, 89, 255)`).
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
839eae4. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Chaitanya Potti <[email protected]>useTheme Hook and Unlock Page Logo Theme Handling (#38002)1 parent 6a69624 commit cdd3cd7
File tree
10 files changed
+103
-60
lines changed- ui
- components
- multichain-accounts
- smart-contract-account-toggle-section/__snapshots__
- smart-contract-account-toggle/__snapshots__
- hooks
- pages
- settings
- advanced-tab/__snapshots__
- developer-options-tab/__snapshots__
- security-tab/__snapshots__
- unlock-page
10 files changed
+103
-60
lines changedLines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
316 | | - | |
| 316 | + | |
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
| |||
363 | 363 | | |
364 | 364 | | |
365 | 365 | | |
366 | | - | |
| 366 | + | |
367 | 367 | | |
368 | 368 | | |
369 | 369 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
| 131 | + | |
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
759 | 759 | | |
760 | 760 | | |
761 | 761 | | |
762 | | - | |
| 762 | + | |
763 | 763 | | |
764 | 764 | | |
765 | 765 | | |
| |||
1867 | 1867 | | |
1868 | 1868 | | |
1869 | 1869 | | |
1870 | | - | |
| 1870 | + | |
1871 | 1871 | | |
1872 | 1872 | | |
1873 | 1873 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
| 7 | + | |
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
14 | 52 | | |
15 | 53 | | |
16 | 54 | | |
17 | 55 | | |
18 | 56 | | |
19 | | - | |
| 57 | + | |
20 | 58 | | |
21 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
22 | 62 | | |
23 | 63 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 64 | + | |
| 65 | + | |
40 | 66 | | |
41 | 67 | | |
42 | 68 | | |
| |||
0 commit comments