diff --git a/.changeset/tender-pets-warn.md b/.changeset/tender-pets-warn.md new file mode 100644 index 00000000..fd04ae58 --- /dev/null +++ b/.changeset/tender-pets-warn.md @@ -0,0 +1,5 @@ +--- +"@reactive-dot/wallet-walletconnect": minor +--- + +`chainIds` is now optional. Either `chainIds` or `optionalChainIds` must be set. diff --git a/packages/wallet-walletconnect/src/index.ts b/packages/wallet-walletconnect/src/index.ts index 03106b08..8e8ac7f5 100644 --- a/packages/wallet-walletconnect/src/index.ts +++ b/packages/wallet-walletconnect/src/index.ts @@ -43,7 +43,7 @@ export class WalletConnect extends DeepLinkWallet { projectId?: string; providerOptions: Omit; modalOptions?: Omit; - chainIds: string[]; + chainIds?: string[]; optionalChainIds?: string[]; }) { super(undefined); @@ -58,7 +58,7 @@ export class WalletConnect extends DeepLinkWallet { projectId: options.projectId, }; - this.#chainIds = options.chainIds; + this.#chainIds = options.chainIds ?? []; this.#optionalChainIds = options.optionalChainIds ?? []; } @@ -87,15 +87,23 @@ export class WalletConnect extends DeepLinkWallet { ); } - const connectOptions: Parameters[0] = { - requiredNamespaces: { + if (this.#chainIds.length === 0 && this.#optionalChainIds.length === 0) { + throw new ReactiveDotError( + "Either chainIds or optionalChainIds must be provided", + ); + } + + const connectOptions: Parameters[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 = {