-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: prevent actions that require private key in demo mode (#6469)
### Description Unfortunately not all flows that access the private key go through the same functions, so this PR adds a new blocking bottom sheet that is a screen and navigates to it from: 1. `ensurePincode` - this is used from the flows that launch CAB / reset pin / view recovery phrase 2. `sendPreparedTransaction` - this is used from all the transaction flows, except for walletconnect 3. walletconnect saga, where we display the action request. There is often UI that awaits the outcome of the transaction send flows (spinners, navigation etc.) so I am returning the same result as if a user dismissed the pincode screen during the flow. ### Test plan Tested all flows to ensure the bottom sheet is correctly triggered, and no extra errors are displayed. https://github.com/user-attachments/assets/f376d1a7-a62c-43fa-b8a3-c598f81711d8 https://github.com/user-attachments/assets/eb817506-1cc1-4a8f-91c0-f9f3560e1455 https://github.com/user-attachments/assets/7bcdf0ee-00d9-465c-89c7-41f613669440 https://github.com/user-attachments/assets/5fbedfcd-7e2d-4b00-b61f-cec38788eb75 https://github.com/user-attachments/assets/55d26718-fa74-4406-a02f-257fdbc293c9 ### Related issues - Fixes RET-1304 ### Backwards compatibility Y ### Network scalability If a new NetworkId and/or Network are added in the future, the changes in this PR will: - [ ] Continue to work without code changes, OR trigger a compilation error (guaranteeing we find it when a new network is added)
- Loading branch information
1 parent
1b52dd5
commit 60ecc4e
Showing
14 changed files
with
171 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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,60 @@ | ||
import { fireEvent, render } from '@testing-library/react-native' | ||
import React from 'react' | ||
import { Provider } from 'react-redux' | ||
import DemoModeAuthBlock from 'src/navigator/DemoModeAuthBlock' | ||
import { navigateBack, navigateClearingStack } from 'src/navigator/NavigationService' | ||
import { demoModeToggled } from 'src/web3/actions' | ||
import { createMockStore } from 'test/utils' | ||
import { mockAccount } from 'test/values' | ||
|
||
jest.mock('src/statsig') | ||
|
||
describe('DemoModeAuthBlock', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
it('renders correctly and executes the expected actions on button press', () => { | ||
const store = createMockStore({ | ||
web3: { | ||
account: mockAccount, | ||
}, | ||
}) | ||
const { getByText } = render( | ||
<Provider store={store}> | ||
<DemoModeAuthBlock /> | ||
</Provider> | ||
) | ||
|
||
expect(getByText('demoMode.restrictedAccess.title')).toBeTruthy() | ||
expect(getByText('demoMode.restrictedAccess.info')).toBeTruthy() | ||
|
||
fireEvent.press(getByText('demoMode.restrictedAccess.cta')) | ||
|
||
expect(store.getActions()).toEqual([demoModeToggled(false)]) | ||
expect(navigateBack).toHaveBeenCalledTimes(1) | ||
expect(navigateClearingStack).not.toHaveBeenCalled() | ||
|
||
fireEvent.press(getByText('dismiss')) | ||
expect(navigateBack).toHaveBeenCalledTimes(2) | ||
}) | ||
|
||
it('navigates to onboarding when exiting demo mode', () => { | ||
const store = createMockStore({ | ||
web3: { | ||
account: null, // no wallet set up | ||
}, | ||
}) | ||
const { getByText } = render( | ||
<Provider store={store}> | ||
<DemoModeAuthBlock /> | ||
</Provider> | ||
) | ||
|
||
fireEvent.press(getByText('demoMode.restrictedAccess.cta')) | ||
|
||
expect(store.getActions()).toEqual([demoModeToggled(false)]) | ||
expect(navigateBack).toHaveBeenCalled() | ||
expect(navigateClearingStack).toHaveBeenCalled() | ||
}) | ||
}) |
This file contains 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,61 @@ | ||
import React from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { StyleSheet, Text } from 'react-native' | ||
import BottomSheetScrollView from 'src/components/BottomSheetScrollView' | ||
import Button, { BtnSizes, BtnTypes } from 'src/components/Button' | ||
import { navigateBack, navigateClearingStack } from 'src/navigator/NavigationService' | ||
import { Screens } from 'src/navigator/Screens' | ||
import { useDispatch, useSelector } from 'src/redux/hooks' | ||
import { typeScale } from 'src/styles/fonts' | ||
import { Spacing } from 'src/styles/styles' | ||
import { demoModeToggled } from 'src/web3/actions' | ||
import { rawWalletAddressSelector } from 'src/web3/selectors' | ||
|
||
export default function DemoModeAuthBlock() { | ||
const { t } = useTranslation() | ||
const dispatch = useDispatch() | ||
const originalWalletAddress = useSelector(rawWalletAddressSelector) | ||
|
||
const handleExitDemoMode = () => { | ||
dispatch(demoModeToggled(false)) | ||
navigateBack() // dismiss the bottom sheet | ||
|
||
if (!originalWalletAddress) { | ||
navigateClearingStack(Screens.Welcome) | ||
} | ||
} | ||
|
||
return ( | ||
<BottomSheetScrollView> | ||
<Text style={styles.title}>{t('demoMode.restrictedAccess.title')}</Text> | ||
<Text style={styles.description}>{t('demoMode.restrictedAccess.info')}</Text> | ||
<Button | ||
style={styles.demoModeButton} | ||
onPress={handleExitDemoMode} | ||
text={t('demoMode.restrictedAccess.cta')} | ||
type={BtnTypes.SECONDARY} | ||
size={BtnSizes.FULL} | ||
/> | ||
<Button | ||
style={styles.demoModeButton} | ||
onPress={navigateBack} | ||
text={t('dismiss')} | ||
size={BtnSizes.FULL} | ||
/> | ||
</BottomSheetScrollView> | ||
) | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
title: { | ||
...typeScale.titleSmall, | ||
marginBottom: Spacing.Regular16, | ||
}, | ||
description: { | ||
...typeScale.bodySmall, | ||
marginBottom: Spacing.Small12, | ||
}, | ||
demoModeButton: { | ||
marginTop: Spacing.Small12, | ||
}, | ||
}) |
This file contains 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -12,4 +12,5 @@ export default { | |
footerHeight: 60, | ||
fontSizeBase: 15, | ||
iconHitslop, | ||
demoModeBorderWidth: 3, | ||
} |
This file contains 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 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 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 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