[pull] main from MetaMask:main#564
Merged
Merged
Conversation
#26484) <!-- 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** **Reason for the change:** The `SwitchAccountTypeModal` component was using the `useRoute()` hook internally to access route parameters. This approach has several drawbacks: - Tightly couples the component to the navigation context - Makes type derivation less explicit (required unsafe type assertion: `(route?.params as { address: Hex })?.address`) - Reduces testability as tests needed to mock the `useRoute` hook globally - No graceful handling when address parameter is missing **Improvement/Solution:** - Refactored `SwitchAccountTypeModal` to receive `route` as a prop instead of calling `useRoute()` internally - Added proper TypeScript interfaces: `SwitchAccountTypeModalRouteParams`, `SwitchAccountTypeModalParamList`, and `SwitchAccountTypeModalProps` - Added fallback UI with "No account selected" message when no address is available from route params - Added missing `key` prop to `AccountNetworkRow` component in the map function (fixes React key warning) - Significantly expanded test coverage: - Organized tests into logical describe blocks (`rendering`, `route params handling`, `navigation`, `hook integration`) - Added tests for empty network list, multiple networks, loading state - Added tests for address matching/non-matching scenarios - Added test for hook integration to verify correct address is passed ## **Changelog** CHANGELOG entry: null ## **Related issues** Fixes: N/A (internal refactoring) ## **Manual testing steps** ```gherkin Feature: Switch Account Type Modal (EIP-7702) Scenario: User opens switch account type modal with valid address Given the user has an account upgraded to a smart account on a supported network And the user is viewing account details When user taps on "Switch account type" Then user should see the Switch Account Type modal And user should see their account name And user should see the list of networks where the account is upgraded And each network row should show "Smart account" status Scenario: User switches back to regular account Given the user is viewing the Switch Account Type modal And the account is currently a smart account on Sepolia When user taps "Switch back" on the Sepolia row Then the account should be downgraded to a regular account on Sepolia Scenario: User navigates back from modal Given the user is viewing the Switch Account Type modal When user taps the back button Then the modal should close And user should return to the previous screen Scenario: Modal shows loading state while fetching network data Given the network data is still being fetched When user opens the Switch Account Type modal Then user should see a loading spinner And the network list should not be visible ``` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** N/A - No visual changes (except for new fallback state) ### **After** N/A - No visual changes (except for new fallback state when no address is available) ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/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-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )