Error connecting and handling sessions in the WalletConnect SDK
After I use the mobile device to scan the QR code, it only closes the modal but does not execute the OnAfterConnect function
Expected behavior
after scan QR Code, the WalletConnect.Instance.ActiveSessionChanged function will be executed
note*: i unchecked ResumeSessionOnInit boolean
Screenshots
My Code
private void Start()
{
//Application.targetFrameRate = Screen.currentResolution.refreshRate;
// When WalletConnectModal is ready, enable buttons and subscribe to other events.
// WalletConnectModal.SignClient can be null if WalletConnectModal is not ready.
WalletConnectModal.Ready += (sender, args) =>
{
//// SessionResumed is true if Modal resumed session from storage
if (args.SessionResumed)
{
OnAfterConnect();
Debug.Log(1);
}
else
{
OnAfterDisconnect();
Debug.Log(2);
}
// Invoked after wallet connected
WalletConnect.Instance.ActiveSessionChanged += (_, @struct) =>
{
if (string.IsNullOrEmpty(@struct.Topic))
return;
Debug.Log($"[WalletConnectModalSample] Session connected. Topic: {@struct.Topic}");
OnAfterConnect();
Debug.Log(3);
};
// Invoked after wallet disconnected
WalletConnect.Instance.SessionDisconnected += (_, _) =>
{
Debug.Log($"[WalletConnectModalSample] Session deleted.");
OnAfterDisconnect();
Debug.Log(4);
};
};
}
private void OnAfterConnect()
{
var UWM = UIWalletManager.Instance;
var address = GetAddress();
UWM.web3Manager.userAddress = address;
UWM.screenManager.ShowScreen("HOME");
UWM.web3Manager.loginWith = LoginWith.WCModal;
Debug.Log(address);
}
private void OnAfterDisconnect()
{
WalletConnectModal.Disconnect();
}
Environment
- OS: Android
- Unity version 2022.3.5f1
- Package name and version: WalletConnectUnity Modal v1.0.6
Hello @tieugame2110,
Does it log any errors? What mobile wallets did you use test it with?
Hi @skibitsky, Action does not provide any feedback on errors, i test with MetaMask, Spot OnChain wallet (Goerli testnet)
The notable point is that the wallet is okay the first time it connects, but after disconnecting or even deleting the session on the device, this error occurs
@tieugame2110
Can you please describe exact steps to reproduce it?
or even deleting the session on the device
How exactly did you delete the session?
@skibitsky
delete the session on MetaMask:
delete the session on Spot OnChain:
Could you check if any of these fields in the WalletConnectProjectConfig scriptable asset are empty?
IdNameDescriptionUrlIcon(at least one item should be present)
@skibitsky
I ensure that all fields have been filled in.
@tieugame2110 can you access https://walletconnect.com website without VPN or any other proxy from your network?
@skibitsky Yes, i can. I think the issue is related to the WalletConnect session, because any wallet when first connected executes the correct code, but from the second time onwards encounters this error.