Chore: Migrate E2ESaveYourPasswordView to Typescript (#3493)

Co-authored-by: AlexAlexandre <alexalexandrejr@gmail.com>
Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Reinaldo Neto 2021-11-17 17:05:35 -03:00 committed by GitHub
parent 4ef0cfe581
commit 049e3f164f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 14 deletions

View File

@ -1,5 +1,6 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import { StackNavigationProp } from '@react-navigation/stack';
import { Dispatch } from 'redux';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { Clipboard, ScrollView, StyleSheet, Text, View } from 'react-native'; import { Clipboard, ScrollView, StyleSheet, Text, View } from 'react-native';
@ -53,20 +54,26 @@ const styles = StyleSheet.create({
} }
}); });
class E2ESaveYourPasswordView extends React.Component { interface IE2ESaveYourPasswordViewState {
static navigationOptions = ({ navigation }) => ({ password: string;
}
interface IE2ESaveYourPasswordViewProps {
server: string;
navigation: StackNavigationProp<any, 'E2ESaveYourPasswordView'>;
encryptionSetBanner(): void;
theme: string;
}
class E2ESaveYourPasswordView extends React.Component<IE2ESaveYourPasswordViewProps, IE2ESaveYourPasswordViewState> {
private mounted: boolean;
static navigationOptions = ({ navigation }: Pick<IE2ESaveYourPasswordViewProps, 'navigation'>) => ({
headerLeft: () => <HeaderButton.CloseModal navigation={navigation} testID='e2e-save-your-password-view-close' />, headerLeft: () => <HeaderButton.CloseModal navigation={navigation} testID='e2e-save-your-password-view-close' />,
title: I18n.t('Save_Your_E2E_Password') title: I18n.t('Save_Your_E2E_Password')
}); });
static propTypes = { constructor(props: IE2ESaveYourPasswordViewProps) {
server: PropTypes.string,
navigation: PropTypes.object,
encryptionSetBanner: PropTypes.func,
theme: PropTypes.string
};
constructor(props) {
super(props); super(props);
this.mounted = false; this.mounted = false;
this.state = { password: '' }; this.state = { password: '' };
@ -83,8 +90,9 @@ class E2ESaveYourPasswordView extends React.Component {
// Set stored password on local state // Set stored password on local state
const password = await UserPreferences.getStringAsync(`${server}-${E2E_RANDOM_PASSWORD_KEY}`); const password = await UserPreferences.getStringAsync(`${server}-${E2E_RANDOM_PASSWORD_KEY}`);
if (this.mounted) { if (this.mounted) {
this.setState({ password }); this.setState({ password: password! });
} else { } else {
// @ts-ignore
this.state.password = password; this.state.password = password;
} }
} catch { } catch {
@ -164,10 +172,10 @@ class E2ESaveYourPasswordView extends React.Component {
} }
} }
const mapStateToProps = state => ({ const mapStateToProps = (state: any) => ({
server: state.server.server server: state.server.server
}); });
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = (dispatch: Dispatch) => ({
encryptionSetBanner: () => dispatch(encryptionSetBannerAction()) encryptionSetBanner: () => dispatch(encryptionSetBannerAction())
}); });
export default connect(mapStateToProps, mapDispatchToProps)(withTheme(E2ESaveYourPasswordView)); export default connect(mapStateToProps, mapDispatchToProps)(withTheme(E2ESaveYourPasswordView));