From 5864ab3cabc3167cb2a57905c37b32eb95844122 Mon Sep 17 00:00:00 2001 From: Matthew Wall Date: Fri, 6 Sep 2024 11:01:52 -0400 Subject: [PATCH 1/3] fix missing dapp metadata for eth actions --- .../MobileWalletProtocolListener.tsx | 43 ++++++++++++++----- src/screens/SignTransactionSheet.tsx | 2 - 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/components/MobileWalletProtocolListener.tsx b/src/components/MobileWalletProtocolListener.tsx index 1c5dd960d4e..6416c908a1d 100644 --- a/src/components/MobileWalletProtocolListener.tsx +++ b/src/components/MobileWalletProtocolListener.tsx @@ -5,21 +5,44 @@ import { logger, RainbowError } from '@/logger'; import { IS_ANDROID, IS_DEV } from '@/env'; export const MobileWalletProtocolListener = () => { - const { message, handleRequestUrl, sendFailureToClient, ...mwpProps } = useMobileWalletProtocolHost(); + const { message, handleRequestUrl, sendFailureToClient, session, ...mwpProps } = useMobileWalletProtocolHost(); const lastMessageUuidRef = useRef(null); + const pendingMessageRef = useRef(null); useEffect(() => { - if (message && lastMessageUuidRef.current !== message.uuid) { - lastMessageUuidRef.current = message.uuid; - try { - handleMobileWalletProtocolRequest({ request: message, ...mwpProps }); - } catch (error) { - logger.error(new RainbowError('Error handling Mobile Wallet Protocol request'), { - error, - }); + const handleMessage = async () => { + if (message && lastMessageUuidRef.current !== message.uuid) { + console.log('message', message); + lastMessageUuidRef.current = message.uuid; + + // Check if it's a handshake request + const isHandshake = message.actions.some(action => action.kind === 'handshake'); + + if (isHandshake || session) { + try { + await handleMobileWalletProtocolRequest({ request: message, session, ...mwpProps }); + } catch (error) { + logger.error(new RainbowError('Error handling Mobile Wallet Protocol request'), { + error, + }); + } + } else { + // Store the message to process once we have a valid session + pendingMessageRef.current = message; + } } + }; + + handleMessage(); + }, [message, session, mwpProps]); + + useEffect(() => { + if (session && pendingMessageRef.current) { + const pendingMessage = pendingMessageRef.current; + pendingMessageRef.current = null; + handleMobileWalletProtocolRequest({ request: pendingMessage, session, ...mwpProps }); } - }, [message, mwpProps]); + }, [session, mwpProps]); useEffect(() => { if (IS_DEV) { diff --git a/src/screens/SignTransactionSheet.tsx b/src/screens/SignTransactionSheet.tsx index 11be9876981..7fd728f1b3a 100644 --- a/src/screens/SignTransactionSheet.tsx +++ b/src/screens/SignTransactionSheet.tsx @@ -104,8 +104,6 @@ export const SignTransactionSheet = () => { source, } = routeParams; - console.log({ specifiedAddress }); - const addressToUse = specifiedAddress ?? accountAddress; const { provider, nativeAsset } = useProviderSetup(chainId, addressToUse); From 07fbf1582762480df3517c83384140a8fc19a0a5 Mon Sep 17 00:00:00 2001 From: Matthew Wall Date: Fri, 6 Sep 2024 11:08:56 -0400 Subject: [PATCH 2/3] use isHandshakeAction helper function --- src/components/MobileWalletProtocolListener.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/MobileWalletProtocolListener.tsx b/src/components/MobileWalletProtocolListener.tsx index 6416c908a1d..e501b01da47 100644 --- a/src/components/MobileWalletProtocolListener.tsx +++ b/src/components/MobileWalletProtocolListener.tsx @@ -1,5 +1,10 @@ import { useEffect, useRef } from 'react'; -import { addDiagnosticLogListener, getAndroidIntentUrl, useMobileWalletProtocolHost } from '@coinbase/mobile-wallet-protocol-host'; +import { + addDiagnosticLogListener, + getAndroidIntentUrl, + isHandshakeAction, + useMobileWalletProtocolHost, +} from '@coinbase/mobile-wallet-protocol-host'; import { handleMobileWalletProtocolRequest } from '@/utils/requestNavigationHandlers'; import { logger, RainbowError } from '@/logger'; import { IS_ANDROID, IS_DEV } from '@/env'; @@ -16,7 +21,7 @@ export const MobileWalletProtocolListener = () => { lastMessageUuidRef.current = message.uuid; // Check if it's a handshake request - const isHandshake = message.actions.some(action => action.kind === 'handshake'); + const isHandshake = message.actions.some(isHandshakeAction); if (isHandshake || session) { try { From eb1e5a99646eb8d5bebd4e0048119e528803d0f3 Mon Sep 17 00:00:00 2001 From: Matthew Wall Date: Mon, 9 Sep 2024 14:54:56 -0400 Subject: [PATCH 3/3] Update src/components/MobileWalletProtocolListener.tsx Co-authored-by: Bruno Barbieri <1247834+brunobar79@users.noreply.github.com> --- src/components/MobileWalletProtocolListener.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MobileWalletProtocolListener.tsx b/src/components/MobileWalletProtocolListener.tsx index e501b01da47..6db813b3b8f 100644 --- a/src/components/MobileWalletProtocolListener.tsx +++ b/src/components/MobileWalletProtocolListener.tsx @@ -17,7 +17,7 @@ export const MobileWalletProtocolListener = () => { useEffect(() => { const handleMessage = async () => { if (message && lastMessageUuidRef.current !== message.uuid) { - console.log('message', message); + lastMessageUuidRef.current = message.uuid; // Check if it's a handshake request