diff --git a/native/account/fullscreen-siwe-panel.react.js b/native/account/fullscreen-siwe-panel.react.js --- a/native/account/fullscreen-siwe-panel.react.js +++ b/native/account/fullscreen-siwe-panel.react.js @@ -1,6 +1,7 @@ // @flow import { useNavigation } from '@react-navigation/native'; +import invariant from 'invariant'; import * as React from 'react'; import { ActivityIndicator, View } from 'react-native'; @@ -10,6 +11,7 @@ import { useDispatch } from 'lib/utils/redux-utils.js'; import { useGetEthereumAccountFromSIWEResult } from './registration/ethereum-utils.js'; +import { RegistrationContext } from './registration/registration-context.js'; import { useSIWEServerCall } from './siwe-hooks.js'; import SIWEPanel from './siwe-panel.react.js'; import { @@ -34,6 +36,10 @@ [], ); + const registrationContext = React.useContext(RegistrationContext); + invariant(registrationContext, 'registrationContext should be set'); + const { setSkipEthereumLoginOnce } = registrationContext; + const getEthereumAccountFromSIWEResult = useGetEthereumAccountFromSIWEResult(); const { navigate } = useNavigation(); @@ -41,12 +47,18 @@ const onAccountDoesNotExist = React.useCallback( async (result: SIWEResult) => { await getEthereumAccountFromSIWEResult(result); + setSkipEthereumLoginOnce(true); goBackToPrompt(); navigate<'Registration'>(RegistrationRouteName, { screen: AccountDoesNotExistRouteName, }); }, - [getEthereumAccountFromSIWEResult, navigate, goBackToPrompt], + [ + getEthereumAccountFromSIWEResult, + navigate, + goBackToPrompt, + setSkipEthereumLoginOnce, + ], ); const siweServerCall = useSIWEServerCall(); diff --git a/native/account/registration/keyserver-selection.react.js b/native/account/registration/keyserver-selection.react.js --- a/native/account/registration/keyserver-selection.react.js +++ b/native/account/registration/keyserver-selection.react.js @@ -24,6 +24,7 @@ import { type NavigationRoute, ConnectEthereumRouteName, + AvatarSelectionRouteName, } from '../../navigation/route-names.js'; import { useSelector } from '../../redux/redux-utils.js'; import { useStyles, useColors } from '../../themes/colors.js'; @@ -50,7 +51,12 @@ function KeyserverSelection(props: Props): React.Node { const registrationContext = React.useContext(RegistrationContext); invariant(registrationContext, 'registrationContext should be set'); - const { cachedSelections, setCachedSelections } = registrationContext; + const { + cachedSelections, + setCachedSelections, + skipEthereumLoginOnce, + setSkipEthereumLoginOnce, + } = registrationContext; const initialKeyserverURL = cachedSelections.keyserverURL; const [customKeyserver, setCustomKeyserver] = React.useState( @@ -111,6 +117,7 @@ const { navigate } = props.navigation; const { coolOrNerdMode } = props.route.params.userSelections; + const { ethereumAccount } = cachedSelections; const onSubmit = React.useCallback(async () => { setError(undefined); @@ -125,9 +132,24 @@ ...oldUserSelections, keyserverURL, })); - navigate<'ConnectEthereum'>({ - name: ConnectEthereumRouteName, - params: { userSelections: { coolOrNerdMode, keyserverURL } }, + + const userSelections = { coolOrNerdMode, keyserverURL }; + if (!skipEthereumLoginOnce || !ethereumAccount) { + navigate<'ConnectEthereum'>({ + name: ConnectEthereumRouteName, + params: { userSelections }, + }); + return; + } + + const userSelectionsWithAccount = { + ...userSelections, + accountSelection: ethereumAccount, + }; + setSkipEthereumLoginOnce(false); + navigate<'AvatarSelection'>({ + name: AvatarSelectionRouteName, + params: { userSelections: userSelectionsWithAccount }, }); }, [ keyserverURL, @@ -135,6 +157,9 @@ setCachedSelections, navigate, coolOrNerdMode, + skipEthereumLoginOnce, + ethereumAccount, + setSkipEthereumLoginOnce, ]); const styles = useStyles(unboundStyles); diff --git a/native/account/registration/registration-context-provider.react.js b/native/account/registration/registration-context-provider.react.js --- a/native/account/registration/registration-context-provider.react.js +++ b/native/account/registration/registration-context-provider.react.js @@ -15,14 +15,27 @@ const [cachedSelections, setCachedSelections] = React.useState(emptyObj); + const [skipEthereumLoginOnce, baseSetSkipEthereumLoginOnce] = + React.useState(); + const setSkipEthereumLoginOnce = React.useCallback((skip: boolean) => { + baseSetSkipEthereumLoginOnce(skip || undefined); + }, []); + const registrationServerCall = useRegistrationServerCall(); const contextValue = React.useMemo( () => ({ register: registrationServerCall, cachedSelections, setCachedSelections, + skipEthereumLoginOnce, + setSkipEthereumLoginOnce, }), - [registrationServerCall, cachedSelections], + [ + registrationServerCall, + cachedSelections, + skipEthereumLoginOnce, + setSkipEthereumLoginOnce, + ], ); return ( diff --git a/native/account/registration/registration-context.js b/native/account/registration/registration-context.js --- a/native/account/registration/registration-context.js +++ b/native/account/registration/registration-context.js @@ -13,6 +13,11 @@ +register: RegistrationServerCallInput => Promise, +cachedSelections: CachedUserSelections, +setCachedSelections: SetState, + // We set this when entering the registration flow from the ETH login flow so + // that the user doesn't have to perform ETH auth again. We unset it after + // skipping the login flow once, so that the user can back out and change it. + +skipEthereumLoginOnce?: ?true, + +setSkipEthereumLoginOnce: boolean => void, }; const RegistrationContext: React.Context =