Skip to content

Commit

Permalink
fix: android hw connect modal close (#1276)
Browse files Browse the repository at this point in the history
  • Loading branch information
zuozhuo authored Aug 9, 2022
1 parent 0f2ba92 commit 9be56b0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
5 changes: 4 additions & 1 deletion packages/kit/src/routes/Modal/CreateWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ export type CreateWalletRoutesParams = {
};
[CreateWalletModalRoutes.NewWalletModal]: undefined;
[CreateWalletModalRoutes.AppWalletDoneModal]: IAppWalletDoneModalParams;
[CreateWalletModalRoutes.SetupSuccessModal]: { device: SearchDevice };
[CreateWalletModalRoutes.SetupSuccessModal]: {
device: SearchDevice;
onPressOnboardingFinished?: () => Promise<void>;
};
[CreateWalletModalRoutes.SetupHardwareModal]: { device: SearchDevice };
[CreateWalletModalRoutes.SetupNewDeviceModal]: {
device: SearchDevice;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import React, { FC } from 'react';
import React, { FC, useCallback } from 'react';

import { RouteProp, useRoute } from '@react-navigation/core';
import { useIntl } from 'react-intl';

import { Center, Icon, Modal, Typography } from '@onekeyhq/components';
import useModalClose from '@onekeyhq/components/src/Modal/Container/useModalClose';
import {
CreateWalletModalRoutes,
CreateWalletRoutesParams,
} from '@onekeyhq/kit/src/routes/Modal/CreateWallet';

import { useNavigationActions } from '../../../hooks';
import { closeExtensionWindowIfOnboardingFinished } from '../../../hooks/useOnboardingRequired';
import {
closeExtensionWindowIfOnboardingFinished,
useOnboardingDone,
} from '../../../hooks/useOnboardingRequired';
import { wait } from '../../../utils/helper';

type RouteProps = RouteProp<
CreateWalletRoutesParams,
Expand All @@ -20,10 +25,14 @@ type RouteProps = RouteProp<
const SetupSuccessModal: FC = () => {
const intl = useIntl();
const route = useRoute<RouteProps>();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { openRootHome } = useNavigationActions();
const closeModal = useModalClose();
const onboardingDone = useOnboardingDone();

// const isSmallScreen = useIsVerticalLayout();

const { device } = route?.params;
const { device, onPressOnboardingFinished } = route?.params;

const content = (
<>
Expand Down Expand Up @@ -51,12 +60,28 @@ const SetupSuccessModal: FC = () => {
</>
);

const onPressClose = useCallback(async () => {
// close current SetupSuccess modal
closeModal();

if (onPressOnboardingFinished) {
await wait(2000);
onPressOnboardingFinished?.();
} else {
// close onboarding routes ( including openRootHome() )
// ** not working for Android first time onBoarding
onboardingDone({ delay: 600 });
}
}, [closeModal, onPressOnboardingFinished, onboardingDone]);

return (
<Modal
header={device.name ?? ''}
headerDescription={intl.formatMessage({ id: 'content__activated' })}
secondaryActionTranslationId="action__close"
onSecondaryActionPress={openRootHome}
secondaryActionProps={{
onPress: onPressClose,
}}
staticChildrenProps={{
flex: '1',
p: 6,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ function BehindTheSceneCreatingWallet({
routeParams,
handleWalletCreated,
shouldStartCreating,
onPressOnboardingFinished,
}: {
routeParams: IOnboardingBehindTheSceneParams;
handleWalletCreated: () => void;
shouldStartCreating: boolean;
onPressOnboardingFinished?: () => Promise<void>;
}) {
const toast = useToast();
const intl = useIntl();
Expand Down Expand Up @@ -101,7 +103,10 @@ function BehindTheSceneCreatingWallet({
screen: ModalRoutes.CreateWallet,
params: {
screen: CreateWalletModalRoutes.SetupSuccessModal,
params: { device },
params: {
device,
onPressOnboardingFinished,
},
},
});

Expand Down Expand Up @@ -133,11 +138,12 @@ function BehindTheSceneCreatingWallet({
}
return false;
}, [
forceVisibleUnfocused,
isHardwareCreating?.device,
isHardwareCreating?.features,
intl,
forceVisibleUnfocused,
navigation,
onPressOnboardingFinished,
intl,
]);

const startCreatingHDWallet = useCallback(async () => {
Expand Down Expand Up @@ -304,6 +310,7 @@ const BehindTheScene = () => {
routeParams={routeParams}
handleWalletCreated={handleWalletCreated}
shouldStartCreating={shouldStartCreating}
onPressOnboardingFinished={onPressFinished}
/>
{isRenderAsWebview ? (
<Center h="full" w="full">
Expand Down

0 comments on commit 9be56b0

Please sign in to comment.