WalletConnect / WalletConnectUnity

[DEPRECATED] WalletConnect v2 and Modal for Unity 🎮
MIT License
150 stars 49 forks source link

Error connecting and handling sessions in the WalletConnect SDK #161

Open tieugame2110 opened 8 months ago

tieugame2110 commented 8 months ago

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

skibitsky commented 8 months ago

Hello @tieugame2110,

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

tieugame2110 commented 8 months ago

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

skibitsky commented 8 months ago

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

tieugame2110 commented 8 months ago

@skibitsky delete the session on MetaMask: image image image

delete the session on Spot OnChain: image image image

skibitsky commented 8 months ago

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

tieugame2110 commented 8 months ago

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

skibitsky commented 8 months ago

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

tieugame2110 commented 8 months ago

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