2020-09-11 14:31:38 +00:00
|
|
|
import React from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { ScrollView, StyleSheet, Text } from 'react-native';
|
2020-09-11 14:31:38 +00:00
|
|
|
import { connect } from 'react-redux';
|
2021-11-17 20:03:53 +00:00
|
|
|
import { Dispatch } from 'redux';
|
|
|
|
import { StackNavigationOptions, StackNavigationProp } from '@react-navigation/stack';
|
2020-09-11 14:31:38 +00:00
|
|
|
|
|
|
|
import I18n from '../i18n';
|
|
|
|
import { withTheme } from '../theme';
|
|
|
|
import Button from '../containers/Button';
|
|
|
|
import { themes } from '../constants/colors';
|
|
|
|
import TextInput from '../containers/TextInput';
|
|
|
|
import SafeAreaView from '../containers/SafeAreaView';
|
2020-10-30 16:15:58 +00:00
|
|
|
import * as HeaderButton from '../containers/HeaderButton';
|
2020-09-11 14:31:38 +00:00
|
|
|
import { encryptionDecodeKey as encryptionDecodeKeyAction } from '../actions/encryption';
|
|
|
|
import scrollPersistTaps from '../utils/scrollPersistTaps';
|
|
|
|
import KeyboardView from '../presentation/KeyboardView';
|
|
|
|
import StatusBar from '../containers/StatusBar';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { events, logEvent } from '../utils/log';
|
|
|
|
import sharedStyles from './Styles';
|
2021-12-03 19:27:57 +00:00
|
|
|
import { E2EEnterYourPasswordStackParamList } from '../stacks/types';
|
2020-09-11 14:31:38 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
padding: 28
|
|
|
|
},
|
|
|
|
info: {
|
|
|
|
fontSize: 14,
|
|
|
|
marginVertical: 8,
|
|
|
|
...sharedStyles.textRegular
|
|
|
|
}
|
|
|
|
});
|
2021-11-17 20:03:53 +00:00
|
|
|
|
|
|
|
interface IE2EEnterYourPasswordViewState {
|
|
|
|
password: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IE2EEnterYourPasswordViewProps {
|
|
|
|
encryptionDecodeKey: (password: string) => void;
|
|
|
|
theme: string;
|
2021-12-03 19:27:57 +00:00
|
|
|
navigation: StackNavigationProp<E2EEnterYourPasswordStackParamList, 'E2EEnterYourPasswordView'>;
|
2021-11-17 20:03:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class E2EEnterYourPasswordView extends React.Component<IE2EEnterYourPasswordViewProps, IE2EEnterYourPasswordViewState> {
|
|
|
|
private passwordInput?: TextInput;
|
|
|
|
|
|
|
|
static navigationOptions = ({ navigation }: Pick<IE2EEnterYourPasswordViewProps, 'navigation'>): StackNavigationOptions => ({
|
2020-10-30 16:15:58 +00:00
|
|
|
headerLeft: () => <HeaderButton.CloseModal navigation={navigation} testID='e2e-enter-your-password-view-close' />,
|
2020-09-11 14:31:38 +00:00
|
|
|
title: I18n.t('Enter_Your_E2E_Password')
|
2021-09-13 20:41:05 +00:00
|
|
|
});
|
2020-09-11 14:31:38 +00:00
|
|
|
|
2021-11-17 20:03:53 +00:00
|
|
|
constructor(props: IE2EEnterYourPasswordViewProps) {
|
2020-09-11 14:31:38 +00:00
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
password: ''
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
submit = () => {
|
|
|
|
logEvent(events.E2E_ENTER_PW_SUBMIT);
|
|
|
|
const { password } = this.state;
|
|
|
|
const { encryptionDecodeKey } = this.props;
|
|
|
|
encryptionDecodeKey(password);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-09-11 14:31:38 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
const { password } = this.state;
|
|
|
|
const { theme } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<KeyboardView
|
|
|
|
style={{ backgroundColor: themes[theme].backgroundColor }}
|
|
|
|
contentContainerStyle={sharedStyles.container}
|
2021-09-13 20:41:05 +00:00
|
|
|
keyboardVerticalOffset={128}>
|
2020-10-30 13:59:44 +00:00
|
|
|
<StatusBar />
|
2021-09-13 20:41:05 +00:00
|
|
|
<ScrollView
|
|
|
|
{...scrollPersistTaps}
|
|
|
|
style={sharedStyles.container}
|
2021-11-17 20:03:53 +00:00
|
|
|
contentContainerStyle={sharedStyles.containerScrollView}>
|
2021-09-13 20:41:05 +00:00
|
|
|
<SafeAreaView
|
|
|
|
style={[styles.container, { backgroundColor: themes[theme].backgroundColor }]}
|
|
|
|
testID='e2e-enter-your-password-view'>
|
2020-09-11 14:31:38 +00:00
|
|
|
<TextInput
|
2021-11-17 20:03:53 +00:00
|
|
|
inputRef={(e: TextInput) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
this.passwordInput = e;
|
|
|
|
}}
|
2020-09-11 14:31:38 +00:00
|
|
|
placeholder={I18n.t('Password')}
|
|
|
|
returnKeyType='send'
|
|
|
|
secureTextEntry
|
|
|
|
onSubmitEditing={this.submit}
|
|
|
|
onChangeText={value => this.setState({ password: value })}
|
|
|
|
testID='e2e-enter-your-password-view-password'
|
|
|
|
textContentType='password'
|
|
|
|
autoCompleteType='password'
|
|
|
|
theme={theme}
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
onPress={this.submit}
|
|
|
|
title={I18n.t('Confirm')}
|
|
|
|
disabled={!password}
|
|
|
|
theme={theme}
|
2020-10-30 18:31:04 +00:00
|
|
|
testID='e2e-enter-your-password-view-confirm'
|
2020-09-11 14:31:38 +00:00
|
|
|
/>
|
|
|
|
<Text style={[styles.info, { color: themes[theme].bodyText }]}>{I18n.t('Enter_Your_Encryption_Password_desc1')}</Text>
|
|
|
|
<Text style={[styles.info, { color: themes[theme].bodyText }]}>{I18n.t('Enter_Your_Encryption_Password_desc2')}</Text>
|
|
|
|
</SafeAreaView>
|
|
|
|
</ScrollView>
|
|
|
|
</KeyboardView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-17 20:03:53 +00:00
|
|
|
const mapDispatchToProps = (dispatch: Dispatch) => ({
|
|
|
|
encryptionDecodeKey: (password: string) => dispatch(encryptionDecodeKeyAction(password))
|
2020-09-11 14:31:38 +00:00
|
|
|
});
|
|
|
|
export default connect(null, mapDispatchToProps)(withTheme(E2EEnterYourPasswordView));
|