Skip to content

Commit 973a5d0

Browse files
authored
Merge pull request #388 from reown-com/vraj/dr-430-enhance-documentation-for-walletkit-web-wallet-integrations
added info about handling web wallet
2 parents 36ef6aa + 1be285a commit 973a5d0

File tree

5 files changed

+112
-1
lines changed

5 files changed

+112
-1
lines changed

images/web-wallet-button.png

258 KB
Loading

images/web-wallet-demo.mp4

3.62 MB
Binary file not shown.

images/web-wallet-qr-demo.mp4

4.17 MB
Binary file not shown.

images/web-wallet-safe.png

232 KB
Loading

walletkit/web/usage.mdx

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,46 @@ title: Usage
44

55
import CloudBanner from "/snippets/cloud-banner.mdx";
66

7-
This section provides instructions on how to initialize the WalletKit client, approve sessions with supported namespaces, and respond to session requests, enabling easy integration of Web3 wallets with dapps through a simple and intuitive interface.
7+
## Overview
8+
9+
WalletConnect makes distributing your Web wallet (such as Safe, Abstract Global Wallet, and many more) much faster. By integrating the WalletKit SDK, your web wallet will be able to connect to any dApp that supports WalletConnect and will be available in the list of wallets on both WalletConnect, Reown AppKit, and others.
10+
11+
<Frame caption="Web Wallet in Reown AppKit & WalletButtons">
12+
<img height="400" width="300" src="/images/web-wallet-safe.png" alt="Web Wallet in Reown AppKit" />
13+
14+
<img height="600" width="300" src="/images/web-wallet-button.png" alt="Web Wallet in WalletConnect" />
15+
</Frame>
16+
Additionally, you don't need to build SDKs in native languages such as Swift, Kotlin, Flutter, Unity, or React Native. This means your wallet can be available not just for web dApps, but also for native dApps, all from a single codebase.
17+
18+
This section provides instructions on how to initialize the WalletKit client, approve sessions with supported namespaces, and respond to session requests, enabling easy integration of Web3 wallets with dApps through a simple and intuitive interface.
19+
20+
## User Experience
21+
22+
### Default Integration
23+
24+
This integration automatically opens a new web wallet tab when a user clicks "Connect" in a dApp. The wallet handles the WalletConnect URI automatically, meaning users don't need to manually copy and paste the URI. This provides a seamless, one-click connection experience.
25+
26+
<Frame caption="Abstract Global Wallet to Wolfswap">
27+
<video
28+
controls
29+
autoPlay
30+
className="w-full aspect-video"
31+
src="/images/web-wallet-demo.mp4"
32+
></video>
33+
</Frame>
34+
35+
### QR Code Integration
36+
37+
This integration only handles the session proposal and approval via the WalletConnect QR code. The user will need to manually copy and paste the WalletConnect URI into the wallet.
38+
39+
<Frame caption="Safe Wallet Connecting to AppKit Lab">
40+
<video
41+
controls
42+
autoPlay
43+
className="w-full aspect-video"
44+
src="/images/web-wallet-qr-demo.mp4"
45+
></video>
46+
</Frame>
847

948
## Cloud Configuration
1049

@@ -43,6 +82,78 @@ const walletKit = await WalletKit.init({
4382

4483
A session is a connection between a dapp and a wallet. It is established when a user approves a session proposal from a dapp. A session is active until the user disconnects from the dapp or the session expires.
4584

85+
### Handling Session Proposals
86+
87+
You can connect your web wallet to a dApp in three ways:
88+
89+
1. Retrieve the WC URI from the dApp via query parameters
90+
2. Implement a scanner to read the WC URI from a WalletConnect QR code
91+
3. Allow users to manually enter the WC URI in an input field
92+
93+
When opening the wallet directly from the dApp, the `WC_URI` will be in the following format in the query parameters:
94+
95+
```
96+
{YOUR_WALLET_URL}/wc?uri={WC_URI}
97+
```
98+
99+
We recommend closing the web wallet tab after the user approves the request and redirecting back to the dApp. For web requests, redirect to the original browser tab, and for mobile requests, redirect to the native mobile dApp.
100+
101+
<Note>
102+
To test your web wallet connection flow, use our [Appkit Laboratory](https://appkit-lab.reown.com/) by adding a custom wallet with your web wallet URL.
103+
</Note>
104+
105+
### Handling Session Requests
106+
107+
When a dApp sends a session request to your wallet, the request will be available in the following format in the query parameters:
108+
109+
```
110+
{YOUR_WALLET_URL}/wc?requestId={requestId}&sessionTopic={session.Topic}
111+
```
112+
113+
This format allows your wallet to identify both the specific request and the session it belongs to.
114+
115+
<Note>
116+
To test your web wallet connection flow, use our [Appkit Laboratory](https://appkit-lab.reown.com/) by adding a custom wallet with your web wallet URL.
117+
</Note>
118+
119+
### Handling Redirects
120+
121+
When handling redirects after session approval or request completion, you should:
122+
123+
1. For web dApps:
124+
- Redirect back to the original browser tab using `window.opener.location.href`
125+
- Close the current wallet tab using `window.close()`
126+
127+
2. For native dApps:
128+
- Check the peer metadata for a `redirect` URL in the session proposal
129+
- If available, use deep linking to redirect to the native app
130+
- If no redirect URL is found, display a "Return to App" message to the user
131+
132+
Example implementation:
133+
134+
```javascript
135+
function handleRedirect(session) {
136+
// Check if this is a native app
137+
const isNativeApp = session.peer.metadata.redirect !== undefined;
138+
139+
if (isNativeApp) {
140+
// Redirect to native app if URL is available
141+
if (session.peer.metadata.redirect) {
142+
window.location.href = session.peer.metadata.redirect;
143+
} else {
144+
// Show "Return to App" message
145+
showReturnToAppMessage();
146+
}
147+
} else {
148+
// For web dApps, redirect back to original tab
149+
if (window.opener) {
150+
window.opener.location.href = session.peer.metadata.url;
151+
window.close();
152+
}
153+
}
154+
}
155+
```
156+
46157
### Namespace Builder
47158

48159
With WalletKit (and @walletconnect/utils) we've published a helper utility that greatly reduces the complexity of parsing the `required` and `optional` namespaces. It accepts as parameters a `session proposal` along with your user's `chains/methods/events/accounts` and returns ready-to-use `namespaces` object.

0 commit comments

Comments
 (0)