From 3873b7b8f355d783c5270804d1b4470fa6b8f0e4 Mon Sep 17 00:00:00 2001 From: Matthew Wall Date: Mon, 9 Sep 2024 14:55:15 -0400 Subject: [PATCH] fix missing dapp metadata for eth actions (#6086) * fix missing dapp metadata for eth actions * use isHandshakeAction helper function * Update src/components/MobileWalletProtocolListener.tsx Co-authored-by: Bruno Barbieri <1247834+brunobar79@users.noreply.github.com> --------- Co-authored-by: Bruno Barbieri <1247834+brunobar79@users.noreply.github.com> --- .../MobileWalletProtocolListener.tsx | 50 +++++++++++++++---- src/screens/SignTransactionSheet.tsx | 2 - 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/components/MobileWalletProtocolListener.tsx b/src/components/MobileWalletProtocolListener.tsx index 1c5dd960d4e..6db813b3b8f 100644 --- a/src/components/MobileWalletProtocolListener.tsx +++ b/src/components/MobileWalletProtocolListener.tsx @@ -1,25 +1,53 @@ 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'; 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) { + + lastMessageUuidRef.current = message.uuid; + + // Check if it's a handshake request + const isHandshake = message.actions.some(isHandshakeAction); + + 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);