Chore: Migrate ChangePasscodeView to Typescript (#3482)

This commit is contained in:
Reinaldo Neto 2021-11-10 17:50:38 -03:00 committed by GitHub
parent 8b4e39d1cf
commit 138f0ab444
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 14 deletions

View File

@ -8,7 +8,7 @@ import I18n from '../../i18n';
interface IPasscodeChoose { interface IPasscodeChoose {
theme: string; theme: string;
force: boolean; force?: boolean;
finishProcess: Function; finishProcess: Function;
} }

View File

@ -1,15 +1,13 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { StyleSheet } from 'react-native'; import { StyleSheet } from 'react-native';
import PropTypes from 'prop-types';
import Orientation from 'react-native-orientation-locker'; import Orientation from 'react-native-orientation-locker';
import useDeepCompareEffect from 'use-deep-compare-effect'; import useDeepCompareEffect from 'use-deep-compare-effect';
import isEmpty from 'lodash/isEmpty'; import isEmpty from 'lodash/isEmpty';
import Modal from 'react-native-modal'; import Modal from 'react-native-modal';
import Touchable from 'react-native-platform-touchable'; import Touchable from 'react-native-platform-touchable';
import { withTheme } from '../theme'; import { useTheme } from '../theme';
import { hasNotch, isTablet } from '../utils/deviceInfo'; import { hasNotch, isTablet } from '../utils/deviceInfo';
import { TYPE } from '../containers/Passcode/constants';
import { PasscodeChoose } from '../containers/Passcode'; import { PasscodeChoose } from '../containers/Passcode';
import EventEmitter from '../utils/events'; import EventEmitter from '../utils/events';
import { CustomIcon } from '../lib/Icons'; import { CustomIcon } from '../lib/Icons';
@ -27,9 +25,17 @@ const styles = StyleSheet.create({
} }
}); });
const ChangePasscodeView = React.memo(({ theme }) => { interface IArgs {
submit(passcode: string): void;
cancel(): void;
force: boolean;
}
const ChangePasscodeView = React.memo(() => {
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const [data, setData] = useState({}); const [data, setData] = useState<Partial<IArgs>>({});
const { theme } = useTheme();
useDeepCompareEffect(() => { useDeepCompareEffect(() => {
if (!isEmpty(data)) { if (!isEmpty(data)) {
@ -39,11 +45,11 @@ const ChangePasscodeView = React.memo(({ theme }) => {
} }
}, [data]); }, [data]);
const showChangePasscode = args => { const showChangePasscode = (args: IArgs) => {
setData(args); setData(args);
}; };
const onSubmit = passcode => { const onSubmit = (passcode: string) => {
const { submit } = data; const { submit } = data;
if (submit) { if (submit) {
submit(passcode); submit(passcode);
@ -74,7 +80,7 @@ const ChangePasscodeView = React.memo(({ theme }) => {
return ( return (
<Modal useNativeDriver isVisible={visible} hideModalContentWhileAnimating style={styles.modal}> <Modal useNativeDriver isVisible={visible} hideModalContentWhileAnimating style={styles.modal}>
<PasscodeChoose theme={theme} type={TYPE.choose} finishProcess={onSubmit} force={data?.force} /> <PasscodeChoose theme={theme} finishProcess={onSubmit} force={data?.force} />
{!data?.force ? ( {!data?.force ? (
<Touchable onPress={onCancel} style={styles.close}> <Touchable onPress={onCancel} style={styles.close}>
<CustomIcon name='close' color={themes[theme].passcodePrimary} size={30} /> <CustomIcon name='close' color={themes[theme].passcodePrimary} size={30} />
@ -84,8 +90,4 @@ const ChangePasscodeView = React.memo(({ theme }) => {
); );
}); });
ChangePasscodeView.propTypes = { export default ChangePasscodeView;
theme: PropTypes.string
};
export default withTheme(ChangePasscodeView);