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
165 stars 101 forks source link

Problem with 'reactNativeDemo' #293

Closed theAndEx closed 10 months ago

theAndEx commented 1 year ago

Hi,

I took "reactNativeDemo" and did everything in the video (https://github.com/MetaMask/metamask-sdk/issues/249#issuecomment-1662747784), but after switching to the Metamask app, I got to the main screen of Metamask. There is no connection request.

My actions:

  1. I took a completely clean project - 'reactNativeDemo' from https://github.com/MetaMask/metamask-sdk/tree/main/packages/examples/reactNativeDemo.
  2. yarn install.
  3. yarn start.
  4. yarn android.
  5. After the application has started, I press 'CONNECT', and I get to the main Metamask page without a connection request.

GIF - https://gyazo.com/6dce031dc4ef4cd5d0d2405b248babae

What could be the reason for this?

christopherferreira9 commented 1 year ago

Hi @theAndEx ! How did you install the MetaMask wallet on the emulator?

theAndEx commented 1 year ago

Hi @theAndEx ! How did you install the MetaMask wallet on the emulator?

Hi @christopherferreira9, via Play Store.

christopherferreira9 commented 1 year ago

Hi @theAndEx , can you please check if this issue is present when using a real device? We usually target our tests to real devices instead of emulators and simulators.

horatiubran commented 1 year ago

Hello, I have the same issue but on a real device. I use my samsung galaxy s22.

christopherferreira9 commented 1 year ago

Hi @theAndEx , we are trying to find the root cause for these ReactNative issues as it doesn't seem to happen in every device at all times so we're trying to isolate the root cause itself. Also, in the meantime, can you try with the latest MetaMask SDK version we just released?

theAndEx commented 1 year ago

It is very strange. I see that on some devices (emulators) everything works, on others it doesn’t. I created a new device and everything started working.

So, my problem arose with version 0.5.6. If this is relevant, then I can try to reproduce the problem on the same device that I originally used with the latest version.

But now I have a problem with open Metamask app. I see that the same situation is in your demo project. When I have already gone to the application (Metamask), in the password entry page, I close the Metamask app and return to the original one. In this situation, I cannot redirect to the Metamask app again. Could I fix this somehow? @christopherferreira9

Thank you.

andreahaku commented 1 year ago

@theAndEx Could you check the android settings of your devices?

Open Android settings , search 'default' and select "Choose Default apps' > "Choose Default apps" > Opening Links > scroll down to MetaMask and tap it > Supported Web addresses > check if links are selected or "verified/trusted" by default (most importantly metamask.app.link). If they are not, then check them/it.

Let me know if it worked for you!

theAndEx commented 1 year ago

https://gyazo.com/f6902f43c489046fc9f7a703df860e84 https://gyazo.com/e15f4dc74d802102d87a18ce3c8af574

I see that there is a link to the application.

But the current problem is that when you press the "connect" button => the Metamask app opens, and at that moment, close it, go back to the original application and press the "connect" button again - nothing happens.

andreahaku commented 1 year ago

@theAndEx do you use a VPN or something similar?

theAndEx commented 1 year ago

@andreahaku when using the emulator - no, I don’t use it. I can record the screen if needed.

andreahaku commented 1 year ago

@theAndEx we are trying to replicate it and will keep you updated on our finding.

theAndEx commented 1 year ago

I did this.

And the "catch" does not always work correctly, but now you can reject the connection request/close the app (Metamask) and then try to sign in again.


    try {
      sdk.on(
        EventType.CONNECTION_STATUS,
        (_connectionStatus: ConnectionStatus) => {
          if (
            _connectionStatus === 'disconnected' ||
            _connectionStatus === 'terminated' ||
            _connectionStatus === 'timeout'
          ) {
            sdk.terminate();
          }
        },
      );

      const result = (await ethereum?.request({
        method: 'eth_requestAccounts',
      })) as string[];

     ... some code ...

    } catch (e) {
      console.log('ERROR', e);
      sdk.terminate();
      Alert.alert('Something wrong!', 'Please wait and try again later.');
    }
  };
andreahaku commented 1 year ago

I did this.

And the "catch" does not always work correctly, but now you can reject the connection request/close the app (Metamask) and then try to sign in again.

    try {
      sdk.on(
        EventType.CONNECTION_STATUS,
        (_connectionStatus: ConnectionStatus) => {
          if (
            _connectionStatus === 'disconnected' ||
            _connectionStatus === 'terminated' ||
            _connectionStatus === 'timeout'
          ) {
            sdk.terminate();
          }
        },
      );

      const result = (await ethereum?.request({
        method: 'eth_requestAccounts',
      })) as string[];

     ... some code ...

    } catch (e) {
      console.log('ERROR', e);
      sdk.terminate();
      Alert.alert('Something wrong!', 'Please wait and try again later.');
    }
  };

and does this solve the problem with the Android connection modal not showing up?

christopherferreira9 commented 10 months ago

Hi all! We will be closing this issue since there has been no activity on it. We just updated the example dapps to the latest version of the SDK, can you please give those a try and open a new bug if needed?