diff --git a/native/account/siwe-panel.react.js b/native/account/siwe-panel.react.js index 1e3fb2aac..44ee09d54 100644 --- a/native/account/siwe-panel.react.js +++ b/native/account/siwe-panel.react.js @@ -1,103 +1,103 @@ // @flow import * as React from 'react'; import Animated from 'react-native-reanimated'; import WebView from 'react-native-webview'; import { registerActionTypes, register } from 'lib/actions/user-actions'; import type { RegisterInfo, LogInExtraInfo, RegisterResult, LogInStartingPayload, } from 'lib/types/account-types'; import { useServerCall, useDispatchActionPromise, type DispatchActionPromise, } from 'lib/utils/action-utils'; import { NavContext } from '../navigation/navigation-context'; import { useSelector } from '../redux/redux-utils'; import { nativeLogInExtraInfoSelector } from '../selectors/account-selectors'; +import { defaultLandingURLPrefix } from '../utils/url-utils'; import { setNativeCredentials } from './native-credentials'; -const commSIWE = __DEV__ - ? 'http://localhost/commlanding/siwe' - : 'https://comm.app/siwe'; + +const commSIWE = `${defaultLandingURLPrefix}/siwe`; type BaseProps = { +setActiveAlert: (activeAlert: boolean) => void, +opacityValue: Animated.Node, }; type Props = { ...BaseProps, // Redux state +logInExtraInfo: () => LogInExtraInfo, // Redux dispatch functions +dispatchActionPromise: DispatchActionPromise, // async functions that hit server APIs +registerAction: (registerInfo: RegisterInfo) => Promise, }; function SIWEPanel({ logInExtraInfo, dispatchActionPromise, registerAction, }: Props) { const handleSIWE = React.useCallback( ({ address, signature }) => { // this is all mocked from register-panel const extraInfo = logInExtraInfo(); dispatchActionPromise( registerActionTypes, registerAction({ username: address, password: signature, ...extraInfo, }), undefined, ({ calendarQuery: extraInfo.calendarQuery }: LogInStartingPayload), ); setNativeCredentials({ username: address, password: signature }); }, [logInExtraInfo, dispatchActionPromise, registerAction], ); const handleMessage = React.useCallback( event => { const { nativeEvent: { data }, } = event; const { address, signature } = JSON.parse(data); if (address && signature) { handleSIWE({ address, signature }); } }, [handleSIWE], ); const source = React.useMemo(() => ({ uri: commSIWE }), []); return ; } const ConnectedSIWEPanel: React.ComponentType = React.memo( function ConnectedRegisterPanel(props: BaseProps) { const navContext = React.useContext(NavContext); const logInExtraInfo = useSelector(state => nativeLogInExtraInfoSelector({ redux: state, navContext, }), ); const dispatchActionPromise = useDispatchActionPromise(); const callRegister = useServerCall(register); return ( ); }, ); export default ConnectedSIWEPanel; diff --git a/native/utils/url-utils.js b/native/utils/url-utils.js index 5f3a1255f..862f51b0e 100644 --- a/native/utils/url-utils.js +++ b/native/utils/url-utils.js @@ -1,61 +1,77 @@ // @flow import invariant from 'invariant'; import { Platform } from 'react-native'; import DeviceInfo from 'react-native-device-info'; import { natDevHostname, checkForMissingNatDevHostname } from './dev-hostname'; const localhostHostname = 'localhost'; const localhostHostnameFromAndroidEmulator = '10.0.2.2'; const productionNodeServerURL = 'https://squadcal.org'; +const productionLandingURL = 'https://comm.app'; const devIsEmulator: boolean = __DEV__ && DeviceInfo.isEmulatorSync(); function getDevServerHostname(): string { invariant(__DEV__, 'getDevServerHostname called from production'); if (!devIsEmulator) { checkForMissingNatDevHostname(); return natDevHostname; } else if (Platform.OS === 'android') { return localhostHostnameFromAndroidEmulator; } else if (Platform.OS === 'ios') { return localhostHostname; } invariant(false, `unsupported platform: ${Platform.OS}`); } function getDevNodeServerURLFromHostname(hostname: string): string { return `http://${hostname}/comm`; } +function getDevLandingURLFromHostname(hostname: string): string { + return `http://${hostname}/commlanding`; +} + function getDevNodeServerURL(): string { invariant(__DEV__, 'getDevNodeServerURL called from production'); const hostname = getDevServerHostname(); return getDevNodeServerURLFromHostname(hostname); } +function getDevLandingURL(): string { + invariant(__DEV__, 'getDevLandingURL called from production'); + const hostname = getDevServerHostname(); + return getDevLandingURLFromHostname(hostname); +} + const nodeServerOptions = [productionNodeServerURL]; if (Platform.OS === 'android') { nodeServerOptions.push( getDevNodeServerURLFromHostname(localhostHostnameFromAndroidEmulator), ); } else { nodeServerOptions.push(getDevNodeServerURLFromHostname(localhostHostname)); } const defaultURLPrefix: string = __DEV__ ? getDevNodeServerURL() : productionNodeServerURL; +const defaultLandingURLPrefix: string = __DEV__ + ? getDevLandingURL() + : productionLandingURL; + const natNodeServer: string = getDevNodeServerURLFromHostname(natDevHostname); const setCustomServer = 'SET_CUSTOM_SERVER'; export { defaultURLPrefix, + defaultLandingURLPrefix, getDevServerHostname, nodeServerOptions, natNodeServer, setCustomServer, };