Skip to content

Commit b1e5fb6

Browse files
committed
use optionalNamespaces on new connection since requiredNamespaces is deprecated since @walletconnect/sign-client@2.21.0 ( keep requiredNamespaces on existing sessions )
1 parent 4413c44 commit b1e5fb6

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ The MultiversX namespaces respect the [CAIP Standards](https://namespaces.chaina
188188

189189
```json
190190
{
191-
"requiredNamespaces": {
191+
"optionalNamespaces": {
192192
"mvx": {
193193
"chains": ["mvx:D"],
194194
"methods": [

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@multiversx/sdk-wallet-connect-provider",
3-
"version": "6.1.2-alpha.0",
3+
"version": "6.1.2-alpha.1",
44
"description": "Signing provider for dApps: WalletConnect",
55
"main": "out/index.js",
66
"types": "out/index.d.js",

src/utils.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Address, Transaction } from "@multiversx/sdk-core";
22
import Client from "@walletconnect/sign-client";
33
import {
44
EngineTypes,
5+
ProposalTypes,
56
SessionTypes,
67
SignClientTypes,
78
} from "@walletconnect/types";
@@ -38,7 +39,7 @@ export function getCurrentSession(
3839
}
3940

4041
const acknowledgedSessions = client
41-
.find(getConnectionParams(chainId))
42+
.find(getExistingConnectionParams(chainId))
4243
.filter((s) => s.acknowledged);
4344

4445
if (acknowledgedSessions.length > 0) {
@@ -80,7 +81,27 @@ export function getCurrentTopic(
8081
export function getConnectionParams(
8182
chainId: string,
8283
options?: ConnectParamsTypes
84+
): EngineTypes.ConnectParams {
85+
const optionalNamespaces = getMvxNamespace(chainId, options);
86+
return {
87+
optionalNamespaces,
88+
};
89+
}
90+
91+
export function getExistingConnectionParams(
92+
chainId: string,
93+
options?: ConnectParamsTypes
8394
): EngineTypes.FindParams {
95+
const requiredNamespaces = getMvxNamespace(chainId, options);
96+
return {
97+
requiredNamespaces,
98+
};
99+
}
100+
101+
export function getMvxNamespace(
102+
chainId: string,
103+
options?: ConnectParamsTypes
104+
): ProposalTypes.OptionalNamespaces {
84105
const methods = [
85106
...WALLETCONNECT_MULTIVERSX_METHODS,
86107
...(options?.methods ?? []),
@@ -92,12 +113,10 @@ export function getConnectionParams(
92113
const events = options?.events ?? [];
93114

94115
return {
95-
requiredNamespaces: {
96-
[WALLETCONNECT_MULTIVERSX_NAMESPACE]: {
97-
methods,
98-
chains,
99-
events,
100-
},
116+
[WALLETCONNECT_MULTIVERSX_NAMESPACE]: {
117+
methods,
118+
chains,
119+
events,
101120
},
102121
};
103122
}

0 commit comments

Comments
 (0)