Skip to content

Commit

Permalink
fix(wallet-walletconnect): make WalletConnect chainIds optional (#400)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut authored Dec 10, 2024
1 parent 4e1197c commit bef0909
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-pets-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@reactive-dot/wallet-walletconnect": minor
---

`chainIds` is now optional. Either `chainIds` or `optionalChainIds` must be set.
20 changes: 14 additions & 6 deletions packages/wallet-walletconnect/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class WalletConnect extends DeepLinkWallet {
projectId?: string;
providerOptions: Omit<UniversalProviderOpts, "projectId">;
modalOptions?: Omit<WalletConnectModalConfig, "projectId">;
chainIds: string[];
chainIds?: string[];
optionalChainIds?: string[];
}) {
super(undefined);
Expand All @@ -58,7 +58,7 @@ export class WalletConnect extends DeepLinkWallet {
projectId: options.projectId,
};

this.#chainIds = options.chainIds;
this.#chainIds = options.chainIds ?? [];
this.#optionalChainIds = options.optionalChainIds ?? [];
}

Expand Down Expand Up @@ -87,15 +87,23 @@ export class WalletConnect extends DeepLinkWallet {
);
}

const connectOptions: Parameters<ISignClient["connect"]>[0] = {
requiredNamespaces: {
if (this.#chainIds.length === 0 && this.#optionalChainIds.length === 0) {
throw new ReactiveDotError(
"Either chainIds or optionalChainIds must be provided",
);
}

const connectOptions: Parameters<ISignClient["connect"]>[0] = {};

if (this.#chainIds.length > 0) {
connectOptions.requiredNamespaces = {
polkadot: {
methods: ["polkadot_signTransaction", "polkadot_signMessage"],
chains: this.#chainIds,
events: ['chainChanged", "accountsChanged'],
},
},
};
};
}

if (this.#optionalChainIds.length > 0) {
connectOptions.optionalNamespaces = {
Expand Down

0 comments on commit bef0909

Please sign in to comment.