-
-
Couldn't load subscription status.
- Fork 319
Refactor: entropy thunks cleanup #22382
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,21 @@ | ||
| import { useCallback, useEffect } from 'react'; | ||
| import { useDispatch } from 'react-redux'; | ||
| import { useDispatch, useSelector } from 'react-redux'; | ||
|
|
||
| import { RouteProp, useNavigation, useRoute } from '@react-navigation/native'; | ||
| import { isFulfilled } from '@reduxjs/toolkit'; | ||
|
|
||
| import { | ||
| Feature, | ||
| MessageSystemRootState, | ||
| selectIsFeatureEnabled, | ||
| } from '@suite-common/message-system'; | ||
| import { createAndBackupWalletThunk } from '@suite-native/device'; | ||
| import { | ||
| DeviceOnboardingStackParamList, | ||
| DeviceOnboardingStackRoutes, | ||
| StackProps, | ||
| RootStackParamList, | ||
| RootStackRoutes, | ||
| StackToStackCompositeNavigationProps, | ||
| } from '@suite-native/navigation'; | ||
| import { ERRORS } from '@trezor/connect'; | ||
|
|
||
|
|
@@ -22,12 +30,26 @@ const DEFINITIVE_ERRORS: ERRORS.ErrorCode[] = [ | |
| 'Failure_EntropyCheck', | ||
| ]; | ||
|
|
||
| export const WalletCreationScreen = ({ | ||
| navigation, | ||
| route, | ||
| }: StackProps<DeviceOnboardingStackParamList, DeviceOnboardingStackRoutes.WalletCreation>) => { | ||
| type NavigationProp = StackToStackCompositeNavigationProps< | ||
| DeviceOnboardingStackParamList, | ||
| DeviceOnboardingStackRoutes.WalletCreation, | ||
| RootStackParamList | ||
| >; | ||
|
|
||
| type RouteProps = RouteProp< | ||
| DeviceOnboardingStackParamList, | ||
| DeviceOnboardingStackRoutes.WalletCreation | ||
| >; | ||
|
|
||
| export const WalletCreationScreen = () => { | ||
| const route = useRoute<RouteProps>(); | ||
| const { walletBackupType } = route.params; | ||
| const dispatch = useDispatch(); | ||
| const navigation = useNavigation<NavigationProp>(); | ||
|
|
||
| const isEntropyCheckEnabled = useSelector((state: MessageSystemRootState) => | ||
| selectIsFeatureEnabled(state, Feature.entropyCheckMobile, true), | ||
| ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extracting |
||
|
|
||
| const handleCreateAndBackupWallet = useCallback(async () => { | ||
| const response = await dispatch(createAndBackupWalletThunk({ walletBackupType })); | ||
|
|
@@ -40,16 +62,18 @@ export const WalletCreationScreen = ({ | |
| flowType: 'create', | ||
| }); | ||
| } | ||
| if ( | ||
| responsePayload.payload.code && | ||
| DEFINITIVE_ERRORS.includes(responsePayload.payload.code) | ||
| ) { | ||
| const { code } = responsePayload.payload; | ||
| if (code && DEFINITIVE_ERRORS.includes(code)) { | ||
| if (isEntropyCheckEnabled && code === 'Failure_EntropyCheck') { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: I think what's not ideal is that we could simply return the value of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. Together with your comment above it's a good followup for a next PR in future. |
||
| navigation.navigate(RootStackRoutes.DeviceCompromisedModal); | ||
| } | ||
|
|
||
| return; | ||
| } | ||
| } | ||
|
|
||
| // repeat the attempt if error was not one of the DEFINITIVE_ERRORS | ||
| handleCreateAndBackupWallet(); | ||
| }, [dispatch, walletBackupType, navigation]); | ||
| }, [dispatch, walletBackupType, navigation, isEntropyCheckEnabled]); | ||
|
|
||
| useEffect(() => { | ||
| handleCreateAndBackupWallet(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied the implementation from
suite.Unifying it will lower the surface for future human mistakes 🙂