-
Notifications
You must be signed in to change notification settings - Fork 664
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add WalletConnect deeplink choice to local storage (#479)
- Loading branch information
1 parent
5cf7698
commit 867067c
Showing
6 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@rainbow-me/rainbowkit': patch | ||
--- | ||
|
||
Improve deep linking support for WalletConnect-based wallets on iOS | ||
|
||
We now store the wallet’s universal link URL in local storage so that WalletConnect can use it for deep linking. This is typically handled by the official WalletConnect modal, but we need to handle it ourselves when rendering custom QR codes within RainbowKit. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/rainbowkit/src/components/RainbowKitProvider/useOnDisconnected.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useEffect, useRef } from 'react'; | ||
import { useConnect } from 'wagmi'; | ||
|
||
export function useOnDisconnected(callback: () => void) { | ||
const { isDisconnected } = useConnect(); | ||
|
||
// Ensure callback is executed once on disconnect | ||
const callbackAlreadyExecutedRef = useRef(false); | ||
|
||
useEffect(() => { | ||
if (isDisconnected) { | ||
if (callbackAlreadyExecutedRef.current) { | ||
return; | ||
} | ||
|
||
callbackAlreadyExecutedRef.current = true; | ||
callback(); | ||
} else { | ||
callbackAlreadyExecutedRef.current = false; | ||
} | ||
}, [isDisconnected, callback]); | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/rainbowkit/src/components/RainbowKitProvider/walletConnectDeepLink.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const storageKey = 'WALLETCONNECT_DEEPLINK_CHOICE'; | ||
|
||
export function setWalletConnectDeepLink({ | ||
mobileUri, | ||
name, | ||
}: { | ||
mobileUri: string; | ||
name: string; | ||
}) { | ||
if (mobileUri.startsWith('http') && mobileUri.includes('?uri=')) { | ||
localStorage.setItem( | ||
storageKey, | ||
JSON.stringify({ | ||
href: mobileUri.split('?')[0], | ||
name, | ||
}) | ||
); | ||
} | ||
} | ||
|
||
export function clearWalletConnectDeepLink() { | ||
localStorage.removeItem(storageKey); | ||
} |
867067c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
rainbowkit-example – ./
rainbowkit-example-git-main-rainbowdotme.vercel.app
rainbowkit-example-rainbowdotme.vercel.app
rainbowkit-example.vercel.app
867067c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
rainbowkit-site – ./
rainbowkit.com
rainbowkit-site-rainbowdotme.vercel.app
rainbowkit.vercel.app
rainbowkit-site-git-main-rainbowdotme.vercel.app
www.rainbowkit.com