diff --git a/landing/siwe.react.js b/landing/siwe.react.js --- a/landing/siwe.react.js +++ b/landing/siwe.react.js @@ -5,6 +5,7 @@ getDefaultWallets, RainbowKitProvider, darkTheme, + useModalState, } from '@rainbow-me/rainbowkit'; import invariant from 'invariant'; import _merge from 'lodash/fp/merge'; @@ -97,6 +98,16 @@ } }, [hasNonce, openConnectModal]); + const prevConnectModalOpen = React.useRef(false); + const modalState = useModalState(); + const { connectModalOpen } = modalState; + React.useEffect(() => { + if (!connectModalOpen && prevConnectModalOpen.current) { + postMessageToNativeWebView({ type: 'siwe_closed' }); + } + prevConnectModalOpen.current = connectModalOpen; + }, [connectModalOpen]); + if (!hasNonce) { return (
diff --git a/lib/types/siwe-types.js b/lib/types/siwe-types.js --- a/lib/types/siwe-types.js +++ b/lib/types/siwe-types.js @@ -7,9 +7,13 @@ // This is a message that the rendered webpage (landing/siwe.react.js) uses to // communicate back to the React Native WebView that is rendering it // (native/account/siwe-panel.react.js) -export type SIWEWebViewMessage = { - +type: 'siwe_success', - +address: string, - +message: string, - +signature: string, -}; +export type SIWEWebViewMessage = + | { + +type: 'siwe_success', + +address: string, + +message: string, + +signature: string, + } + | { + +type: 'siwe_closed', + }; 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 @@ -82,6 +82,9 @@ }, [logInExtraInfo, dispatchActionPromise, registerAction], ); + const bottomSheetRef = React.useRef(); + const closeBottomSheet = bottomSheetRef.current?.close; + const { onClose } = props; const handleMessage = React.useCallback( event => { const data: SIWEWebViewMessage = JSON.parse(event.nativeEvent.data); @@ -90,9 +93,12 @@ if (address && signature) { handleSIWE({ address, signature }); } + } else if (data.type === 'siwe_closed') { + onClose(); + closeBottomSheet?.(); } }, - [handleSIWE], + [handleSIWE, onClose, closeBottomSheet], ); const source = React.useMemo( @@ -133,7 +139,6 @@ [], ); - const { onClose } = props; const onBottomSheetChange = React.useCallback( (index: number) => { if (index === -1) { @@ -152,6 +157,7 @@ handleIndicatorStyle={bottomSheetHandleIndicatorStyle} enablePanDownToClose={true} onChange={onBottomSheetChange} + ref={bottomSheetRef} >