REF: Prompt Modal with useReducer and tests#8622
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors PromptPasswordConfirmationSheet to use a useReducer-based state model and introduces unit tests to cover key UI flows and reducer behavior.
Changes:
- Refactor
PromptPasswordConfirmationSheetstate management from multipleuseStatecalls to a dedicated reducer (PromptPasswordConfirmationSheet.reducer.ts). - Add unit tests covering modal flows (enter/create password, fake storage) and reducer behavior.
- Adjust the navigation stack options for the prompt sheet (notably removing the header title).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| screen/PromptPasswordConfirmationSheet.tsx | Refactors state handling to useReducer, extracts shake logic, and adds an alert path for password mismatch. |
| screen/PromptPasswordConfirmationSheet.reducer.ts | New reducer module defining state/actions and resettable initial state. |
| tests/unit/PromptPasswordConfirmationSheet.test.tsx | New UI-oriented unit tests for the sheet, including navigation/storage/haptics mocks. |
| tests/unit/prompt-password-confirmation-reducer.test.ts | New unit tests validating reducer transitions and initial state behavior. |
| navigation/PromptPasswordConfirmationStack.tsx | Updates stack screen options; currently removes the localized title. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (isCreateFlow && password && confirmPassword && password !== confirmPassword) { | ||
| failWithShake(); | ||
| presentAlert({ message: loc.settings.passwords_do_not_match }); | ||
| return; |
| options={navigationStyle({ | ||
| title: loc.settings.password, | ||
| presentation: 'formSheet', |
|
|
||
| it('rejects CREATE_FAKE_STORAGE when password is already in use', async () => { | ||
| setRoute({ modalType: MODAL_TYPES.CREATE_FAKE_STORAGE, returnTo: 'PlausibleDeniability' }); | ||
| mockIsPasswordInUse.mockResolvedValue(true); |
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
GladosBlueWallet
left a comment
There was a problem hiding this comment.
The sheet's state machine is much less fragile now, and the tests cover the actual transitions instead of worshipping a mock altar. The shake/error paths remain intact, the create/encrypt flows are cleaner, and the reducer makes the whole thing less haunted. Another small miracle: the code now remembers what state it is in.
No description provided.