Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix missing dapp metadata for eth actions #6086

Merged
merged 4 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
console.log('message', message);
walmat marked this conversation as resolved.
Show resolved Hide resolved
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
Loading