Skip to content

Commit

Permalink
fix: do not open the CreateWallet screen if the wallet does not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
limpbrains committed Oct 7, 2024
1 parent 0f5e75d commit 7b313c5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
11 changes: 7 additions & 4 deletions src/navigation/onboarding/OnboardingNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import CreateWallet, {
import { NavigationContainer } from '../../styles/components';
import { useAppSelector } from '../../hooks/redux';
import { requiresRemoteRestoreSelector } from '../../store/reselect/user';
import { walletExistsSelector } from '../../store/reselect/wallet';

export type OnboardingStackParamList = {
TermsOfUse: undefined;
Expand All @@ -38,13 +39,15 @@ const navOptionHandlerNoBack = {

const OnboardingNavigator = (): ReactElement => {
const requiresRemoteRestore = useAppSelector(requiresRemoteRestoreSelector);
const walletExists = useAppSelector(walletExistsSelector);

// If a wallet exists but remote LDK revocery is not complete, show the CreateWallet screen
const initialRouteName =
walletExists && requiresRemoteRestore ? 'CreateWallet' : 'TermsOfUse';

return (
<NavigationContainer>
<Stack.Navigator
initialRouteName={
requiresRemoteRestore ? 'CreateWallet' : 'TermsOfUse'
}>
<Stack.Navigator initialRouteName={initialRouteName}>
<Stack.Screen
name="TermsOfUse"
component={TermsOfUse}
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Onboarding/CreateWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const CreateWallet = ({
return;
}

if (params?.action === 'create') {
if (params.action === 'create') {
handleCreate(params.bip39Passphrase);
} else {
handleRestore(params.mnemonic, params.bip39Passphrase);
Expand Down
28 changes: 16 additions & 12 deletions src/screens/Onboarding/Slideshow.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
import React, {
memo,
ReactElement,
useState,
useRef,
useMemo,
useEffect,
memo,
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from 'react';
import { Trans, useTranslation } from 'react-i18next';
import {
Image,
ImageSourcePropType,
Platform,
StyleSheet,
View,
useWindowDimensions,
Platform,
} from 'react-native';
import Carousel, { ICarouselInstance } from 'react-native-reanimated-carousel';
import Animated, {
interpolate,
useAnimatedStyle,
useSharedValue,
} from 'react-native-reanimated';
import { Trans, useTranslation } from 'react-i18next';
import Carousel, { ICarouselInstance } from 'react-native-reanimated-carousel';

import { View as ThemedView } from '../../styles/components';
import { Display, BodyM, BodyMB } from '../../styles/text';
import { IThemeColors } from '../../styles/themes';
import SafeAreaInset from '../../components/SafeAreaInset';
import Dot from '../../components/SliderDots';
import Button from '../../components/buttons/Button';
import ButtonTertiary from '../../components/buttons/ButtonTertiary';
import { useAppDispatch } from '../../hooks/redux';
import type { OnboardingStackScreenProps } from '../../navigation/types';
import { updateUser } from '../../store/slices/user';
import { View as ThemedView } from '../../styles/components';
import { BodyM, BodyMB, Display } from '../../styles/text';
import { IThemeColors } from '../../styles/themes';

type Slide = {
color: keyof IThemeColors;
Expand Down Expand Up @@ -134,6 +136,7 @@ const Slideshow = ({
}: OnboardingStackScreenProps<'Slideshow'>): ReactElement => {
const skipIntro = route.params?.skipIntro ?? false;
const bip39Passphrase = route.params?.bip39Passphrase;
const dispatch = useAppDispatch();
const dimensions = useWindowDimensions();
const { t } = useTranslation('onboarding');
const ref = useRef<ICarouselInstance>(null);
Expand Down Expand Up @@ -169,11 +172,12 @@ const Slideshow = ({
};

const onCreateWallet = useCallback(async (): Promise<void> => {
dispatch(updateUser({ requiresRemoteRestore: false }));
navigation.navigate('CreateWallet', {
action: 'create',
bip39Passphrase,
});
}, [bip39Passphrase, navigation]);
}, [bip39Passphrase, dispatch, navigation]);

const onRestoreWallet = (): void => {
navigation.navigate('MultipleDevices');
Expand Down

0 comments on commit 7b313c5

Please sign in to comment.