MetaMask / metamask-sdk

The simplest yet most secure way to connect your blockchain-based applications to millions of MetaMask Wallet users.
https://metamask.io/sdk/
Other
138 stars 90 forks source link

[Bug]: Wallet is not reconnecting app got stuck on the meta mask app. First time wallet will connect after closing the app it is not connecting until clear the unity app storage. #912

Open basitcubix opened 1 week ago

basitcubix commented 1 week ago

SDK

Unity

Provide environment information

I am using unity 2021.3.39(LTS) deploying it on android phone s22 ultra, Android Os 14

MetaMask SDK Version

unity sdk 2.0.0

MetaMask Mobile app Version

unity sdk 2.0.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

android via unity

Describe the Bug

After connecting the wallet first time everything is working fine but when ever i close the app and open it again upon pressing the connect button its redirecting me to meta mask but nothing happens got stuck on the metamask app it keeps happening until i clear the storage of the unity app. there should be a way to end the session before connecting to the wallet or if the session is currently being stored there should be button for secret sign-in

https://github.com/MetaMask/metamask-sdk/assets/132077089/50fac862-45be-437c-9db4-e0d9cb7e9bd7

Expected Behavior

meta mask wallet should be connected every time when the app connects rather than its stops on the meta mask app and nothing is happening

Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster

No response

To Reproduce

Import the sample scene Build the app for android connect the wallet first time After connecting the wallet close both app meta and unity open the unity App press the connect button from the sample scene meta mask app will open connecting screen will appear but nothing will happen now the app is stuck in the endless loop state

QuipHop commented 1 week ago

Stuck with this too. IOS has absolutely the same problem and behavior. I see that ClearSession() method actually disconnects the user but the connection list remains the same but instead of connected app name I see some ID. Looks like there is no way to check already connected app to avoid endless loop, correct me if I'm wrong.

christopherferreira9 commented 1 week ago

Hi all! We are aware if this issue and we're currently testing a fix for it that should be available in the coming days. Sorry for the inconvenience :/

basitcubix commented 1 week ago

Hey @christopherferreira9 can you share time estimate when the next release will be expected in the mean time can you share a temporarily fix here i have mange to somehow stop the reconnecting wallet issue by calling a MetaMaskUnity.Instance.EndSession(); but i cant seem to change the chainid its getting stuck on the metamask app even with the End Session, here is my code snippet

    public async void ChangeChain(string chain, Action<string, string> connectCallback = null)
        {
            MetaMaskUnity.Instance.EndSession();
            this.connectCallback = connectCallback;

            var request = new MetaMaskEthereumRequest
            {
                Method = "wallet_switchEthereumChain",
                Parameters = new object[] { new { chainId = chain } } // chainId must be in hexadecimal numbers
            };

            //    onSignSend?.Invoke(this, EventArgs.Empty);
            await MetaMaskUnity.Instance.Wallet.Request(request);
        }
WoodsFiend commented 1 week ago

If anyone is looking for a quick fix for this I found that changing to the MetaMaskSDK prefab and setting "Save Session Data" to false eliminates this issue (not sure about mobile but it works better in editor). It does mean that user's need to Connect every time though.