diff --git a/native/account/logged-out-modal.react.js b/native/account/logged-out-modal.react.js --- a/native/account/logged-out-modal.react.js +++ b/native/account/logged-out-modal.react.js @@ -50,19 +50,14 @@ } from '../navigation/route-names.js'; import { useSelector } from '../redux/redux-utils.js'; import { usePersistedStateLoaded } from '../selectors/app-state-selectors.js'; -import { - type DerivedDimensionsInfo, - derivedDimensionsInfoSelector, -} from '../selectors/dimensions-selectors.js'; +import { derivedDimensionsInfoSelector } from '../selectors/dimensions-selectors.js'; import { splashStyleSelector } from '../splash.js'; import { useStyles } from '../themes/colors.js'; import type { KeyboardEvent } from '../types/react-native.js'; -import type { ImageStyle } from '../types/styles.js'; import { runTiming, ratchetAlongWithKeyboardHeight, } from '../utils/animation-utils.js'; -import type { StateContainer } from '../utils/state-container.js'; import EthereumLogo from '../vectors/ethereum-logo.react.js'; let initialAppLoad = true; @@ -218,239 +213,11 @@ }, }; -type BaseProps = { +type Props = { +navigation: RootNavigationProp<'LoggedOutModal'>, +route: NavigationRoute<'LoggedOutModal'>, }; -type Props = { - ...BaseProps, - +logInStateContainer: StateContainer, - +legacyRegisterStateContainer: StateContainer, - +mode: Mode, - +contentHeight: Value, - +keyboardHeightValue: Value, - +buttonOpacity: Value, - +panelPaddingTop: Node, - +panelOpacity: Node, - +combinedSetMode: LoggedOutMode => void, - +goBackToPrompt: () => void, - +activeAlertRef: { current: boolean }, - +setActiveAlert: boolean => void, - +resetToPrompt: () => boolean, - // Redux state - +dimensions: DerivedDimensionsInfo, - +splashStyle: ImageStyle, - +styles: $ReadOnly, -}; -class LoggedOutModal extends React.PureComponent { - render(): React.Node { - const { styles } = this.props; - - const siweButton = ( - <> - - - - - - Sign in with Ethereum - - - - - or - - - - ); - - let panel = null; - let buttons = null; - if (this.props.mode.curMode === 'log-in') { - panel = ( - - ); - } else if (this.props.mode.curMode === 'register') { - panel = ( - - ); - } else if (this.props.mode.curMode === 'prompt') { - const opacityStyle = { opacity: this.props.buttonOpacity }; - - const registerButtons = []; - registerButtons.push( - - - Register - - , - ); - if (enableNewRegistrationMode) { - registerButtons.push( - - - Register (new) - - , - ); - } - - const signInButtons = []; - signInButtons.push( - - - Sign in - - , - ); - if (__DEV__) { - signInButtons.push( - - - Sign in (QR) - - , - ); - } - - buttons = ( - - - {siweButton} - {signInButtons} - {registerButtons} - - ); - } else if (this.props.mode.curMode === 'loading') { - panel = ( - - ); - } - - const windowWidth = this.props.dimensions.width; - const buttonStyle = { - opacity: this.props.panelOpacity, - left: windowWidth < 360 ? 28 : 40, - }; - const padding = { paddingTop: this.props.panelPaddingTop }; - - const animatedContent = ( - - - Comm - - - - - - - {panel} - - ); - - let siwePanel; - if (this.props.mode.curMode === 'siwe') { - siwePanel = ( - - ); - } - - const backgroundSource = { uri: splashBackgroundURI }; - return ( - - - - - - {animatedContent} - {buttons} - - - {siwePanel} - - ); - } - - onPressSIWE = () => { - this.props.combinedSetMode('siwe'); - }; - - onPressLogIn = () => { - if (Platform.OS !== 'ios') { - // For some strange reason, iOS's password management logic doesn't - // realize that the username and password fields in LogInPanel are related - // if the username field gets focused on mount. To avoid this issue we - // need the username and password fields to both appear on-screen before - // we focus the username field. However, when we set keyboardHeightValue - // to -1 here, we are telling our Reanimated logic to wait until the - // keyboard appears before showing LogInPanel. Since we need LogInPanel - // to appear before the username field is focused, we need to avoid this - // behavior on iOS. - this.props.keyboardHeightValue.setValue(-1); - } - this.props.combinedSetMode('log-in'); - }; - - onPressQRCodeSignIn = () => { - this.props.navigation.navigate(QRCodeSignInNavigatorRouteName); - }; - - onPressRegister = () => { - this.props.keyboardHeightValue.setValue(-1); - this.props.combinedSetMode('register'); - }; - - onPressNewRegister = () => { - this.props.navigation.navigate(RegistrationRouteName); - }; -} - const isForegroundSelector = createIsForegroundSelector( LoggedOutModalRouteName, ); @@ -470,8 +237,8 @@ +nextMode: LoggedOutMode, }; -const ConnectedLoggedOutModal: React.ComponentType = - React.memo(function ConnectedLoggedOutModal(props: BaseProps) { +const ConnectedLoggedOutModal: React.ComponentType = React.memo( + function ConnectedLoggedOutModal(props: Props) { const mountedRef = React.useRef(false); React.useEffect(() => { mountedRef.current = true; @@ -804,27 +571,207 @@ const splashStyle = useSelector(splashStyleSelector); const styles = useStyles(unboundStyles); + + const onPressSIWE = React.useCallback(() => { + combinedSetMode('siwe'); + }, [combinedSetMode]); + + const onPressLogIn = React.useCallback(() => { + if (Platform.OS !== 'ios') { + // For some strange reason, iOS's password management logic doesn't + // realize that the username and password fields in LogInPanel are + // related if the username field gets focused on mount. To avoid this + // issue we need the username and password fields to both appear + // on-screen before we focus the username field. However, when we set + // keyboardHeightValue to -1 here, we are telling our Reanimated logic + // to wait until the keyboard appears before showing LogInPanel. Since + // we need LogInPanel to appear before the username field is focused, we + //need to avoid this behavior on iOS. + keyboardHeightValue.setValue(-1); + } + combinedSetMode('log-in'); + }, [keyboardHeightValue, combinedSetMode]); + + const { navigate } = props.navigation; + const onPressQRCodeSignIn = React.useCallback(() => { + navigate(QRCodeSignInNavigatorRouteName); + }, [navigate]); + + const onPressRegister = React.useCallback(() => { + keyboardHeightValue.setValue(-1); + combinedSetMode('register'); + }, [keyboardHeightValue, combinedSetMode]); + + const onPressNewRegister = React.useCallback(() => { + navigate(RegistrationRouteName); + }, [navigate]); + + const siweButton = ( + <> + + + + + + Sign in with Ethereum + + + + + or + + + + ); + + let panel = null; + let buttons = null; + if (mode.curMode === 'log-in') { + panel = ( + + ); + } else if (mode.curMode === 'register') { + panel = ( + + ); + } else if (mode.curMode === 'prompt') { + const opacityStyle = { opacity: buttonOpacity }; + + const registerButtons = []; + registerButtons.push( + + + Register + + , + ); + if (enableNewRegistrationMode) { + registerButtons.push( + + + Register (new) + + , + ); + } + + const signInButtons = []; + signInButtons.push( + + + Sign in + + , + ); + if (__DEV__) { + signInButtons.push( + + + Sign in (QR) + + , + ); + } + + buttons = ( + + + {siweButton} + {signInButtons} + {registerButtons} + + ); + } else if (mode.curMode === 'loading') { + panel = ( + + ); + } + + const windowWidth = dimensions.width; + const buttonStyle = { + opacity: panelOpacity, + left: windowWidth < 360 ? 28 : 40, + }; + const padding = { paddingTop: panelPaddingTop }; + + const animatedContent = ( + + + Comm + + + + + + + {panel} + + ); + + let siwePanel; + if (mode.curMode === 'siwe') { + siwePanel = ( + + ); + } + + const backgroundSource = { uri: splashBackgroundURI }; return ( - + + + + + + {animatedContent} + {buttons} + + + {siwePanel} + ); - }); + }, +); export default ConnectedLoggedOutModal;