import Clipboard from '@react-native-clipboard/clipboard' import { NativeStackScreenProps } from '@react-navigation/native-stack' import React, { useLayoutEffect, useRef } from 'react' import { useTranslation } from 'react-i18next' import { ScrollView, StyleSheet, Text, View } from 'react-native' import { SafeAreaView } from 'react-native-safe-area-context' import { recoveryPhraseInOnboardingCompleted } from 'src/account/actions' import AppAnalytics from 'src/analytics/AppAnalytics' import { OnboardingEvents } from 'src/analytics/Events' import BackupPhraseContainer, { BackupPhraseContainerMode, BackupPhraseType, } from 'src/backup/BackupPhraseContainer' import { useAccountKey } from 'src/backup/utils' import BottomSheet, { BottomSheetModalRefType } from 'src/components/BottomSheet' import Button, { BtnSizes, BtnTypes } from 'src/components/Button' import TextButton from 'src/components/TextButton' import CopyIcon from 'src/icons/CopyIcon' import { HeaderTitleWithSubtitle, nuxNavigationOptionsOnboarding } from 'src/navigator/Headers' import { Screens } from 'src/navigator/Screens' import { TopBarTextButton } from 'src/navigator/TopBarButton' import { StackParamList } from 'src/navigator/types' import { getOnboardingStepValues, goToNextOnboardingScreen, onboardingPropsSelector, } from 'src/onboarding/steps' import { useDispatch, useSelector } from 'src/redux/hooks' import colors from 'src/styles/colors' import { typeScale } from 'src/styles/fonts' import { Spacing } from 'src/styles/styles' import Logger from 'src/utils/Logger' type Props = NativeStackScreenProps function OnboardingRecoveryPhrase({ navigation, route }: Props) { const infoBottomSheetRef = useRef(null) const onboardingProps = useSelector(onboardingPropsSelector) // Use a lower step count for CAB onboarding const { step, totalSteps } = getOnboardingStepValues( route.params?.origin === 'cabOnboarding' ? Screens.SignInWithEmail : Screens.ProtectWallet, onboardingProps ) const accountKey = useAccountKey() const dispatch = useDispatch() const { t } = useTranslation() useLayoutEffect(() => { navigation.setOptions({ headerTitle: () => { return ( ) }, headerRight: () => ( ), }) }, [navigation, step, totalSteps]) const onPressHelp = () => { AppAnalytics.track(OnboardingEvents.protect_wallet_help) infoBottomSheetRef.current?.snapToIndex(0) } const onPressDismissBottomSheet = () => { AppAnalytics.track(OnboardingEvents.protect_wallet_help_dismiss) infoBottomSheetRef.current?.close() } const onPressCopy = () => { AppAnalytics.track(OnboardingEvents.protect_wallet_copy_phrase) Clipboard.setString(accountKey ?? '') Logger.showMessage(t('recoveryPhrase.mnemonicCopied')) } const onPressContinue = () => { AppAnalytics.track(OnboardingEvents.protect_wallet_complete) dispatch(recoveryPhraseInOnboardingCompleted()) goToNextOnboardingScreen({ firstScreenInCurrentStep: Screens.ProtectWallet, onboardingProps }) } return ( {t('recoveryPhrase.titleV1_90')} {t('recoveryPhrase.bodyV1_90')} {t('recoveryPhrase.copy')}