I want to connect my dapp with WalletConnect, but I want to create only one pairing for my application. For testing purpose I use WalletConnect demo wallet and as I can see every time I create connection, new pairing appears:
WalletConnect demo wallet with multiple, same pairings
I want to have one pairing only.
When user first time visits my dapp, I connect to WalletConnect using UniversalProvider (without topic - topic is undefined yet).
import UniversalProvider from "@walletconnect/universal-provider";
const ethereumProvider = await UniversalProvider.init({
projectId: projectId
});
let requiredNamespaces = {
namespaces: {
eip155: {
methods: [
"eth_sendTransaction",
"eth_signTransaction",
"eth_sign",
"personal_sign",
"eth_signTypedData",
],
chains: [chainId],
events: ["chainChanged", "accountsChanged"],
}
},
};
const session = await ethereumProvider.connect(requiredNamespaces);
So session is established so I store session object and topicId in local storage:
// after this I store session object and session.topic in local storage
window.localStorage.setItem('session', JSON.stringify(session));
window.localStorage.setItem('topicId', JSON.stringify(session.topic));
Now user decided to disconnect session:
await ethereumProvider.disconnect();
// I remove session, but topic is still stored
window.localStorage.removeItem('session');
And now user decided to connect to my dapp again:
const topicId = JSON.parse(window.localStorage.getItem('topicId'));
let requiredNamespaces = {
namespaces: {
eip155: {
methods: [
"eth_sendTransaction",
"eth_signTransaction",
"eth_sign",
"personal_sign",
"eth_signTypedData",
],
chains: [chainId],
events: ["chainChanged", "accountsChanged"],
pairingTopic: topicId
}
},
};
const session = await ethereumProvider.connect(requiredNamespaces);
And now the problem - the new pairing will be added to wallet, instead of using the old one.
I don't know if this is proper way of handling WalletConnect session and pairing.
Do I do something wrong? Maybe I shouldn't disconnect this way? Is this a WalletConnect issue?