Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Migrate E2ESaveYourPasswordView to Typescript #3493

Merged
merged 3 commits into from
Nov 17, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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 { Clipboard, ScrollView, StyleSheet, Text, View } from 'react-native';

Expand Down Expand Up @@ -53,20 +54,26 @@ const styles = StyleSheet.create({
}
});

class E2ESaveYourPasswordView extends React.Component {
static navigationOptions = ({ navigation }) => ({
interface IE2ESaveYourPasswordViewState {
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' />,
title: I18n.t('Save_Your_E2E_Password')
});

static propTypes = {
server: PropTypes.string,
navigation: PropTypes.object,
encryptionSetBanner: PropTypes.func,
theme: PropTypes.string
};

constructor(props) {
constructor(props: IE2ESaveYourPasswordViewProps) {
super(props);
this.mounted = false;
this.state = { password: '' };
Expand All @@ -83,8 +90,9 @@ class E2ESaveYourPasswordView extends React.Component {
// Set stored password on local state
const password = await UserPreferences.getStringAsync(`${server}-${E2E_RANDOM_PASSWORD_KEY}`);
if (this.mounted) {
this.setState({ password });
this.setState({ password: password! });
} else {
// @ts-ignore
this.state.password = password;
}
} catch {
Expand Down Expand Up @@ -164,10 +172,10 @@ class E2ESaveYourPasswordView extends React.Component {
}
}

const mapStateToProps = state => ({
const mapStateToProps = (state: any) => ({
server: state.server.server
});
const mapDispatchToProps = dispatch => ({
const mapDispatchToProps = (dispatch: Dispatch) => ({
encryptionSetBanner: () => dispatch(encryptionSetBannerAction())
});
export default connect(mapStateToProps, mapDispatchToProps)(withTheme(E2ESaveYourPasswordView));