Reputation: 11
I am trying to use wallet connect v2 in react-native. When a connection request is made for 5 chains, I want to connect only 3 chains. Is there a way? If I put only 3 accounts in nameSpace, I get an error. Is there any way to connect only some chains when the wallet connect v2 connection request comes to the react-native wallet?
const { id, params } = this.proposal;
const { requiredNamespaces, relays } = params;
const namespaces: SessionTypes.Namespaces = {};
Object.keys(requiredNamespaces).forEach(key => {
const accounts: string[] = [];
requiredNamespaces[key].chains?.map(chain => {
const availableNetwork = availableNetworkList.find(
({ chainId }) => chainId === this.getEIP155ChainId(chain),
);
console.log('requiredNamespaces', requiredNamespaces[key]);
availableNetwork?.isConnect
? accounts.push(`${chain}:${this.currentETHAddress}`)
: accounts.push(`${chain}:`);
});
namespaces[key] = {
accounts,
methods: requiredNamespaces[key].methods,
events: requiredNamespaces[key].events,
};
console.log('namespaces', namespaces);
});
await this.web3wallet.approveSession({
id,
relayProtocol: relays[0].protocol,
namespaces,
});
When a connection request was received for 5 chains, the addresses for only 3 chains were added and passed to the namespace of the approve session.
Upvotes: 1
Views: 894
Reputation: 759
That goes against the WCv2 definition. These are required namespaces, as opposed the optional namespaces. If the required namespaces cannot be supported as requested, the proposal should fail.
The only way you could perhaps connect anyway, is by approving all namespaces, and later blocking session requests for certain chain ID's in your application.
https://docs.walletconnect.com/2.0/specs/clients/sign/namespaces#approving-a-session-response
Upvotes: 1