-
Notifications
You must be signed in to change notification settings - Fork 619
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure large lists of WalletConnect wallets work in Brave (#492)
- Loading branch information
1 parent
9b1f866
commit ce473cd
Showing
16 changed files
with
152 additions
and
158 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,9 @@ | ||
--- | ||
'@rainbow-me/rainbowkit': patch | ||
--- | ||
|
||
Fix WalletConnect in Brave when a large number of WalletConnect-based wallets have been configured | ||
|
||
Brave’s fingerprint prevention logic silently blocks WebSocket connections if too many are opened in the same session. Since we create a fresh WalletConnect connector instance for each wallet, consumers that have configured a large number of wallets can inadvertently break the connection flow in Brave. | ||
|
||
To fix this, we now share WalletConnect connector instances between wallets when the connectors are being provided with the same options. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export function flatten<Item>(array: Item[][]) { | ||
const flattenedItems: Item[] = []; | ||
|
||
for (const items of array) { | ||
flattenedItems.push(...items); | ||
} | ||
|
||
return flattenedItems; | ||
} |
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
38 changes: 38 additions & 0 deletions
38
packages/rainbowkit/src/wallets/getWalletConnectConnector.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,38 @@ | ||
import { WalletConnectConnector } from 'wagmi/connectors/walletConnect'; | ||
import { Chain } from '../components/RainbowKitProvider/RainbowKitChainContext'; | ||
import { rpcUrlsForChains } from './../utils/rpcUrlsForChains'; | ||
|
||
type SerializedOptions = string; | ||
const sharedConnectors = new Map<SerializedOptions, WalletConnectConnector>(); | ||
|
||
type WalletConnectConnectorOptions = ConstructorParameters< | ||
typeof WalletConnectConnector | ||
>[0]; | ||
|
||
function createConnector(options: WalletConnectConnectorOptions) { | ||
const connector = new WalletConnectConnector(options); | ||
sharedConnectors.set(JSON.stringify(options), connector); | ||
return connector; | ||
} | ||
|
||
export function getWalletConnectConnector({ | ||
chains, | ||
qrcode = false, | ||
}: { | ||
chains: Chain[]; | ||
qrcode?: boolean; | ||
}) { | ||
const rpc = rpcUrlsForChains(chains); | ||
const options: WalletConnectConnectorOptions = { | ||
chains, | ||
options: { | ||
qrcode, | ||
rpc, | ||
}, | ||
}; | ||
|
||
const serializedOptions = JSON.stringify(options); | ||
const sharedConnector = sharedConnectors.get(serializedOptions); | ||
|
||
return sharedConnector ?? createConnector(options); | ||
} |
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
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
Oops, something went wrong.
ce473cd
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-rainbowdotme.vercel.app
rainbowkit-example-git-main-rainbowdotme.vercel.app
rainbowkit-example.vercel.app
ce473cd
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-site-rainbowdotme.vercel.app
www.rainbowkit.com
rainbowkit.vercel.app
rainbowkit-site-git-main-rainbowdotme.vercel.app
rainbowkit.com