Establishing Communication Between Mobile Wallets and Apps
When integrating a wallet with a mobile application, it’s essential to understand how they communicate. The process involves two main steps:
QR Code Handshake: The mobile app (Dapp) generates a unique URI (Uniform Resource Identifier) and displays it as a QR code. This URI acts like a secret handshake. When the user scans the QR code using their wallet app, they establish a connection. It’s like saying, “Hey, let’s chat!”
Deep Links and Universal Links: The URI from the QR code allows the wallet app to create a deep link or universal link. These links work on both Android and iOS. They enable seamless communication between the wallet and the app.
Developers should prefer Deep Linking over Universal Linking.Universal Linking may redirect the user to a browser, which might not provide the intended user experience. Deep Linking ensures the user is taken directly to the app.
In some scenarios, wallets use redirect metadata provided in session proposals to open applications. This can cause unintended behavior, such as:Redirecting to the wrong app when multiple apps share the same redirect metadata (e.g., a desktop and mobile version of the same Dapp).
Opening an unrelated application if a QR code is scanned on a different device than where the wallet is installed.
Restrict Redirect Metadata to Deep Link Use Cases: Redirect metadata should only be used when the session proposal is initiated through a deep link. QR code scans should not trigger app redirects using session proposal metadata.
The connection and sign request flows are similar across platforms.
Dapps developers must do the same for their own custom schemes if they want the wallet to be able to navigate back after a session approval or a sign request response
In order to redirect to the Dapp, you’ll need to use Linking from react-native and call openURL() method with the Dapp scheme that comes in the proposal metadata.
Copy
import { Linking } from "react-native";async function onApprove(proposal, namespaces) { const session = await walletKit.approveSession({ id: proposal.id, namespaces, }); const dappScheme = session.peer.metadata.redirect?.native; if (dappScheme) { Linking.openURL(dappScheme); } else { // Inform the user to manually return to the DApp }}