Skip to content

Commit

Permalink
Chore: Migrate E2ESaveYourPasswordView to Typescript (#3493)
Browse files Browse the repository at this point in the history
Co-authored-by: AlexAlexandre <alexalexandrejr@gmail.com>
Co-authored-by: Diego Mello <diegolmello@gmail.com>
  • Loading branch information
3 people authored Nov 17, 2021
1 parent 4ef0cfe commit 049e3f1
Showing 1 changed file with 22 additions and 14 deletions.
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));

0 comments on commit 049e3f1

Please sign in to comment.