diff --git a/landing/siwe.react.js b/landing/siwe.react.js --- a/landing/siwe.react.js +++ b/landing/siwe.react.js @@ -108,6 +108,41 @@ prevConnectModalOpen.current = connectModalOpen; }, [connectModalOpen]); + const newModalAppeared = React.useCallback(mutationList => { + for (const mutation of mutationList) { + for (const addedNode of mutation.addedNodes) { + if ( + addedNode instanceof HTMLElement && + addedNode.id === 'walletconnect-wrapper' + ) { + postMessageToNativeWebView({ + type: 'walletconnect_modal_update', + state: 'open', + }); + } + } + for (const addedNode of mutation.removedNodes) { + if ( + addedNode instanceof HTMLElement && + addedNode.id === 'walletconnect-wrapper' + ) { + postMessageToNativeWebView({ + type: 'walletconnect_modal_update', + state: 'closed', + }); + } + } + } + }, []); + React.useEffect(() => { + const observer = new MutationObserver(newModalAppeared); + invariant(document.body, 'document.body should be set'); + observer.observe(document.body, { childList: true }); + return () => { + observer.disconnect(); + }; + }, [newModalAppeared]); + 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 @@ -16,4 +16,8 @@ } | { +type: 'siwe_closed', + } + | { + +type: 'walletconnect_modal_update', + +state: 'open' | '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 @@ -64,6 +64,20 @@ })(); }, [dispatchActionPromise, getSIWENonceCall]); + const [isLoading, setLoading] = React.useState(true); + const [isWalletConnectModalOpen, setWalletConnectModalOpen] = React.useState( + false, + ); + const snapPoints = React.useMemo(() => { + if (isLoading) { + return [1]; + } else if (isWalletConnectModalOpen) { + return [700]; + } else { + return [450]; + } + }, [isLoading, isWalletConnectModalOpen]); + const handleSIWE = React.useCallback( ({ address, signature }) => { // this is all mocked from register-panel @@ -96,6 +110,9 @@ } else if (data.type === 'siwe_closed') { onClose(); closeBottomSheet?.(); + } else if (data.type === 'walletconnect_modal_update') { + console.log(`received ${JSON.stringify(data)}`); + setWalletConnectModalOpen(data.state === 'open'); } }, [handleSIWE, onClose, closeBottomSheet], @@ -111,16 +128,6 @@ [nonce], ); - const [isLoading, setLoading] = React.useState(true); - - const snapPoints = React.useMemo(() => { - if (isLoading) { - return [1]; - } else { - return [700]; - } - }, [isLoading]); - const onWebViewLoaded = React.useCallback(() => { setLoading(false); }, []);