Skip to content

Commit

Permalink
fix missing dapp metadata for eth actions (#6086)
Browse files Browse the repository at this point in the history
* fix missing dapp metadata for eth actions

* use isHandshakeAction helper function

* Update src/components/MobileWalletProtocolListener.tsx

Co-authored-by: Bruno Barbieri <[email protected]>

---------

Co-authored-by: Bruno Barbieri <[email protected]>
  • Loading branch information
walmat and brunobar79 authored Sep 9, 2024
1 parent 0759e1d commit 8b1f712
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
50 changes: 39 additions & 11 deletions src/components/MobileWalletProtocolListener.tsx
Original file line number Diff line number Diff line change
@@ -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<string | null>(null);
const pendingMessageRef = useRef<typeof message | null>(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) {
Expand Down
2 changes: 0 additions & 2 deletions src/screens/SignTransactionSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ export const SignTransactionSheet = () => {
source,
} = routeParams;

console.log({ specifiedAddress });

const addressToUse = specifiedAddress ?? accountAddress;

const { provider, nativeAsset } = useProviderSetup(chainId, addressToUse);
Expand Down

0 comments on commit 8b1f712

Please sign in to comment.