-
Notifications
You must be signed in to change notification settings - Fork 181
SEL-483: Implement recovery backup prompts #710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+317
−1
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4b4b5cd
feat: prompt users to back up account
transphorm c6f63ff
feat: prompt users to back up account
transphorm bfb3d5d
format
transphorm 4457f79
Add tests for recovery prompt logic
transphorm 329294a
Merge branch 'codex/prompt-users-to-enable-cloud-recovery' of github.…
transphorm e2dd66a
more lint updates
transphorm 7ca15aa
fix imports
transphorm 70f3b25
fix unused import
transphorm 7a8d8e2
update cursor suggestions
transphorm 8e823d4
implement coderabbit suggestions and fix tests
transphorm 8a3cdac
Merge branch 'dev' into codex/prompt-users-to-enable-cloud-recovery
transphorm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11 | ||
| import { useEffect } from 'react'; | ||
|
|
||
| import { navigationRef } from '../navigation'; | ||
| import { useSettingStore } from '../stores/settingStore'; | ||
| import { useModal } from './useModal'; | ||
|
|
||
| export default function useRecoveryPrompts() { | ||
| const { loginCount, cloudBackupEnabled, hasViewedRecoveryPhrase } = | ||
| useSettingStore(); | ||
| const { showModal, visible } = useModal({ | ||
| titleText: 'Protect your account', | ||
| bodyText: | ||
| 'Enable cloud backup or save your recovery phrase so you can recover your account.', | ||
| buttonText: 'Back up now', | ||
| onButtonPress: async () => { | ||
| if (navigationRef.isReady()) { | ||
| navigationRef.navigate('CloudBackupSettings', { | ||
| nextScreen: 'SaveRecoveryPhrase', | ||
| }); | ||
| } | ||
| }, | ||
| onModalDismiss: () => {}, | ||
| } as const); | ||
|
|
||
| useEffect(() => { | ||
| if (!navigationRef.isReady()) { | ||
| return; | ||
| } | ||
| if (!cloudBackupEnabled && !hasViewedRecoveryPhrase) { | ||
| const shouldPrompt = | ||
| loginCount > 0 && (loginCount <= 3 || (loginCount - 3) % 5 === 0); | ||
| if (shouldPrompt) { | ||
| showModal(); | ||
| } | ||
| } | ||
| }, [loginCount, cloudBackupEnabled, hasViewedRecoveryPhrase, showModal]); | ||
|
|
||
| return { visible }; | ||
| } | ||
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11 | ||
| import { renderHook } from '@testing-library/react-native'; | ||
|
|
||
| import { useModal } from '../../../src/hooks/useModal'; | ||
| import useRecoveryPrompts from '../../../src/hooks/useRecoveryPrompts'; | ||
| import { useSettingStore } from '../../../src/stores/settingStore'; | ||
|
|
||
| jest.mock('../../../src/hooks/useModal'); | ||
| jest.mock('../../../src/navigation', () => ({ | ||
| navigationRef: { | ||
| isReady: jest.fn(() => true), | ||
| navigate: jest.fn(), | ||
| }, | ||
| })); | ||
|
|
||
| const showModal = jest.fn(); | ||
| (useModal as jest.Mock).mockReturnValue({ showModal, visible: false }); | ||
|
|
||
| describe('useRecoveryPrompts', () => { | ||
| beforeEach(() => { | ||
| showModal.mockClear(); | ||
| useSettingStore.setState({ | ||
| loginCount: 0, | ||
| cloudBackupEnabled: false, | ||
| hasViewedRecoveryPhrase: false, | ||
| }); | ||
| }); | ||
|
|
||
| it('shows modal on first login', () => { | ||
| useSettingStore.getState().incrementLoginCount(); | ||
| renderHook(() => useRecoveryPrompts()); | ||
| expect(showModal).toHaveBeenCalled(); | ||
| }); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| it('does not show modal when login count is 4', () => { | ||
| useSettingStore.setState({ loginCount: 4 }); | ||
| renderHook(() => useRecoveryPrompts()); | ||
| expect(showModal).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('shows modal on eighth login', () => { | ||
| useSettingStore.setState({ loginCount: 8 }); | ||
| renderHook(() => useRecoveryPrompts()); | ||
| expect(showModal).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('does not show modal if backup already enabled', () => { | ||
| useSettingStore.setState({ loginCount: 1, cloudBackupEnabled: true }); | ||
| renderHook(() => useRecoveryPrompts()); | ||
| expect(showModal).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11 | ||
| import { useSettingStore } from '../../../src/stores/settingStore'; | ||
|
|
||
| describe('settingStore', () => { | ||
| beforeEach(() => { | ||
| useSettingStore.setState({ | ||
| loginCount: 0, | ||
| cloudBackupEnabled: false, | ||
| hasViewedRecoveryPhrase: false, | ||
| }); | ||
| }); | ||
|
|
||
| it('increments login count', () => { | ||
| useSettingStore.getState().incrementLoginCount(); | ||
| expect(useSettingStore.getState().loginCount).toBe(1); | ||
| }); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| it('resets login count when recovery phrase viewed', () => { | ||
| useSettingStore.setState({ loginCount: 2 }); | ||
| useSettingStore.getState().setHasViewedRecoveryPhrase(true); | ||
| expect(useSettingStore.getState().hasViewedRecoveryPhrase).toBe(true); | ||
| expect(useSettingStore.getState().loginCount).toBe(0); | ||
| }); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| it('resets login count when enabling cloud backup', () => { | ||
| useSettingStore.setState({ loginCount: 3, cloudBackupEnabled: false }); | ||
| useSettingStore.getState().toggleCloudBackupEnabled(); | ||
| expect(useSettingStore.getState().cloudBackupEnabled).toBe(true); | ||
| expect(useSettingStore.getState().loginCount).toBe(0); | ||
| }); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.