Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error connecting and handling sessions in the WalletConnect SDK #161

Open
tieugame2110 opened this issue Feb 19, 2024 · 8 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@tieugame2110
Copy link

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
@skibitsky skibitsky self-assigned this Feb 19, 2024
@skibitsky
Copy link
Member

Hello @tieugame2110,

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

@tieugame2110
Copy link
Author

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
Copy link
Member

@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
Copy link
Author

@skibitsky
delete the session on MetaMask:
image
image
image

delete the session on Spot OnChain:
image
image
image

@skibitsky skibitsky added the bug Something isn't working label Feb 21, 2024
@skibitsky
Copy link
Member

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)

@tieugame2110
Copy link
Author

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

@skibitsky
Copy link
Member

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

@tieugame2110
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants