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 @@ -27,26 +27,24 @@ [], ); - const { goBackToPrompt } = props; - const siweServerCallParams = React.useMemo(() => { - const onServerCallFailure = () => { - Alert.alert( - 'Unknown error', - 'Uhh... try again?', - [{ text: 'OK', onPress: goBackToPrompt }], - { cancelable: false }, - ); - }; - return { onFailure: onServerCallFailure }; - }, [goBackToPrompt]); - const siweServerCall = useSIWEServerCall(siweServerCallParams); - + const siweServerCall = useSIWEServerCall(); const successRef = React.useRef(false); const dispatch = useDispatch(); + const { goBackToPrompt } = props; const onSuccess = React.useCallback( async (result: SIWEResult) => { successRef.current = true; - await siweServerCall({ ...result, doNotRegister: true }); + try { + await siweServerCall({ ...result, doNotRegister: true }); + } catch (e) { + Alert.alert( + 'Unknown error', + 'Uhh... try again?', + [{ text: 'OK', onPress: goBackToPrompt }], + { cancelable: false }, + ); + throw e; + } dispatch({ type: setDataLoadedActionType, payload: { @@ -54,7 +52,7 @@ }, }); }, - [siweServerCall, dispatch], + [siweServerCall, dispatch, goBackToPrompt], ); const ifBeforeSuccessGoBackToPrompt = React.useCallback(() => { diff --git a/native/account/registration/existing-ethereum-account.react.js b/native/account/registration/existing-ethereum-account.react.js --- a/native/account/registration/existing-ethereum-account.react.js +++ b/native/account/registration/existing-ethereum-account.react.js @@ -31,20 +31,19 @@ +route: NavigationRoute<'ExistingEthereumAccount'>, }; function ExistingEthereumAccount(props: Props): React.Node { - const siweServerCallParams = React.useMemo(() => { - const onServerCallFailure = () => { - Alert.alert('Unknown error', 'Uhh... try again?', [{ text: 'OK' }], { - cancelable: false, - }); - }; - return { onFailure: onServerCallFailure }; - }, []); - const siweServerCall = useSIWEServerCall(siweServerCallParams); + const siweServerCall = useSIWEServerCall(); const { params } = props.route; const dispatch = useDispatch(); const onProceedToLogIn = React.useCallback(async () => { - await siweServerCall({ ...params, doNotRegister: true }); + try { + await siweServerCall({ ...params, doNotRegister: true }); + } catch (e) { + Alert.alert('Unknown error', 'Uhh... try again?', [{ text: 'OK' }], { + cancelable: false, + }); + throw e; + } dispatch({ type: setDataLoadedActionType, payload: { diff --git a/native/account/registration/registration-server-call.js b/native/account/registration/registration-server-call.js --- a/native/account/registration/registration-server-call.js +++ b/native/account/registration/registration-server-call.js @@ -124,14 +124,7 @@ [logInExtraInfo, callRegister, dispatchActionPromise], ); - const siweServerCallParams = React.useMemo(() => { - const onServerCallFailure = () => { - Alert.alert('Unknown error', 'Uhh... try again?'); - }; - return { onFailure: onServerCallFailure }; - }, []); - const siweServerCall = useSIWEServerCall(siweServerCallParams); - + const siweServerCall = useSIWEServerCall(); const dispatch = useDispatch(); const returnedFunc = React.useCallback( (input: RegistrationServerCallInput) => @@ -146,9 +139,14 @@ if (accountSelection.accountType === 'username') { await registerUsernameAccount(accountSelection, keyserverURL); } else { - await siweServerCall(accountSelection, { - urlPrefixOverride: keyserverURL, - }); + try { + await siweServerCall(accountSelection, { + urlPrefixOverride: keyserverURL, + }); + } catch (e) { + Alert.alert('Unknown error', 'Uhh... try again?'); + throw e; + } } dispatch({ type: setURLPrefix, diff --git a/native/account/siwe-hooks.js b/native/account/siwe-hooks.js --- a/native/account/siwe-hooks.js +++ b/native/account/siwe-hooks.js @@ -25,38 +25,28 @@ +doNotRegister?: boolean, ... }; -type UseSIWEServerCallParams = { - +onFailure: () => mixed, -}; -function useSIWEServerCall( - params: UseSIWEServerCallParams, -): (SIWEServerCallParams, ?CallServerEndpointOptions) => Promise { - const { onFailure } = params; - +function useSIWEServerCall(): ( + SIWEServerCallParams, + ?CallServerEndpointOptions, +) => Promise { const siweAuthCall = useServerCall(siweAuth); const callSIWE = React.useCallback( - async ( + ( message: string, signature: string, extraInfo: $ReadOnly<{ ...LogInExtraInfo, +doNotRegister?: boolean }>, callServerEndpointOptions: ?CallServerEndpointOptions, - ) => { - try { - return await siweAuthCall( - { - message, - signature, - ...extraInfo, - }, - callServerEndpointOptions, - ); - } catch (e) { - onFailure(); - throw e; - } - }, - [onFailure, siweAuthCall], + ) => + siweAuthCall( + { + message, + signature, + ...extraInfo, + }, + callServerEndpointOptions, + ), + [siweAuthCall], ); const navContext = React.useContext(NavContext);