diff --git a/packages/kit/src/routes/Modal/CreateWallet.tsx b/packages/kit/src/routes/Modal/CreateWallet.tsx index 5722c08d158..6dc66221e9a 100644 --- a/packages/kit/src/routes/Modal/CreateWallet.tsx +++ b/packages/kit/src/routes/Modal/CreateWallet.tsx @@ -74,7 +74,10 @@ export type CreateWalletRoutesParams = { }; [CreateWalletModalRoutes.NewWalletModal]: undefined; [CreateWalletModalRoutes.AppWalletDoneModal]: IAppWalletDoneModalParams; - [CreateWalletModalRoutes.SetupSuccessModal]: { device: SearchDevice }; + [CreateWalletModalRoutes.SetupSuccessModal]: { + device: SearchDevice; + onPressOnboardingFinished?: () => Promise; + }; [CreateWalletModalRoutes.SetupHardwareModal]: { device: SearchDevice }; [CreateWalletModalRoutes.SetupNewDeviceModal]: { device: SearchDevice; diff --git a/packages/kit/src/views/CreateWallet/HardwareWallet/SetupSuccess.tsx b/packages/kit/src/views/CreateWallet/HardwareWallet/SetupSuccess.tsx index 8c8a64b164a..6f8460b397c 100644 --- a/packages/kit/src/views/CreateWallet/HardwareWallet/SetupSuccess.tsx +++ b/packages/kit/src/views/CreateWallet/HardwareWallet/SetupSuccess.tsx @@ -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, @@ -20,10 +25,14 @@ type RouteProps = RouteProp< const SetupSuccessModal: FC = () => { const intl = useIntl(); const route = useRoute(); + // 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 = ( <> @@ -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 ( void; shouldStartCreating: boolean; + onPressOnboardingFinished?: () => Promise; }) { const toast = useToast(); const intl = useIntl(); @@ -101,7 +103,10 @@ function BehindTheSceneCreatingWallet({ screen: ModalRoutes.CreateWallet, params: { screen: CreateWalletModalRoutes.SetupSuccessModal, - params: { device }, + params: { + device, + onPressOnboardingFinished, + }, }, }); @@ -133,11 +138,12 @@ function BehindTheSceneCreatingWallet({ } return false; }, [ - forceVisibleUnfocused, isHardwareCreating?.device, isHardwareCreating?.features, - intl, + forceVisibleUnfocused, navigation, + onPressOnboardingFinished, + intl, ]); const startCreatingHDWallet = useCallback(async () => { @@ -304,6 +310,7 @@ const BehindTheScene = () => { routeParams={routeParams} handleWalletCreated={handleWalletCreated} shouldStartCreating={shouldStartCreating} + onPressOnboardingFinished={onPressFinished} /> {isRenderAsWebview ? (