Skip to content

Commit

Permalink
[SDK] Fix: Limit WC chains connected to 10 for max payload size (#5427)
Browse files Browse the repository at this point in the history
CNCT-2231

<!-- start pr-codex -->

---

## PR-Codex overview
This PR introduces a validation check for the `chains` option in the WalletConnect integration, ensuring that no more than 10 chains can be specified. If more than 10 chains are provided, a warning is logged, and only the first 10 chains are used.

### Detailed summary
- Added a check for `options.chains` to limit the number of chains to a maximum of 10.
- Implemented a warning message if more than 10 chains are specified, informing the user of the truncation.
- Used `slice(0, 10)` to return only the first 10 chains if the limit is exceeded.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->
  • Loading branch information
gregfromstl committed Nov 15, 2024
1 parent 7b21f1b commit 10ca0bc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/thirdweb/src/wallets/wallet-connect/receiver/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,19 @@ export async function createWalletConnectClient(
const {
wallet,
requestHandlers,
chains,
onConnect,
onDisconnect,
client: thirdwebClient,
} = options;
const chains = (() => {
if (options.chains && options.chains.length > 10) {
console.warn(
"WalletConnect: Can specify no more than 10 chains, truncating to the first 10 provided chains...",
);
return options.chains.slice(0, 10);
}

Check warning on line 174 in packages/thirdweb/src/wallets/wallet-connect/receiver/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/wallets/wallet-connect/receiver/index.ts#L170-L174

Added lines #L170 - L174 were not covered by tests
return options.chains;
})();

if (walletConnectClientCache.has(thirdwebClient)) {
return walletConnectClientCache.get(thirdwebClient) as WalletConnectClient;
Expand Down

0 comments on commit 10ca0bc

Please sign in to comment.