diff --git a/native/account/registration/existing-ethereum-account.react.js b/native/account/registration/existing-ethereum-account.react.js index 2050b52d8..707af41af 100644 --- a/native/account/registration/existing-ethereum-account.react.js +++ b/native/account/registration/existing-ethereum-account.react.js @@ -1,145 +1,166 @@ // @flow import * as React from 'react'; import { Text, View } from 'react-native'; import { setDataLoadedActionType } from 'lib/actions/client-db-store-actions.js'; import { siweAuthActionTypes } from 'lib/actions/siwe-actions.js'; import { useENSName } from 'lib/hooks/ens-cache.js'; import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js'; import type { SIWEResult } from 'lib/types/siwe-types.js'; import { useDispatch } from 'lib/utils/redux-utils.js'; +import { usingCommServicesAccessToken } from 'lib/utils/services-utils.js'; import RegistrationButtonContainer from './registration-button-container.react.js'; import RegistrationButton from './registration-button.react.js'; import RegistrationContainer from './registration-container.react.js'; import RegistrationContentContainer from './registration-content-container.react.js'; import type { RegistrationNavigationProp } from './registration-navigator.react.js'; import type { NavigationRoute } from '../../navigation/route-names.js'; import { useSelector } from '../../redux/redux-utils.js'; import { useStyles } from '../../themes/colors.js'; import { UnknownErrorAlertDetails } from '../../utils/alert-messages.js'; import Alert from '../../utils/alert.js'; -import { useLegacySIWEServerCall } from '../siwe-hooks.js'; +import { + useIdentityWalletLogInCall, + useLegacySIWEServerCall, +} from '../siwe-hooks.js'; const siweAuthLoadingStatusSelector = createLoadingStatusSelector(siweAuthActionTypes); export type ExistingEthereumAccountParams = SIWEResult; type Props = { +navigation: RegistrationNavigationProp<'ExistingEthereumAccount'>, +route: NavigationRoute<'ExistingEthereumAccount'>, }; function ExistingEthereumAccount(props: Props): React.Node { const legacySiweServerCall = useLegacySIWEServerCall(); + const identityWalletLogInCall = useIdentityWalletLogInCall(); const { params } = props.route; const dispatch = useDispatch(); const onProceedToLogIn = React.useCallback(async () => { - try { - await legacySiweServerCall({ ...params, doNotRegister: true }); - } catch (e) { - Alert.alert( - UnknownErrorAlertDetails.title, - UnknownErrorAlertDetails.message, - [{ text: 'OK' }], - { - cancelable: false, + if (usingCommServicesAccessToken) { + try { + await identityWalletLogInCall(params); + } catch (e) { + Alert.alert( + UnknownErrorAlertDetails.title, + UnknownErrorAlertDetails.message, + [{ text: 'OK' }], + { + cancelable: false, + }, + ); + throw e; + } + } else { + try { + await legacySiweServerCall({ ...params, doNotRegister: true }); + } catch (e) { + Alert.alert( + UnknownErrorAlertDetails.title, + UnknownErrorAlertDetails.message, + [{ text: 'OK' }], + { + cancelable: false, + }, + ); + throw e; + } + dispatch({ + type: setDataLoadedActionType, + payload: { + dataLoaded: true, }, - ); - throw e; + }); } - dispatch({ - type: setDataLoadedActionType, - payload: { - dataLoaded: true, - }, - }); - }, [legacySiweServerCall, params, dispatch]); + }, [legacySiweServerCall, identityWalletLogInCall, params, dispatch]); const siweAuthCallLoading = useSelector( state => siweAuthLoadingStatusSelector(state) === 'loading', ); const { address } = params; const walletIdentifier = useENSName(address); const walletIdentifierTitle = walletIdentifier === address ? 'Ethereum wallet' : 'ENS name'; const { goBack } = props.navigation; const styles = useStyles(unboundStyles); return ( Account already exists for wallet You can proceed to log in with this wallet, or go back and use a different wallet. {walletIdentifierTitle} {walletIdentifier} ); } const unboundStyles = { header: { fontSize: 24, color: 'panelForegroundLabel', paddingBottom: 16, }, body: { fontFamily: 'Arial', fontSize: 15, lineHeight: 20, color: 'panelForegroundSecondaryLabel', paddingBottom: 40, }, walletTile: { backgroundColor: 'panelForeground', borderRadius: 8, padding: 24, alignItems: 'center', }, walletIdentifierTitleText: { fontSize: 17, color: 'panelForegroundLabel', textAlign: 'center', }, walletIdentifier: { backgroundColor: 'panelSecondaryForeground', paddingVertical: 8, paddingHorizontal: 24, borderRadius: 56, marginTop: 8, alignItems: 'center', }, walletIdentifierText: { fontSize: 15, color: 'panelForegroundLabel', }, }; export default ExistingEthereumAccount;