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 @@ -3,6 +3,8 @@ import * as React from 'react'; import { Alert, ActivityIndicator, View } from 'react-native'; +import type { SIWEResult } from 'lib/types/siwe-types.js'; + import { useSIWEServerCall } from './siwe-hooks.js'; import SIWEPanel from './siwe-panel.react.js'; @@ -22,20 +24,35 @@ [], ); - const { onClose } = props; + const onCloseProp = props.onClose; const siweServerCallParams = React.useMemo(() => { const onServerCallFailure = () => { Alert.alert( 'Unknown error', 'Uhh... try again?', - [{ text: 'OK', onPress: onClose }], + [{ text: 'OK', onPress: onCloseProp }], { cancelable: false }, ); }; return { onFailure: onServerCallFailure }; - }, [onClose]); + }, [onCloseProp]); const siweServerCall = useSIWEServerCall(siweServerCallParams); + const successRef = React.useRef(false); + const onSuccess = React.useCallback( + (result: SIWEResult) => { + successRef.current = true; + return siweServerCall(result); + }, + [siweServerCall], + ); + + const onClose = React.useCallback(() => { + if (!successRef.current) { + onCloseProp(); + } + }, [onCloseProp]); + const { closing } = props; return ( <> @@ -44,7 +61,7 @@ closing={closing} onClosed={onClose} onClosing={onClose} - onSuccessfulWalletSignature={siweServerCall} + onSuccessfulWalletSignature={onSuccess} setLoading={setLoading} /> diff --git a/native/account/siwe-panel.react.js b/native/account/siwe-panel.react.js --- a/native/account/siwe-panel.react.js +++ b/native/account/siwe-panel.react.js @@ -107,14 +107,12 @@ const closeBottomSheet = bottomSheetRef.current?.close; const { closing, onSuccessfulWalletSignature } = props; - const disableOnClose = React.useRef(false); const handleMessage = React.useCallback( async event => { const data: SIWEWebViewMessage = JSON.parse(event.nativeEvent.data); if (data.type === 'siwe_success') { const { address, message, signature } = data; if (address && signature) { - disableOnClose.current = true; closeBottomSheet?.(); await onSuccessfulWalletSignature({ address, message, signature }); } @@ -167,10 +165,6 @@ const { onClosed } = props; const onBottomSheetChange = React.useCallback( (index: number) => { - if (disableOnClose.current) { - disableOnClose.current = false; - return; - } if (index === -1) { onClosed(); }