Skip to content

Commit

Permalink
OK-7749, OK-7920 fix recover account navigation. (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
linleiqin authored Apr 18, 2022
1 parent c4be72f commit d64c806
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable react-hooks/exhaustive-deps */
import React, { FC, useEffect } from 'react';

import { useNavigation } from '@react-navigation/core';
import { RouteProp, useRoute } from '@react-navigation/native';

import { Center, Modal, Spinner } from '@onekeyhq/components';
Expand All @@ -10,7 +9,6 @@ import {
CreateAccountModalRoutes,
CreateAccountRoutesParams,
} from '@onekeyhq/kit/src/routes';
import { ModalScreenProps } from '@onekeyhq/kit/src/routes/types';

export type EnableLocalAuthenticationProps = {
password: string;
Expand All @@ -37,12 +35,10 @@ const HDAccountAuthenticationDone: FC<EnableLocalAuthenticationProps> = ({
</Center>
);
};
type NavigationProps = ModalScreenProps<CreateAccountRoutesParams>;

export const HDAccountAuthentication: FC = () => {
const route = useRoute<RouteProps>();
const { onDone } = route.params;
const navigation = useNavigation<NavigationProps['navigation']>();
return (
<Modal footer={null}>
<Protected>
Expand All @@ -51,7 +47,6 @@ export const HDAccountAuthentication: FC = () => {
password={password}
onDone={() => {
onDone(password);
navigation?.goBack();
}}
/>
)}
Expand Down
34 changes: 9 additions & 25 deletions packages/kit/src/views/Account/AddNewAccount/RecoverAccounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ import {
CreateAccountModalRoutes,
CreateAccountRoutesParams,
} from '@onekeyhq/kit/src/routes';
import {
ModalRoutes,
ModalScreenProps,
RootRoutes,
} from '@onekeyhq/kit/src/routes/types';
import { ModalScreenProps } from '@onekeyhq/kit/src/routes/types';

type NavigationProps = ModalScreenProps<CreateAccountRoutesParams>;

Expand Down Expand Up @@ -202,30 +198,18 @@ const RecoverAccounts: FC = () => {
id: 'account__recover_Step_1_of_2',
})}`}
onBackActionPress={() => {
navigation.navigate(RootRoutes.Modal, {
screen: ModalRoutes.CreateAccount,
params: {
screen: CreateAccountModalRoutes.CreateAccountForm,
params: {
walletId,
},
},
navigation.navigate(CreateAccountModalRoutes.CreateAccountForm, {
walletId,
});
}}
primaryActionTranslationId="action__next"
onPrimaryActionPress={() => {
navigation.navigate(RootRoutes.Modal, {
screen: ModalRoutes.CreateAccount,
params: {
screen: CreateAccountModalRoutes.RecoverAccountsConfirm,
params: {
accounts: [
...flatListData.filter((i) => !i.isDisabled && i.selected),
],
walletId,
network,
},
},
navigation.navigate(CreateAccountModalRoutes.RecoverAccountsConfirm, {
accounts: [
...flatListData.filter((i) => !i.isDisabled && i.selected),
],
walletId,
network,
});
}}
primaryActionProps={{
Expand Down
51 changes: 15 additions & 36 deletions packages/kit/src/views/Account/AddNewAccount/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ import {
CreateAccountModalRoutes,
CreateAccountRoutesParams,
} from '@onekeyhq/kit/src/routes';
import {
ModalRoutes,
ModalScreenProps,
RootRoutes,
} from '@onekeyhq/kit/src/routes/types';
import { ModalScreenProps } from '@onekeyhq/kit/src/routes/types';

type PrivateKeyFormValues = {
network: string;
Expand Down Expand Up @@ -85,7 +81,6 @@ const CreateAccount: FC<CreateAccountProps> = ({ onClose }) => {
title: intl.formatMessage({ id: errorKey }),
});
}

closeDrawer();
if (navigation.canGoBack()) {
navigation.getParent()?.goBack?.();
Expand All @@ -96,14 +91,10 @@ const CreateAccount: FC<CreateAccountProps> = ({ onClose }) => {
);

const onSubmit = handleSubmit(() => {
navigation.navigate(RootRoutes.Modal, {
screen: ModalRoutes.CreateAccount,
params: {
screen: CreateAccountModalRoutes.CreateAccountAuthentication,
params: {
onDone: authenticationDone,
},
},
console.log('onSubmit');

navigation.navigate(CreateAccountModalRoutes.CreateAccountAuthentication, {
onDone: authenticationDone,
});
});

Expand Down Expand Up @@ -145,30 +136,18 @@ const CreateAccount: FC<CreateAccountProps> = ({ onClose }) => {
</Typography.Body2>
<Pressable
onPress={() => {
navigation.navigate(RootRoutes.Modal, {
screen: ModalRoutes.CreateAccount,
params: {
screen:
CreateAccountModalRoutes.CreateAccountAuthentication,
params: {
onDone: (password) => {
const network = getValues('network');
navigation.navigate(RootRoutes.Modal, {
screen: ModalRoutes.CreateAccount,
params: {
screen:
CreateAccountModalRoutes.RecoverAccountsList,
params: {
walletId: selectedWalletId,
network,
password,
},
},
});
},
navigation.navigate(
CreateAccountModalRoutes.CreateAccountAuthentication,
{
onDone: (password) => {
const network = getValues('network');
navigation.navigate(
CreateAccountModalRoutes.RecoverAccountsList,
{ walletId: selectedWalletId, network, password },
);
},
},
});
);
}}
>
<Typography.Body2Underline color="action-primary-default">
Expand Down

0 comments on commit d64c806

Please sign in to comment.