import type { FC } from '../../lib/teact/teact'; import React, { memo, useRef } from '../../lib/teact/teact'; import { getActions, withGlobal } from '../../global'; import type { GlobalState } from '../../global/types'; import '../../global/actions/initial'; import { PLATFORM_ENV } from '../../util/windowEnvironment'; import useHistoryBack from '../../hooks/useHistoryBack'; import useCurrentOrPrev from '../../hooks/useCurrentOrPrev'; import useElectronDrag from '../../hooks/useElectronDrag'; import Transition from '../ui/Transition'; import AuthPhoneNumber from './AuthPhoneNumber'; import AuthCode from './AuthCode.async'; import AuthPassword from './AuthPassword.async'; import AuthRegister from './AuthRegister.async'; import AuthQrCode from './AuthQrCode'; import './Auth.scss'; type StateProps = Pick; const Auth: FC = ({ authState, }) => { const { returnToAuthPhoneNumber, goToAuthQrCode, } = getActions(); const isMobile = PLATFORM_ENV === 'iOS' || PLATFORM_ENV === 'Android'; const handleChangeAuthorizationMethod = () => { if (!isMobile) { goToAuthQrCode(); } else { returnToAuthPhoneNumber(); } }; useHistoryBack({ isActive: (!isMobile && authState === 'authorizationStateWaitPhoneNumber') || (isMobile && authState === 'authorizationStateWaitQrCode'), onBack: handleChangeAuthorizationMethod, }); // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); useElectronDrag(containerRef); // For animation purposes const renderingAuthState = useCurrentOrPrev( authState !== 'authorizationStateReady' ? authState : undefined, true, ); function getScreen() { switch (renderingAuthState) { case 'authorizationStateWaitCode': return ; case 'authorizationStateWaitPassword': return ; case 'authorizationStateWaitRegistration': return ; case 'authorizationStateWaitPhoneNumber': return ; case 'authorizationStateWaitQrCode': return ; default: return isMobile ? : ; } } function getActiveKey() { switch (renderingAuthState) { case 'authorizationStateWaitCode': return 0; case 'authorizationStateWaitPassword': return 1; case 'authorizationStateWaitRegistration': return 2; case 'authorizationStateWaitPhoneNumber': return 3; case 'authorizationStateWaitQrCode': return 4; default: return isMobile ? 3 : 4; } } return ( {getScreen()} ); }; export default memo(withGlobal( (global): StateProps => { return { authState: global.authState, }; }, )(Auth));