import Clipboard from '@react-native-clipboard/clipboard'; import React, { useEffect, useLayoutEffect, useState } from 'react'; import { ScrollView, StyleSheet, Text, View } from 'react-native'; import { useDispatch } from 'react-redux'; import { StackActions, useNavigation } from '@react-navigation/native'; import { StackNavigationProp } from '@react-navigation/stack'; import { encryptionSetBanner } from '../actions/encryption'; import Button from '../containers/Button'; import * as HeaderButton from '../containers/HeaderButton'; import SafeAreaView from '../containers/SafeAreaView'; import StatusBar from '../containers/StatusBar'; import { LISTENER } from '../containers/Toast'; import I18n from '../i18n'; import { E2E_RANDOM_PASSWORD_KEY } from '../lib/constants'; import { useAppSelector } from '../lib/hooks'; import EventEmitter from '../lib/methods/helpers/events'; import { events, logEvent } from '../lib/methods/helpers/log'; import scrollPersistTaps from '../lib/methods/helpers/scrollPersistTaps'; import UserPreferences from '../lib/methods/userPreferences'; import { E2ESaveYourPasswordStackParamList } from '../stacks/types'; import { useTheme } from '../theme'; import sharedStyles from './Styles'; const styles = StyleSheet.create({ container: { flex: 1, paddingTop: 32 }, content: { marginVertical: 68, alignItems: 'center' }, warning: { fontSize: 16, ...sharedStyles.textMedium, textAlign: 'center' }, passwordText: { fontSize: 14, marginBottom: 8, ...sharedStyles.textAlignCenter }, password: { fontSize: 24, marginBottom: 24, ...sharedStyles.textBold }, copyButton: { width: 72, height: 32 }, info: { fontSize: 16, marginBottom: 64, ...sharedStyles.textRegular, textAlign: 'center' } }); const E2ESaveYourPasswordView = () => { const server = useAppSelector(state => state.server.server); const navigation = useNavigation>(); const dispatch = useDispatch(); const [password, setPassword] = useState(''); const { colors } = useTheme(); useLayoutEffect(() => { navigation.setOptions({ title: I18n.t('Save_Your_E2E_Password'), headerLeft: () => }); }, [navigation]); useEffect(() => { const init = () => { const password = UserPreferences.getString(`${server}-${E2E_RANDOM_PASSWORD_KEY}`); if (password) setPassword(password); }; init(); }, []); const onSaved = () => { logEvent(events.E2E_SAVE_PW_SAVED); UserPreferences.removeItem(`${server}-${E2E_RANDOM_PASSWORD_KEY}`); dispatch(encryptionSetBanner()); navigation.dispatch(StackActions.pop()); }; const onCopy = () => { logEvent(events.E2E_SAVE_PW_COPY); if (password) { Clipboard.setString(password); EventEmitter.emit(LISTENER, { message: I18n.t('Copied_to_clipboard') }); } }; const onHowItWorks = () => { logEvent(events.E2E_SAVE_PW_HOW_IT_WORKS); navigation.navigate('E2EHowItWorksView'); }; return ( {I18n.t('Save_Your_Encryption_Password_warning')} {I18n.t('Your_password_is')} {password}