WalletConnectUnity icon indicating copy to clipboard operation
WalletConnectUnity copied to clipboard

Error connecting and handling sessions in the WalletConnect SDK

Open tieugame2110 opened this issue 1 year ago • 8 comments

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 image

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

tieugame2110 avatar Feb 19 '24 08:02 tieugame2110

Hello @tieugame2110,

Does it log any errors? What mobile wallets did you use test it with?

skibitsky avatar Feb 19 '24 10:02 skibitsky

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 avatar Feb 20 '24 03:02 tieugame2110

@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 avatar Feb 20 '24 03:02 skibitsky

@skibitsky delete the session on MetaMask: image image image

delete the session on Spot OnChain: image image image

tieugame2110 avatar Feb 20 '24 05:02 tieugame2110

Could you check if any of these fields in the WalletConnectProjectConfig scriptable asset are empty?

  • Id
  • Name
  • Description
  • Url
  • Icon (at least one item should be present)

skibitsky avatar Feb 27 '24 05:02 skibitsky

@skibitsky I ensure that all fields have been filled in. image

tieugame2110 avatar Feb 27 '24 06:02 tieugame2110

@tieugame2110 can you access https://walletconnect.com website without VPN or any other proxy from your network?

skibitsky avatar Feb 28 '24 04:02 skibitsky

@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.

tieugame2110 avatar Feb 28 '24 09:02 tieugame2110